Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions getgauge/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,34 +171,37 @@ def is_continue_on_failure(self, func, exception):
def get_step_positions(self, file_name):
positions = []
for step, infos in self.__steps_map.items():
positions = positions + [{'stepValue': step, 'span': i.span}
for i in infos if i.file_name == file_name]
positions.extend(
[{'stepValue': step, 'span': i.span} for i in infos if paths_equal(i.file_name, file_name)]
)
return positions

def _get_all_hooks(self, file_name):
all_hooks = []
for hook in self.hooks:
all_hooks = all_hooks + \
[h for h in getattr(self, "__{}".format(hook))
if h.file_name == file_name]
all_hooks.extend(
[h for h in getattr(self, "__{}".format(hook)) if paths_equal(h.file_name, file_name)]
)
return all_hooks

def get_all_methods_in(self, file_name):
methods = []
for _, infos in self.__steps_map.items():
methods = methods + [i for i in infos if i.file_name == file_name]
methods.extend(
[i for i in infos if paths_equal(i.file_name, file_name)]
)
return methods + self._get_all_hooks(file_name)

def is_file_cached(self, file_name):
for _, infos in self.__steps_map.items():
if any(i.file_name == file_name for i in infos):
if any(paths_equal(i.file_name, file_name) for i in infos):
return True
return False

def remove_steps(self, file_name):
new_map = {}
for step, infos in self.__steps_map.items():
filtered_info = [i for i in infos if i.file_name != file_name]
filtered_info = [i for i in infos if not paths_equal(i.file_name, file_name)]
if len(filtered_info) > 0:
new_map[step] = filtered_info
self.__steps_map = new_map
Expand All @@ -209,6 +212,11 @@ def clear(self):
setattr(self, '__{}'.format(hook), [])


def paths_equal(first_file_path, second_file_path):
""" Normalize paths in order to compare them. """
return os.path.normcase(str(first_file_path)) == os.path.normcase(str(second_file_path))


def _filter_hooks(tags, hooks):
filtered_hooks = []
for hook in hooks:
Expand Down
2 changes: 1 addition & 1 deletion python.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "python",
"version": "0.4.11",
"version": "0.4.12",
"description": "Python support for gauge",
"run": {
"windows": [
Expand Down
33 changes: 33 additions & 0 deletions tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import sys
import unittest

from getgauge.registry import Registry
Expand Down Expand Up @@ -361,6 +362,38 @@ def test_Registry_get_all_methods_in_should_give_all_the_methods_define_in_that_
self.assertEqual(3, len(registry.get_all_methods_in("foo.py")))
self.assertEqual(2, len(registry.get_all_methods_in("bar.py")))

@unittest.skipIf(not sys.platform.startswith("win"), "Test is designed to cover Windows like paths")
def test_Registry_get_all_methods_in_should_handle_paths_case_sensitive(self):
lower_c_drive = 'c:/random/path/foo.py'
upper_c_drive = 'C:/random/path/foo.py'

step_infos = [
{'text': 'Foo', 'func': 'func1', 'file_name': lower_c_drive},
{'text': 'Foo <>', 'func': 'func2', 'file_name': upper_c_drive}
]
for info in step_infos:
registry.add_step(info['text'], info['func'], info['file_name'])

""" Note: we should find both steps regardless the different spelling as the path is in fact equal! """
self.assertEqual(2, len(registry.get_all_methods_in(lower_c_drive)))
self.assertEqual(2, len(registry.get_all_methods_in(upper_c_drive)))

@unittest.skipIf(sys.platform.startswith("win"), "Fails on Windows due to case sensitivity")
def test_Registry_get_all_methods_in_should_handle_paths_case_sensitive_on_mac(self):
path1 = '/random/path/foo.py'
path2 = '/random/PATH/foo.py'

step_infos = [
{'text': 'Foo', 'func': 'func1', 'file_name': path1},
{'text': 'Foo <>', 'func': 'func2', 'file_name': path2}
]
for info in step_infos:
registry.add_step(info['text'], info['func'], info['file_name'])

""" Note: since the paths are in fact different, they should be treated as different paths! """
self.assertEqual(1, len(registry.get_all_methods_in(path1)))
self.assertEqual(1, len(registry.get_all_methods_in(path2)))

def tearDown(self):
global registry
registry = Registry()
Expand Down
Loading