Fixing hang in get_module_qualname_from_path
This commit fixes a possible hang in the get_module_qualname... function. When running against a '.' target, the while statement would loop forever looking for a head of '/', when all it would ever find was '.'. Now either option is enough to break the loop. A head of '.' already indicates we're as far down as we can get since there is no non-file path left. Closes-Bug: #1538633 Change-Id: I4aca741b816e4203d6b4da4e62c5edd37d553da4
This commit is contained in:
@@ -186,7 +186,7 @@ def get_module_qualname_from_path(path):
|
||||
' Missing path or file name' % (path))
|
||||
|
||||
qname = [os.path.splitext(tail)[0]]
|
||||
while head != '/':
|
||||
while head not in ['/', '.']:
|
||||
if os.path.isfile(os.path.join(head, '__init__.py')):
|
||||
(head, tail) = os.path.split(head)
|
||||
qname.insert(0, tail)
|
||||
|
||||
@@ -103,6 +103,14 @@ class UtilTests(testtools.TestCase):
|
||||
self.tempdir, 'good', 'a', 'b', 'c', 'test_typical.py'))
|
||||
self.assertEqual('good.a.b.c.test_typical', name)
|
||||
|
||||
def test_get_module_qualname_from_path_with_dot(self):
|
||||
'''Test get_module_qualname_from_path with a "." .'''
|
||||
|
||||
name = b_utils.get_module_qualname_from_path(os.path.join(
|
||||
'.', '__init__.py'))
|
||||
|
||||
self.assertEqual('__init__', name)
|
||||
|
||||
def test_get_module_qualname_from_path_abs_missingmid(self):
|
||||
# Test get_module_qualname_from_path with missing module
|
||||
# __init__.py
|
||||
|
||||
Reference in New Issue
Block a user