run_unittests: Add a chdir context manager
Because seriously
This commit is contained in:
parent
2c844f86f2
commit
af4acc8e05
|
@ -76,6 +76,13 @@ from run_tests import (
|
||||||
|
|
||||||
URLOPEN_TIMEOUT = 5
|
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):
|
def get_dynamic_section_entry(fname, entry):
|
||||||
if is_cygwin() or is_osx():
|
if is_cygwin() or is_osx():
|
||||||
|
@ -5861,7 +5868,7 @@ class LinuxlikeTests(BasePlatformTests):
|
||||||
testdir = os.path.join(self.common_test_dir, testdir)
|
testdir = os.path.join(self.common_test_dir, testdir)
|
||||||
subdir = os.path.join(testdir, subdir_path)
|
subdir = os.path.join(testdir, subdir_path)
|
||||||
curdir = os.getcwd()
|
curdir = os.getcwd()
|
||||||
os.chdir(subdir)
|
with chdir(subdir):
|
||||||
# Can't distribute broken symlinks in the source tree because it breaks
|
# Can't distribute broken symlinks in the source tree because it breaks
|
||||||
# the creation of zipapps. Create it dynamically and run the test by
|
# the creation of zipapps. Create it dynamically and run the test by
|
||||||
# hand.
|
# hand.
|
||||||
|
@ -5878,7 +5885,6 @@ class LinuxlikeTests(BasePlatformTests):
|
||||||
self.assertFalse(os.path.isfile(link), msg=link)
|
self.assertFalse(os.path.isfile(link), msg=link)
|
||||||
finally:
|
finally:
|
||||||
os.remove(os.path.join(subdir, 'invalid-symlink.txt'))
|
os.remove(os.path.join(subdir, 'invalid-symlink.txt'))
|
||||||
os.chdir(curdir)
|
|
||||||
|
|
||||||
def test_install_subdir_symlinks(self):
|
def test_install_subdir_symlinks(self):
|
||||||
self.install_subdir_invalid_symlinks('62 install subdir', os.path.join('sub', 'sub1'))
|
self.install_subdir_invalid_symlinks('62 install subdir', os.path.join('sub', 'sub1'))
|
||||||
|
|
Loading…
Reference in New Issue