run_unittests: Add a helper for asserting path existence

It is useful to have a message displayed if the assert is fired.
pull/2191/head
Nirbheek Chauhan 7 years ago
parent c69a4aee1e
commit cae5caa7f1
  1. 42
      run_unittests.py

@ -467,7 +467,7 @@ class BasePlatformTests(unittest.TestCase):
return output
def init(self, srcdir, extra_args=None, default_args=True, inprocess=False):
self.assertTrue(os.path.exists(srcdir))
self.assertPathExists(srcdir)
if extra_args is None:
extra_args = []
if not isinstance(extra_args, list):
@ -628,6 +628,14 @@ class BasePlatformTests(unittest.TestCase):
else:
raise RuntimeError('Invalid backend: {!r}'.format(self.backend.name))
def assertPathExists(self, path):
m = 'Path {!r} should exist'.format(path)
self.assertTrue(os.path.exists(path), msg=m)
def assertPathDoesNotExist(self, path):
m = 'Path {!r} should not exist'.format(path)
self.assertFalse(os.path.exists(path), msg=m)
class AllPlatformTests(BasePlatformTests):
'''
@ -773,11 +781,11 @@ class AllPlatformTests(BasePlatformTests):
exename = os.path.join(self.installdir, 'usr/bin/prog' + exe_suffix)
testdir = os.path.join(self.common_test_dir, '8 install')
self.init(testdir)
self.assertFalse(os.path.exists(exename))
self.assertPathDoesNotExist(exename)
self.install()
self.assertTrue(os.path.exists(exename))
self.assertPathExists(exename)
self.uninstall()
self.assertFalse(os.path.exists(exename))
self.assertPathDoesNotExist(exename)
def test_testsetups(self):
if not shutil.which('valgrind'):
@ -868,10 +876,10 @@ class AllPlatformTests(BasePlatformTests):
self.build()
genfile = os.path.join(self.builddir, 'generated.dat')
exe = os.path.join(self.builddir, 'fooprog' + exe_suffix)
self.assertTrue(os.path.exists(genfile))
self.assertFalse(os.path.exists(exe))
self.assertPathExists(genfile)
self.assertPathDoesNotExist(exe)
self.build(target=('fooprog' + exe_suffix))
self.assertTrue(os.path.exists(exe))
self.assertPathExists(exe)
def test_internal_include_order(self):
testdir = os.path.join(self.common_test_dir, '138 include order')
@ -1240,8 +1248,8 @@ int main(int argc, char **argv) {
self.build('dist')
distfile = os.path.join(self.distdir, 'disttest-1.4.3.tar.xz')
checksumfile = distfile + '.sha256sum'
self.assertTrue(os.path.exists(distfile))
self.assertTrue(os.path.exists(checksumfile))
self.assertPathExists(distfile)
self.assertPathExists(checksumfile)
def test_rpath_uses_ORIGIN(self):
'''
@ -1604,35 +1612,35 @@ class LinuxlikeTests(BasePlatformTests):
# File without aliases set.
nover = os.path.join(libpath, 'libnover.so')
self.assertTrue(os.path.exists(nover))
self.assertPathExists(nover)
self.assertFalse(os.path.islink(nover))
self.assertEqual(get_soname(nover), 'libnover.so')
self.assertEqual(len(glob(nover[:-3] + '*')), 1)
# File with version set
verset = os.path.join(libpath, 'libverset.so')
self.assertTrue(os.path.exists(verset + '.4.5.6'))
self.assertPathExists(verset + '.4.5.6')
self.assertEqual(os.readlink(verset), 'libverset.so.4')
self.assertEqual(get_soname(verset), 'libverset.so.4')
self.assertEqual(len(glob(verset[:-3] + '*')), 3)
# File with soversion set
soverset = os.path.join(libpath, 'libsoverset.so')
self.assertTrue(os.path.exists(soverset + '.1.2.3'))
self.assertPathExists(soverset + '.1.2.3')
self.assertEqual(os.readlink(soverset), 'libsoverset.so.1.2.3')
self.assertEqual(get_soname(soverset), 'libsoverset.so.1.2.3')
self.assertEqual(len(glob(soverset[:-3] + '*')), 2)
# File with version and soversion set to same values
settosame = os.path.join(libpath, 'libsettosame.so')
self.assertTrue(os.path.exists(settosame + '.7.8.9'))
self.assertPathExists(settosame + '.7.8.9')
self.assertEqual(os.readlink(settosame), 'libsettosame.so.7.8.9')
self.assertEqual(get_soname(settosame), 'libsettosame.so.7.8.9')
self.assertEqual(len(glob(settosame[:-3] + '*')), 2)
# File with version and soversion set to different values
bothset = os.path.join(libpath, 'libbothset.so')
self.assertTrue(os.path.exists(bothset + '.1.2.3'))
self.assertPathExists(bothset + '.1.2.3')
self.assertEqual(os.readlink(bothset), 'libbothset.so.1.2.3')
self.assertEqual(os.readlink(bothset + '.1.2.3'), 'libbothset.so.4.5.6')
self.assertEqual(get_soname(bothset), 'libbothset.so.1.2.3')
@ -1719,9 +1727,9 @@ class LinuxlikeTests(BasePlatformTests):
def test_unity_subproj(self):
testdir = os.path.join(self.common_test_dir, '49 subproject')
self.init(testdir, extra_args='--unity=subprojects')
self.assertTrue(os.path.exists(os.path.join(self.builddir, 'subprojects/sublib/simpletest@exe/simpletest-unity.c')))
self.assertTrue(os.path.exists(os.path.join(self.builddir, 'subprojects/sublib/sublib@sha/sublib-unity.c')))
self.assertFalse(os.path.exists(os.path.join(self.builddir, 'user@exe/user-unity.c')))
self.assertPathExists(os.path.join(self.builddir, 'subprojects/sublib/simpletest@exe/simpletest-unity.c'))
self.assertPathExists(os.path.join(self.builddir, 'subprojects/sublib/sublib@sha/sublib-unity.c'))
self.assertPathDoesNotExist(os.path.join(self.builddir, 'user@exe/user-unity.c'))
self.build()
def test_installed_modes(self):

Loading…
Cancel
Save