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,24 +5868,23 @@ 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.
|
||||||
src = '../../nonexistent.txt'
|
src = '../../nonexistent.txt'
|
||||||
os.symlink(src, 'invalid-symlink.txt')
|
os.symlink(src, 'invalid-symlink.txt')
|
||||||
try:
|
try:
|
||||||
self.init(testdir)
|
self.init(testdir)
|
||||||
self.build()
|
self.build()
|
||||||
self.install()
|
self.install()
|
||||||
install_path = subdir_path.split(os.path.sep)[-1]
|
install_path = subdir_path.split(os.path.sep)[-1]
|
||||||
link = os.path.join(self.installdir, 'usr', 'share', install_path, 'invalid-symlink.txt')
|
link = os.path.join(self.installdir, 'usr', 'share', install_path, 'invalid-symlink.txt')
|
||||||
self.assertTrue(os.path.islink(link), msg=link)
|
self.assertTrue(os.path.islink(link), msg=link)
|
||||||
self.assertEqual(src, os.readlink(link))
|
self.assertEqual(src, os.readlink(link))
|
||||||
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