fix in_base for base='/'
If the base directory already ends with '/' the test failed.
It failed because we added an extra '/' to make sure that '/foobar' is
not under '/foo', so ask '/foobar/'.startswith('/foo/').
Whoever when we have the base already start with '/' we might test:
'/foo/bar/'.startwith('/foo//'), and give a false negative. We
shouldn't have this case, because we normalized the path, but in the
case of the root directory ('/') even a normalized path ends with '/',
and thus when base='/' this function failed.
Some re-factoring was needed to make this base testable.
This commit is contained in:
@@ -1081,12 +1081,38 @@ class TestToolsFunctions(unittest.TestCase):
|
||||
self.assertEqual(prettydate(d='invalid_date'), '[invalid date]')
|
||||
|
||||
|
||||
|
||||
pjoin = os.path.join
|
||||
|
||||
def have_symlinks():
|
||||
return os.name == 'posix'
|
||||
|
||||
|
||||
class Test_Expose__in_base(unittest.TestCase):
|
||||
|
||||
def test_in_base(self):
|
||||
are_under = [ # (sub, base)
|
||||
('/foo/bar', '/foo'),
|
||||
('/foo', '/foo'),
|
||||
('/foo', '/'),
|
||||
('/', '/'),
|
||||
]
|
||||
for sub, base in are_under:
|
||||
self.assertTrue( Expose._Expose__in_base(subdir=sub, basedir=base, sep='/'),
|
||||
'%s is not under %s' % (sub, base) )
|
||||
|
||||
def test_not_in_base(self):
|
||||
are_not_under = [ # (sub, base)
|
||||
('/foobar', '/foo'),
|
||||
('/foo', '/foo/bar'),
|
||||
('/bar', '/foo'),
|
||||
('/foo/bar', '/bar'),
|
||||
('/', '/x'),
|
||||
]
|
||||
for sub, base in are_not_under:
|
||||
self.assertFalse( Expose._Expose__in_base(subdir=sub, basedir=base, sep='/'),
|
||||
'%s should not be under %s' % (sub, base) )
|
||||
|
||||
|
||||
class TestExpose(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user