Skip to content

Commit 5b48ff9

Browse files
committed
refactor: code simplications + remove duplicate test assertions
1 parent bad4567 commit 5b48ff9

File tree

2 files changed

+17
-44
lines changed

2 files changed

+17
-44
lines changed

rootpath/detect.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,37 @@ def find_root_path(current_path, pattern = None):
5252

5353
detecting = True
5454

55+
found_more_files = None
56+
found_root = None
57+
found_system_root = None
58+
59+
file_names = None
60+
root_file_names = None
61+
5562
while (detecting):
5663
file_names = listdir(current_path)
57-
no_more_files = len(file_names) <= 0
64+
found_more_files = bool(len(file_names) > 0)
5865

59-
if no_more_files:
66+
if not found_more_files:
6067
detecting = False
6168

6269
return None
6370

64-
project_root_files = filter(pattern.match, file_names)
65-
project_root_files = list(project_root_files)
71+
root_file_names = filter(pattern.match, file_names)
72+
root_file_names = list(root_file_names)
6673

67-
found_root = len(project_root_files) > 0
74+
found_root = bool(len(root_file_names) > 0)
6875

6976
if found_root:
7077
detecting = False
7178

7279
return current_path
7380

74-
if current_path == '/':
81+
found_system_root = bool(current_path == path.sep)
82+
83+
if found_system_root:
7584
return None
7685

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

79-
return result
80-
81-
root_path = find_root_path(current_path, pattern)
82-
83-
return root_path
88+
return find_root_path(current_path, pattern)

rootpath/tests/test_detect.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,6 @@ def test_rootpath_detect_entry(self):
8484

8585
self.assertEqual(root_path, foo_root_path)
8686

87-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo'))
88-
89-
self.assertEqual(root_path, foo_root_path)
90-
91-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/'))
92-
93-
self.assertEqual(root_path, foo_root_path)
94-
95-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo'))
96-
97-
self.assertEqual(root_path, foo_root_path)
98-
99-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/'))
100-
101-
self.assertEqual(root_path, foo_root_path)
102-
10387
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/utils'))
10488

10589
self.assertEqual(root_path, foo_root_path)
@@ -127,22 +111,6 @@ def test_rootpath_detect_entry_pattern(self):
127111

128112
self.assertNotEqual(root_path, foo_root_path)
129113

130-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo'), 'not_a_file')
131-
132-
self.assertNotEqual(root_path, foo_root_path)
133-
134-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/'), 'not_a_file')
135-
136-
self.assertNotEqual(root_path, foo_root_path)
137-
138-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo'), 'not_a_file')
139-
140-
self.assertNotEqual(root_path, foo_root_path)
141-
142-
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/'), 'not_a_file')
143-
144-
self.assertNotEqual(root_path, foo_root_path)
145-
146114
root_path = rootpath.detect(helper.fixture_path('projects/py-foo/foo/utils'), 'not_a_file')
147115

148116
self.assertNotEqual(root_path, foo_root_path)
@@ -178,7 +146,7 @@ def test_rootpath_detect_entry_nested(self):
178146

179147
self.assertEqual(root_path, bar_root_path)
180148

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

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

0 commit comments

Comments
 (0)