Skip to content

Commit

Permalink
Change JSON structure in testimony print
Browse files Browse the repository at this point in the history
`testimony --json print` was direct dump of internal testimony data
structures. It was a little awkward to work with from external point of
view.

- new structure is simplified - it's shallow list of tokens and metadata
- the metadata includes test name and class for each test case
  • Loading branch information
mirekdlugosz authored and elyezer committed Aug 5, 2019
1 parent 5f70500 commit 612b384
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions testimony/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,38 @@ def print_report(testcases):
:param testcases: A dict where the key is a path and value is a list of
found testcases on that path.
"""
result = {}
for path, tests in testcases.items():
result[path] = [test.to_dict() for test in tests]
if not SETTINGS['json']:
print('{0}\n{1}\n'.format(
colored(path, attrs=['bold']), '=' * len(path)))
if len(tests) == 0:
print('No test cases found.\n')
if SETTINGS['json']:
result = []
for path, tests in testcases.items():
for test in tests:
title = testcase_title(test)
print('{0}\n{1}\n\n{2}\n'.format(
title, '-' * len(title), test))
test_dict = test.to_dict()
test_data = test_dict['tokens']
testimony_metadata = {}
testimony_metadata['file-path'] = path
testimony_metadata['test-class'] = test.parent_class
testimony_metadata['test-name'] = test.name
testimony_metadata['invalid-tokens'] = test_dict[
'invalid-tokens']
testimony_metadata['rst-parse-messages'] = test_dict[
'rst-parse-messages']
test_data['_testimony'] = testimony_metadata
result.append(test_data)

if SETTINGS['json']:
print(json.dumps(result))
return 0

result = {}
for path, tests in testcases.items():
result[path] = [test.to_dict() for test in tests]
print('{0}\n{1}\n'.format(
colored(path, attrs=['bold']), '=' * len(path)))
if len(tests) == 0:
print('No test cases found.\n')
for test in tests:
title = testcase_title(test)
print('{0}\n{1}\n\n{2}\n'.format(
title, '-' * len(title), test))


def summary_report(testcases):
"""Summary about the test cases report."""
Expand Down

0 comments on commit 612b384

Please sign in to comment.