Skip to content

Commit

Permalink
fixed wrong source file path when opening source file for a file on a…
Browse files Browse the repository at this point in the history
… network
  • Loading branch information
ldgit committed May 7, 2016
1 parent 3cc8b69 commit d6e7c91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
29 changes: 21 additions & 8 deletions app/commands/file_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,31 @@ def _get_test_filepath(self, root, filepath):
return test_filepath.replace('\\', '/')

def _get_source_filepath(self, test_filepath):
filepath = test_filepath.replace('\\', '/')
filepath = self._remove_tests_folder_from_path(filepath)
filepath = test_filepath
if test_filepath.startswith('\\\\'):
separator = '\\'
else:
separator = '/'
filepath = test_filepath.replace('\\', separator)
filepath = self._remove_tests_folder_from_path(filepath, separator)
filepath = self._remove_test_suffix_from_filename(filepath)

return filepath.replace('//', '/')
return filepath

def _remove_tests_folder_from_path(self, filepath):
if self._settings.tests_folder + '/unit' in filepath:
filepath = filepath.replace(self._settings.tests_folder + '/unit', '')
def _remove_tests_folder_from_path(self, filepath, folder_separator='/'):
tests_folder = self._ensure_correct_folder_separator(folder_separator)
if tests_folder + folder_separator + 'unit' in filepath:
filepath = filepath.replace(tests_folder + folder_separator + 'unit' + folder_separator, '')
else:
filepath = filepath.replace(self._settings.tests_folder, '', 1)
return filepath
filepath = filepath.replace(tests_folder + folder_separator, '', 1)

return self._ensure_no_double_forward_slashes(filepath)

def _ensure_no_double_forward_slashes(self, filepath):
return filepath.replace('//', '/')

def _ensure_correct_folder_separator(self, folder_separator):
return self._settings.tests_folder.replace('/', folder_separator).replace('\\', folder_separator)

def _remove_test_suffix_from_filename(self, filepath):
return filepath[:-8] + filepath[-4:]
16 changes: 12 additions & 4 deletions tests/app/commands/test_file_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ def setUp(self):

def test_open_source_file(self):
self.settings.tests_folder = 'tests/unit'

self.command.open_source_file('C:/path/to/root/tests/unit/path/to/fileTest.php', self.window)

self.assertEqual('C:/path/to/root/path/to/file.php', self.window.file_to_open)

def test_open_source_file_works_with_backslashes(self):
self.settings.tests_folder = 'tests/unit'

self.command.open_source_file('C:\\path\\to\\root\\tests\\unit\\path\\to\\fileTest.php', self.window)

self.assertEqual('C:/path/to/root/path/to/file.php', self.window.file_to_open)

def test_open_source_file_works_for_network_paths(self):
self.settings.tests_folder = 'tests'
self.command.open_source_file('\\\\server\\dev\\root\\tests\\unit\\Service\\SearchParametersMapperTest.php',
self.window)
self.assertEqual('\\\\server\\dev\\root\\Service\\SearchParametersMapper.php', self.window.file_to_open)

def test_open_source_file_works_for_network_paths_and_complex_tests_folder(self):
self.settings.tests_folder = 'tests/unit'
self.command.open_source_file('\\\\server\\dev\\root\\tests\\unit\\Service\\SearchParametersMapperTest.php',
self.window)
self.assertEqual('\\\\server\\dev\\root\\Service\\SearchParametersMapper.php', self.window.file_to_open)

def test_open_source_file_when_tests_folder_is_not_unit_test_folder(self):
self.settings.root = 'C:/path/to/root'
self.settings.tests_folder = 'tests_folder'
Expand Down

0 comments on commit d6e7c91

Please sign in to comment.