Skip to content

Commit 77dbc6b

Browse files
committed
Add unit test, normalize path while adding a step too
Signed-off-by: sschulz92 <bastie92_spam@gmx.de>
1 parent 7d0814d commit 77dbc6b

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

getgauge/registry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ def add(self, func=None, tags=None, file_name=""):
130130
def add_step(self, step_text, func, file_name, span=None, has_alias=False, aliases=None):
131131
if not isinstance(step_text, list):
132132
parsed_step_text = _get_step_value(step_text)
133+
normalized_file_path = os.path.normcase(str(Path(file_name)))
133134
info = StepInfo(step_text, parsed_step_text, func,
134-
file_name, span, has_alias, aliases)
135+
normalized_file_path, span, has_alias, aliases)
135136
self.__steps_map.setdefault(parsed_step_text, []).append(info)
136137
return
137138
for text in step_text:
@@ -193,7 +194,7 @@ def get_all_methods_in(self, file_name):
193194

194195
def is_file_cached(self, file_name):
195196
for _, infos in self.__steps_map.items():
196-
if any(Path(i.file_name).resolve() == Path(file_name).resolve() for i in infos):
197+
if any(paths_equal(i.file_name, file_name) for i in infos):
197198
return True
198199
return False
199200

tests/test_registry.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,12 @@ def test_Registry_before_spec_with_tags(self):
160160
registry.add_before_spec(info['func'], info['tags'])
161161

162162
self.assertEqual([info1['func']], [i.impl for i in registry.before_spec([])])
163-
self.assertEqual([x['func'] for x in infos], [i.impl for i in registry.before_spec(['A', 'b'])])
164-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.before_spec(['A', 'b', 'c'])])
165-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.before_spec(['A'])])
163+
self.assertEqual([x['func'] for x in infos], [
164+
i.impl for i in registry.before_spec(['A', 'b'])])
165+
self.assertEqual([info1['func'], info3['func']], [
166+
i.impl for i in registry.before_spec(['A', 'b', 'c'])])
167+
self.assertEqual([info1['func'], info3['func']], [
168+
i.impl for i in registry.before_spec(['A'])])
166169
self.assertEqual([info1['func']], [i.impl for i in registry.before_spec(['A', 'c'])])
167170

168171
def test_Registry_after_spec_with_tags(self):
@@ -176,9 +179,12 @@ def test_Registry_after_spec_with_tags(self):
176179
registry.add_after_spec(info['func'], info['tags'])
177180

178181
self.assertEqual([info1['func']], [i.impl for i in registry.after_spec([])])
179-
self.assertEqual([x['func'] for x in infos], [i.impl for i in registry.after_spec(['A', 'b'])])
180-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.after_spec(['A', 'b', 'c'])])
181-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.after_spec(['A'])])
182+
self.assertEqual([x['func'] for x in infos], [
183+
i.impl for i in registry.after_spec(['A', 'b'])])
184+
self.assertEqual([info1['func'], info3['func']], [
185+
i.impl for i in registry.after_spec(['A', 'b', 'c'])])
186+
self.assertEqual([info1['func'], info3['func']], [
187+
i.impl for i in registry.after_spec(['A'])])
182188
self.assertEqual([info1['func']], [i.impl for i in registry.after_spec(['A', 'c'])])
183189

184190
def test_Registry_before_scenario(self):
@@ -269,9 +275,12 @@ def test_Registry_before_step_with_tags(self):
269275
registry.add_before_step(info['func'], info['tags'])
270276

271277
self.assertEqual([info1['func']], [i.impl for i in registry.before_step([])])
272-
self.assertEqual([x['func'] for x in infos], [i.impl for i in registry.before_step(['A', 'b'])])
273-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.before_step(['A', 'b', 'c'])])
274-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.before_step(['A'])])
278+
self.assertEqual([x['func'] for x in infos], [
279+
i.impl for i in registry.before_step(['A', 'b'])])
280+
self.assertEqual([info1['func'], info3['func']], [
281+
i.impl for i in registry.before_step(['A', 'b', 'c'])])
282+
self.assertEqual([info1['func'], info3['func']], [
283+
i.impl for i in registry.before_step(['A'])])
275284
self.assertEqual([info1['func']], [i.impl for i in registry.before_step(['A', 'c'])])
276285

277286
def test_Registry_after_step_with_tags(self):
@@ -286,9 +295,12 @@ def test_Registry_after_step_with_tags(self):
286295
registry.add_after_step(info['func'], info['tags'])
287296

288297
self.assertEqual([info1['func']], [i.impl for i in registry.after_step([])])
289-
self.assertEqual([x['func'] for x in infos], [i.impl for i in registry.after_step(['A', 'b'])])
290-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.after_step(['A', 'b', 'c'])])
291-
self.assertEqual([info1['func'], info3['func']], [i.impl for i in registry.after_step(['A'])])
298+
self.assertEqual([x['func'] for x in infos], [
299+
i.impl for i in registry.after_step(['A', 'b'])])
300+
self.assertEqual([info1['func'], info3['func']], [
301+
i.impl for i in registry.after_step(['A', 'b', 'c'])])
302+
self.assertEqual([info1['func'], info3['func']], [
303+
i.impl for i in registry.after_step(['A'])])
292304
self.assertEqual([info1['func']], [i.impl for i in registry.after_step(['A', 'c'])])
293305

294306
def test_Registry__step_positions_of_a_given_file(self):
@@ -361,6 +373,21 @@ def test_Registry_get_all_methods_in_should_give_all_the_methods_define_in_that_
361373
self.assertEqual(3, len(registry.get_all_methods_in("foo.py")))
362374
self.assertEqual(2, len(registry.get_all_methods_in("bar.py")))
363375

376+
def test_Registry_get_all_methods_in_should_handle_paths_case_sensitive(self):
377+
lower_c_drive = 'c:/random/path/foo.py'
378+
upper_c_drive = 'C:/random/path/foo.py'
379+
380+
step_infos = [
381+
{'text': 'Foo', 'func': 'func1', 'file_name': lower_c_drive},
382+
{'text': 'Foo <>', 'func': 'func2', 'file_name': upper_c_drive}
383+
]
384+
for info in step_infos:
385+
registry.add_step(info['text'], info['func'], info['file_name'])
386+
387+
""" Note: we should find both steps regardless the different spelling as the path is in fact equal! """
388+
self.assertEqual(2, len(registry.get_all_methods_in(lower_c_drive)))
389+
self.assertEqual(2, len(registry.get_all_methods_in(upper_c_drive)))
390+
364391
def tearDown(self):
365392
global registry
366393
registry = Registry()

0 commit comments

Comments
 (0)