Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new duration field to JSON output #1937 #1942

Merged
merged 1 commit into from
Mar 5, 2020
Merged
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ The following organizations or individuals have contributed to ScanCode:
- Tushar Mittal @techytushar
- Martin Petkov @MartinPetkov
- Mrinal Paliwal @mriiinal
- Mankaran Singh @MankaranSingh
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

Outputs:
- The "headers" attribute in JSON outputs now contains a 'duration' field. #1942


v3.0.2 (2019-02-15)
-------------------

Expand Down
1 change: 1 addition & 0 deletions src/scancode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ def echo_func(*_args, **_kwargs):
codebase.counters['final:size_count'] = size_count

cle.end_timestamp = time2tstamp()
cle.duration = time() - processing_start
# collect these once as they are use in the headers and in the displayed summary
errors = collect_errors(codebase, verbose)
cle.errors = errors
Expand Down
1 change: 1 addition & 0 deletions src/scancode/cli_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def streamline_headers(headers):
remove_windows_extra_timeout(hle.get('options', {}))
hle.pop('start_timestamp', None)
hle.pop('end_timestamp', None)
hle.pop('duration', None)
streamline_errors(hle['errors'])


Expand Down
2 changes: 2 additions & 0 deletions src/scancode/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Header(object):
notice = String(default='', help='Notice text for this tool.')
start_timestamp = String(help='Start timestamp for this header.')
end_timestamp = String(help='End timestamp for this header.')
duration = String(help='Scan duration in seconds.')
message = String(help='Message text.')
errors = List(help='List of error messages.')
extra_data = Mapping(help='Mapping of extra key/values for this tool.')
Expand All @@ -153,6 +154,7 @@ def from_dict(cls, **kwargs):
'notice',
'start_timestamp',
'end_timestamp',
'duration',
'message',
'errors',
'extra_data',
Expand Down
8 changes: 8 additions & 0 deletions tests/scancode/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,14 @@ def test_scan_errors_out_with_conflicting_verbosity_options():
'--verbose option(s) and --verbose is used. You can set only one of '
'these options at a time.') in result.output

def test_scan_valid_duration_field_in_json_output_headers():
test_file = test_env.get_test_loc('license_text/test.txt')
result_file = test_env.get_temp_file('results.json')
args = ['--json', result_file, test_file]
run_scan_click(args)
with open(result_file) as result:
headers = json.loads(result.read())['headers']
assert headers[0]['duration'] >= 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!


@pytest.mark.scanslow
@pytest.mark.skipif(on_windows and py3, reason='Somehow this test fails for now on Python 3')
Expand Down