Skip to content

Commit

Permalink
Allow for multiple reference text files
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 4, 2021
1 parent f3803fc commit eaefa37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 10 additions & 1 deletion python/plugins/processing/tests/AlgorithmsTestBase.py
Expand Up @@ -368,8 +368,17 @@ def check_results(self, results, context, params, expected):
else:
self.assertEqual(strhash, expected_result['hash'])
elif 'file' == expected_result['type']:
expected_filepath = self.filepath_from_param(expected_result)
result_filepath = results[id]
if isinstance(expected_result.get('name'), list):
# test to see if any match expected
for path in expected_result['name']:
expected_filepath = self.filepath_from_param({'name': path})
if self.checkFilesEqual(expected_filepath, result_filepath):
break
else:
expected_filepath = self.filepath_from_param({'name': expected_result['name'][0]})
else:
expected_filepath = self.filepath_from_param(expected_result)

self.assertFilesEqual(expected_filepath, result_filepath)
elif 'directory' == expected_result['type']:
Expand Down
11 changes: 9 additions & 2 deletions python/testing/__init__.py
Expand Up @@ -196,7 +196,7 @@ def sort_by_pk_or_fid(f):

return True

def assertFilesEqual(self, filepath_expected, filepath_result):
def checkFilesEqual(self, filepath_expected, filepath_result, use_asserts=False):
with open(filepath_expected, 'r') as file_expected:
with open(filepath_result, 'r') as file_result:
diff = difflib.unified_diff(
Expand All @@ -206,7 +206,14 @@ def assertFilesEqual(self, filepath_expected, filepath_result):
tofile='result',
)
diff = list(diff)
self.assertEqual(0, len(diff), ''.join(diff))
eq = not len(diff)
if use_asserts:
self.assertEqual(0, len(diff), ''.join(diff))
else:
return eq

def assertFilesEqual(self, filepath_expected, filepath_result):
self.checkFilesEqual(filepath_expected, filepath_result, use_asserts=True)

def assertDirectoriesEqual(self, dirpath_expected, dirpath_result):
""" Checks whether both directories have the same content (recursively) and raises an assertion error if not. """
Expand Down

0 comments on commit eaefa37

Please sign in to comment.