From bb491735a980d9124078ac032a5281e648027de7 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 30 Jan 2017 02:53:35 +0530 Subject: coredata: Use our own implementation of commonpath os.path.commonpath was added in Python 3.5, so just write our own for now. pathlib was added in Python 3.4, so this should be ok. We need to use that instead of doing str.split() etc because Windows path handling has a lot of exceptions and pathlib handles all that for us. Also adds a unit test for this. --- run_unittests.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index a1d99f3..e8659f4 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -153,6 +153,23 @@ class InternalTests(unittest.TestCase): a = ['-Ldir', '-Lbah'] + a self.assertEqual(a, ['-Ibar', '-Ifoo', '-Ibaz', '-I..', '-I.', '-Ldir', '-Lbah', '-Werror', '-O3', '-O2', '-Wall']) + def test_commonpath(self): + from os.path import sep + commonpath = mesonbuild.mesonlib.commonpath + self.assertRaises(ValueError, commonpath, []) + self.assertEqual(commonpath(['/usr', '/usr']), sep + 'usr') + self.assertEqual(commonpath(['/usr', '/usr/']), sep + 'usr') + self.assertEqual(commonpath(['/usr', '/usr/bin']), sep + 'usr') + self.assertEqual(commonpath(['/usr/', '/usr/bin']), sep + 'usr') + self.assertEqual(commonpath(['/usr/./', '/usr/bin']), sep + 'usr') + self.assertEqual(commonpath(['/usr/bin', '/usr/bin']), sep + 'usr' + sep + 'bin') + self.assertEqual(commonpath(['/usr//bin', '/usr/bin']), sep + 'usr' + sep + 'bin') + self.assertEqual(commonpath(['/usr/./bin', '/usr/bin']), sep + 'usr' + sep + 'bin') + self.assertEqual(commonpath(['/usr/local', '/usr/lib']), sep + 'usr') + self.assertEqual(commonpath(['/usr', '/bin']), sep) + self.assertEqual(commonpath(['/usr', 'bin']), '') + self.assertEqual(commonpath(['blam', 'bin']), '') + class LinuxlikeTests(unittest.TestCase): def setUp(self): -- cgit v1.1