Skip to content

Commit

Permalink
refactor: code simplications + remove duplicate test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
grimen committed Oct 10, 2019
1 parent bad4567 commit 5b48ff9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 44 deletions.
27 changes: 16 additions & 11 deletions rootpath/detect.py
Expand Up @@ -52,32 +52,37 @@ def find_root_path(current_path, pattern = None):

detecting = True

found_more_files = None
found_root = None
found_system_root = None

file_names = None
root_file_names = None

while (detecting):
file_names = listdir(current_path)
no_more_files = len(file_names) <= 0
found_more_files = bool(len(file_names) > 0)

if no_more_files:
if not found_more_files:
detecting = False

return None

project_root_files = filter(pattern.match, file_names)
project_root_files = list(project_root_files)
root_file_names = filter(pattern.match, file_names)
root_file_names = list(root_file_names)

found_root = len(project_root_files) > 0
found_root = bool(len(root_file_names) > 0)

if found_root:
detecting = False

return current_path

if current_path == '/':
found_system_root = bool(current_path == path.sep)

if found_system_root:
return None

current_path = path.abspath(path.join(current_path, '..'))

return result

root_path = find_root_path(current_path, pattern)

return root_path
return find_root_path(current_path, pattern)
34 changes: 1 addition & 33 deletions rootpath/tests/test_detect.py
Expand Up @@ -84,22 +84,6 @@ def test_rootpath_detect_entry(self):

self.assertEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo'))

self.assertEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/'))

self.assertEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo'))

self.assertEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/'))

self.assertEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/utils'))

self.assertEqual(root_path, foo_root_path)
Expand Down Expand Up @@ -127,22 +111,6 @@ def test_rootpath_detect_entry_pattern(self):

self.assertNotEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo'), 'not_a_file')

self.assertNotEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/'), 'not_a_file')

self.assertNotEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo'), 'not_a_file')

self.assertNotEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/'), 'not_a_file')

self.assertNotEqual(root_path, foo_root_path)

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/utils'), 'not_a_file')

self.assertNotEqual(root_path, foo_root_path)
Expand Down Expand Up @@ -178,7 +146,7 @@ def test_rootpath_detect_entry_nested(self):

self.assertEqual(root_path, bar_root_path)

def test_rootpath_detect_entry_nested(self):
def test_rootpath_detect_entry_nested_pattern(self):
bar_root_path = helper.fixture_path('projects/py-foo/vendor/py-bar')

root_path = rootpath.detect(helper.fixture_path('projects/py-foo/vendor/py-bar'), 'not_a_file')
Expand Down

0 comments on commit 5b48ff9

Please sign in to comment.