aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-01-28 14:37:59 -0800
committerDylan Baker <dylan@pnwbakers.com>2020-01-29 09:11:24 -0800
commitaf4acc8e05fdeed2e67c5fea60461fb6748e42cc (patch)
treec44913e26fdc3d5b3dc63971d62be31f1deaf0a6
parent2c844f86f24bb5ce431c2fa4c669f84ffaaab5e7 (diff)
downloadmeson-af4acc8e05fdeed2e67c5fea60461fb6748e42cc.zip
meson-af4acc8e05fdeed2e67c5fea60461fb6748e42cc.tar.gz
meson-af4acc8e05fdeed2e67c5fea60461fb6748e42cc.tar.bz2
run_unittests: Add a chdir context manager
Because seriously
-rwxr-xr-xrun_unittests.py42
1 files changed, 24 insertions, 18 deletions
diff --git a/run_unittests.py b/run_unittests.py
index ff9dbd6..7ed3f7c 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -76,6 +76,13 @@ from run_tests import (
URLOPEN_TIMEOUT = 5
+@contextmanager
+def chdir(path: str):
+ curdir = os.getcwd()
+ os.chdir(path)
+ yield
+ os.chdir(curdir)
+
def get_dynamic_section_entry(fname, entry):
if is_cygwin() or is_osx():
@@ -5861,24 +5868,23 @@ class LinuxlikeTests(BasePlatformTests):
testdir = os.path.join(self.common_test_dir, testdir)
subdir = os.path.join(testdir, subdir_path)
curdir = os.getcwd()
- os.chdir(subdir)
- # Can't distribute broken symlinks in the source tree because it breaks
- # the creation of zipapps. Create it dynamically and run the test by
- # hand.
- src = '../../nonexistent.txt'
- os.symlink(src, 'invalid-symlink.txt')
- try:
- self.init(testdir)
- self.build()
- self.install()
- install_path = subdir_path.split(os.path.sep)[-1]
- link = os.path.join(self.installdir, 'usr', 'share', install_path, 'invalid-symlink.txt')
- self.assertTrue(os.path.islink(link), msg=link)
- self.assertEqual(src, os.readlink(link))
- self.assertFalse(os.path.isfile(link), msg=link)
- finally:
- os.remove(os.path.join(subdir, 'invalid-symlink.txt'))
- os.chdir(curdir)
+ with chdir(subdir):
+ # Can't distribute broken symlinks in the source tree because it breaks
+ # the creation of zipapps. Create it dynamically and run the test by
+ # hand.
+ src = '../../nonexistent.txt'
+ os.symlink(src, 'invalid-symlink.txt')
+ try:
+ self.init(testdir)
+ self.build()
+ self.install()
+ install_path = subdir_path.split(os.path.sep)[-1]
+ link = os.path.join(self.installdir, 'usr', 'share', install_path, 'invalid-symlink.txt')
+ self.assertTrue(os.path.islink(link), msg=link)
+ self.assertEqual(src, os.readlink(link))
+ self.assertFalse(os.path.isfile(link), msg=link)
+ finally:
+ os.remove(os.path.join(subdir, 'invalid-symlink.txt'))
def test_install_subdir_symlinks(self):
self.install_subdir_invalid_symlinks('62 install subdir', os.path.join('sub', 'sub1'))