diff --git a/tests/test_fsl_utils_path.py b/tests/test_fsl_utils_path.py index 0820f4ed642c9499047b6a02f811027d52522d15..f5e798377e5e45dff555c2aa90d2b41fa5ae3ed9 100644 --- a/tests/test_fsl_utils_path.py +++ b/tests/test_fsl_utils_path.py @@ -1356,3 +1356,32 @@ def test_uniquePrefix(): finally: shutil.rmtree(workdir) + + +def test_commonBase(): + + tests = [ + ('/', + ['/a/b/c', + '/d/e', + '/f/g/h/i']), + ('/a', + ['/a/b/c', + '/a/d/e/f/g', + '/a/d/h/g/h/i']), + ('a', + ['a/b/c/d', + 'a/e/f/g/h', + 'a/i/j/k/']) + ] + for exp, paths in tests: + assert fslpath.commonBase(paths) == exp + + failtests = [ + ['a/b/c', 'd/e/f'], + ['/a/b/c', 'd/e/f'], + ['a', 'b/c/d']] + + for ft in failtests: + with pytest.raises(fslpath.PathError): + fslpath.commonBase(ft)