Render proper diffs for duplicate_consistency test (#228)
Use Python's built-in ``diflib`` to compute diffs between the two versions.
This commit is contained in:
parent
9a5caaa95b
commit
8a120b3be7
@ -2,7 +2,9 @@
|
|||||||
Checks that files duplicated across schemes/implementations are consistent.
|
Checks that files duplicated across schemes/implementations are consistent.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import difflib
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -31,8 +33,9 @@ def pytest_generate_tests(metafunc):
|
|||||||
for file in group['files']:
|
for file in group['files']:
|
||||||
argvalues.append((implementation, source, file))
|
argvalues.append((implementation, source, file))
|
||||||
ids.append(
|
ids.append(
|
||||||
"{scheme.name}-{source.scheme.name}: {file}"
|
"{scheme.name} {implementation.name} {source.scheme.name}: {file}"
|
||||||
.format(scheme=scheme, source=source,
|
.format(scheme=scheme, source=source,
|
||||||
|
implementation=implementation,
|
||||||
file=file))
|
file=file))
|
||||||
metafunc.parametrize(('implementation', 'source', 'file'),
|
metafunc.parametrize(('implementation', 'source', 'file'),
|
||||||
argvalues,
|
argvalues,
|
||||||
@ -47,17 +50,25 @@ def file_get_contents(filename):
|
|||||||
@helpers.skip_windows()
|
@helpers.skip_windows()
|
||||||
@helpers.filtered_test
|
@helpers.filtered_test
|
||||||
def test_duplicate_consistency(implementation, source, file):
|
def test_duplicate_consistency(implementation, source, file):
|
||||||
transformed_src = helpers.run_subprocess(
|
target_path = os.path.join(source.path(), file)
|
||||||
['sed', '-e', 's/{}/{}/g'.format(source.namespace_prefix(),
|
this_path = os.path.join(implementation.path(), file)
|
||||||
implementation.namespace_prefix()), os.path.join(source.path(), file)]
|
target_src = file_get_contents(target_path)
|
||||||
)
|
this_src = file_get_contents(this_path)
|
||||||
this_src = file_get_contents(os.path.join(implementation.path(), file))
|
this_transformed_src = this_src.replace(
|
||||||
print(os.path.join(implementation.path(), file))
|
implementation.namespace_prefix(), '')
|
||||||
print(this_src)
|
target_transformed_src = target_src.replace(source.namespace_prefix(), '')
|
||||||
assert(transformed_src == this_src)
|
|
||||||
|
if not this_transformed_src == target_transformed_src:
|
||||||
|
diff = difflib.unified_diff(
|
||||||
|
this_transformed_src.splitlines(keepends=True),
|
||||||
|
target_transformed_src.splitlines(keepends=True),
|
||||||
|
fromfile=this_path,
|
||||||
|
tofile=target_path)
|
||||||
|
raise AssertionError(
|
||||||
|
"Files differed:\n"
|
||||||
|
+ ''.join(diff))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import pytest
|
import pytest
|
||||||
import sys
|
|
||||||
pytest.main(sys.argv)
|
pytest.main(sys.argv)
|
||||||
|
Loading…
Reference in New Issue
Block a user