Skip to content

Commit 9deb27a

Browse files
committed
Add test to verify case-sensitive paths, skip the other one if OS is not Windows
Signed-off-by: sschulz92 <[email protected]>
1 parent f2bc30e commit 9deb27a

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

getgauge/registry.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ 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)))
134133
info = StepInfo(step_text, parsed_step_text, func,
135-
normalized_file_path, span, has_alias, aliases)
134+
file_name, span, has_alias, aliases)
136135
self.__steps_map.setdefault(parsed_step_text, []).append(info)
137136
return
138137
for text in step_text:
@@ -220,7 +219,11 @@ def paths_equal(p1: Union[str, Path], p2: Union[str, Path]) -> bool:
220219
"""
221220
p1 = Path(p1).resolve()
222221
p2 = Path(p2).resolve()
223-
return os.path.normcase(str(p1)) == os.path.normcase(str(p2))
222+
if sys.platform.startswith("win"):
223+
# As Windows is case-insensitive, we can use 'normcase' to compare paths!
224+
return os.path.normcase(str(p1)) == os.path.normcase(str(p2))
225+
# Mac (and others) allows to use case-sensitive files/folders!
226+
return p1 == p2
224227

225228

226229
def _filter_hooks(tags, hooks):

tests/test_registry.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import sys
23
import unittest
34

45
from getgauge.registry import Registry
@@ -160,9 +161,12 @@ def test_Registry_before_spec_with_tags(self):
160161
registry.add_before_spec(info['func'], info['tags'])
161162

162163
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'])])
164+
self.assertEqual([x['func'] for x in infos], [
165+
i.impl for i in registry.before_spec(['A', 'b'])])
166+
self.assertEqual([info1['func'], info3['func']], [
167+
i.impl for i in registry.before_spec(['A', 'b', 'c'])])
168+
self.assertEqual([info1['func'], info3['func']], [
169+
i.impl for i in registry.before_spec(['A'])])
166170
self.assertEqual([info1['func']], [i.impl for i in registry.before_spec(['A', 'c'])])
167171

168172
def test_Registry_after_spec_with_tags(self):
@@ -176,9 +180,12 @@ def test_Registry_after_spec_with_tags(self):
176180
registry.add_after_spec(info['func'], info['tags'])
177181

178182
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'])])
183+
self.assertEqual([x['func'] for x in infos], [
184+
i.impl for i in registry.after_spec(['A', 'b'])])
185+
self.assertEqual([info1['func'], info3['func']], [
186+
i.impl for i in registry.after_spec(['A', 'b', 'c'])])
187+
self.assertEqual([info1['func'], info3['func']], [
188+
i.impl for i in registry.after_spec(['A'])])
182189
self.assertEqual([info1['func']], [i.impl for i in registry.after_spec(['A', 'c'])])
183190

184191
def test_Registry_before_scenario(self):
@@ -269,9 +276,12 @@ def test_Registry_before_step_with_tags(self):
269276
registry.add_before_step(info['func'], info['tags'])
270277

271278
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'])])
279+
self.assertEqual([x['func'] for x in infos], [
280+
i.impl for i in registry.before_step(['A', 'b'])])
281+
self.assertEqual([info1['func'], info3['func']], [
282+
i.impl for i in registry.before_step(['A', 'b', 'c'])])
283+
self.assertEqual([info1['func'], info3['func']], [
284+
i.impl for i in registry.before_step(['A'])])
275285
self.assertEqual([info1['func']], [i.impl for i in registry.before_step(['A', 'c'])])
276286

277287
def test_Registry_after_step_with_tags(self):
@@ -286,9 +296,12 @@ def test_Registry_after_step_with_tags(self):
286296
registry.add_after_step(info['func'], info['tags'])
287297

288298
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'])])
299+
self.assertEqual([x['func'] for x in infos], [
300+
i.impl for i in registry.after_step(['A', 'b'])])
301+
self.assertEqual([info1['func'], info3['func']], [
302+
i.impl for i in registry.after_step(['A', 'b', 'c'])])
303+
self.assertEqual([info1['func'], info3['func']], [
304+
i.impl for i in registry.after_step(['A'])])
292305
self.assertEqual([info1['func']], [i.impl for i in registry.after_step(['A', 'c'])])
293306

294307
def test_Registry__step_positions_of_a_given_file(self):
@@ -361,6 +374,7 @@ def test_Registry_get_all_methods_in_should_give_all_the_methods_define_in_that_
361374
self.assertEqual(3, len(registry.get_all_methods_in("foo.py")))
362375
self.assertEqual(2, len(registry.get_all_methods_in("bar.py")))
363376

377+
@unittest.skipIf(sys.platform == "darwin", "Fails on macOS due to case sensitivity")
364378
def test_Registry_get_all_methods_in_should_handle_paths_case_sensitive(self):
365379
lower_c_drive = 'c:/random/path/foo.py'
366380
upper_c_drive = 'C:/random/path/foo.py'
@@ -376,6 +390,22 @@ def test_Registry_get_all_methods_in_should_handle_paths_case_sensitive(self):
376390
self.assertEqual(2, len(registry.get_all_methods_in(lower_c_drive)))
377391
self.assertEqual(2, len(registry.get_all_methods_in(upper_c_drive)))
378392

393+
@unittest.skipIf(sys.platform.startswith("win"), "Fails on macOS due to case sensitivity")
394+
def test_Registry_get_all_methods_in_should_handle_paths_case_sensitive_on_mac(self):
395+
path1 = '/random/path/foo.py'
396+
path2 = '/random/PATH/foo.py'
397+
398+
step_infos = [
399+
{'text': 'Foo', 'func': 'func1', 'file_name': path1},
400+
{'text': 'Foo <>', 'func': 'func2', 'file_name': path2}
401+
]
402+
for info in step_infos:
403+
registry.add_step(info['text'], info['func'], info['file_name'])
404+
405+
""" Note: since the paths are in fact different, they should be treated as different paths! """
406+
self.assertEqual(1, len(registry.get_all_methods_in(path1)))
407+
self.assertEqual(1, len(registry.get_all_methods_in(path2)))
408+
379409
def tearDown(self):
380410
global registry
381411
registry = Registry()

0 commit comments

Comments
 (0)