From 118532dad6d1cb4d46c90d0d04ae3abf812242c3 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Wed, 4 Apr 2018 12:01:32 -0700 Subject: [PATCH] Add deltas_count field to JSON output #79 Signed-off-by: John M. Horan --- src/deltacode/cli.py | 1 + tests/data/cli/scan_sorted01_new.json | 462 ++++++++++++++++++++++++++ tests/data/cli/scan_sorted01_old.json | 462 ++++++++++++++++++++++++++ tests/test_cli.py | 30 ++ 4 files changed, 955 insertions(+) create mode 100644 tests/data/cli/scan_sorted01_new.json create mode 100644 tests/data/cli/scan_sorted01_old.json diff --git a/src/deltacode/cli.py b/src/deltacode/cli.py index 8ac0cb8d..e8c4eec8 100644 --- a/src/deltacode/cli.py +++ b/src/deltacode/cli.py @@ -47,6 +47,7 @@ def write_json(deltacode, outfile, all_delta_types=False): ('deltacode_options', deltacode.options), ('deltacode_version', __version__), ('deltacode_errors', collect_errors(deltacode)), + ('deltas_count', len([d for d in deltas(deltacode, all_delta_types)])), ('deltas', deltas(deltacode, all_delta_types)) ]) diff --git a/tests/data/cli/scan_sorted01_new.json b/tests/data/cli/scan_sorted01_new.json new file mode 100644 index 00000000..27c202ac --- /dev/null +++ b/tests/data/cli/scan_sorted01_new.json @@ -0,0 +1,462 @@ +{ + "scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.", + "scancode_version": "2.9.0b1.post8.2a658c314", + "scancode_options": { + "input": "C:\\code\\nexb\\dev\\codebase01\\sorting\\sorted01_new", + "--copyright": true, + "--info": true, + "--json-pp": "C:\\code\\nexb\\dev\\deltacode\\tests\\data\\deltacode\\scan_sorted01_new.json", + "--license": true, + "--package": true + }, + "files_count": 6, + "files": [ + { + "path": "sorted01_new", + "type": "directory", + "name": "sorted01_new", + "base_name": "sorted01_new", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "mime_type": null, + "file_type": null, + "programming_language": null, + "is_binary": false, + "is_text": false, + "is_archive": false, + "is_media": false, + "is_source": false, + "is_script": false, + "licenses": [], + "copyrights": [], + "packages": [], + "files_count": 6, + "dirs_count": 2, + "size_count": 1230, + "scan_errors": [] + }, + { + "path": "sorted01_new/a", + "type": "directory", + "name": "a", + "base_name": "a", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "mime_type": null, + "file_type": null, + "programming_language": null, + "is_binary": false, + "is_text": false, + "is_archive": false, + "is_media": false, + "is_source": false, + "is_script": false, + "licenses": [], + "copyrights": [], + "packages": [], + "files_count": 2, + "dirs_count": 0, + "size_count": 430, + "scan_errors": [] + }, + { + "path": "sorted01_new/a/a2.py", + "type": "file", + "name": "a2.py", + "base_name": "a2", + "extension": ".py", + "size": 230, + "date": "2018-03-11", + "sha1": "7cda857e87dbbc466f56ceb9db8b87d8d130693e", + "md5": "57c1d54390286dc928f841a733b19c66", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_new/a/a4.py", + "type": "file", + "name": "a4.py", + "base_name": "a4", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b", + "md5": "fc403815d6605df989414ff40a64ea17", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_new/b", + "type": "directory", + "name": "b", + "base_name": "b", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "mime_type": null, + "file_type": null, + "programming_language": null, + "is_binary": false, + "is_text": false, + "is_archive": false, + "is_media": false, + "is_source": false, + "is_script": false, + "licenses": [], + "copyrights": [], + "packages": [], + "files_count": 4, + "dirs_count": 0, + "size_count": 800, + "scan_errors": [] + }, + { + "path": "sorted01_new/b/a1.py", + "type": "file", + "name": "a1.py", + "base_name": "a1", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "84b647771481d39dd3a53f6dc210c26abac37748", + "md5": "3cb56efa7140478458dbaa2b30239845", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_new/b/b1.py", + "type": "file", + "name": "b1.py", + "base_name": "b1", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "70f6ce80985578b5104db0abc578cf5a05e78f4b", + "md5": "af9e9420c6c5b2b0ca74e96bf7c1a2f4", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_new/b/b2.py", + "type": "file", + "name": "b2.py", + "base_name": "b2", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "3340d86b1da9323067db8022f86dc97cfccee1d0", + "md5": "74ce2b26cebb32670634270dde1fdf33", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_new/b/b3.py", + "type": "file", + "name": "b3.py", + "base_name": "b3", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "e49d4463662414bee5ad2d2e5c1fbd704f33b84e", + "md5": "8d458f54d32959b03dff37ef485b29c6", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + } + ] +} diff --git a/tests/data/cli/scan_sorted01_old.json b/tests/data/cli/scan_sorted01_old.json new file mode 100644 index 00000000..2ca92272 --- /dev/null +++ b/tests/data/cli/scan_sorted01_old.json @@ -0,0 +1,462 @@ +{ + "scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.", + "scancode_version": "2.9.0b1.post8.2a658c314", + "scancode_options": { + "input": "C:\\code\\nexb\\dev\\codebase01\\sorting\\sorted01_old", + "--copyright": true, + "--info": true, + "--json-pp": "C:\\code\\nexb\\dev\\deltacode\\tests\\data\\deltacode\\scan_sorted01_old.json", + "--license": true, + "--package": true + }, + "files_count": 6, + "files": [ + { + "path": "sorted01_old", + "type": "directory", + "name": "sorted01_old", + "base_name": "sorted01_old", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "mime_type": null, + "file_type": null, + "programming_language": null, + "is_binary": false, + "is_text": false, + "is_archive": false, + "is_media": false, + "is_source": false, + "is_script": false, + "licenses": [], + "copyrights": [], + "packages": [], + "files_count": 6, + "dirs_count": 2, + "size_count": 1200, + "scan_errors": [] + }, + { + "path": "sorted01_old/a", + "type": "directory", + "name": "a", + "base_name": "a", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "mime_type": null, + "file_type": null, + "programming_language": null, + "is_binary": false, + "is_text": false, + "is_archive": false, + "is_media": false, + "is_source": false, + "is_script": false, + "licenses": [], + "copyrights": [], + "packages": [], + "files_count": 3, + "dirs_count": 0, + "size_count": 600, + "scan_errors": [] + }, + { + "path": "sorted01_old/a/a1.py", + "type": "file", + "name": "a1.py", + "base_name": "a1", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "84b647771481d39dd3a53f6dc210c26abac37748", + "md5": "3cb56efa7140478458dbaa2b30239845", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_old/a/a2.py", + "type": "file", + "name": "a2.py", + "base_name": "a2", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "310797523e47db8481aeb06f1634317285115091", + "md5": "19efdad483f68bc9997a5c1f7ba41b26", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_old/a/a3.py", + "type": "file", + "name": "a3.py", + "base_name": "a3", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9", + "md5": "795ff2cae8ece792a9bfebe18ad3c8e6", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_old/b", + "type": "directory", + "name": "b", + "base_name": "b", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "mime_type": null, + "file_type": null, + "programming_language": null, + "is_binary": false, + "is_text": false, + "is_archive": false, + "is_media": false, + "is_source": false, + "is_script": false, + "licenses": [], + "copyrights": [], + "packages": [], + "files_count": 3, + "dirs_count": 0, + "size_count": 600, + "scan_errors": [] + }, + { + "path": "sorted01_old/b/b1.py", + "type": "file", + "name": "b1.py", + "base_name": "b1", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "70f6ce80985578b5104db0abc578cf5a05e78f4b", + "md5": "af9e9420c6c5b2b0ca74e96bf7c1a2f4", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_old/b/b2.py", + "type": "file", + "name": "b2.py", + "base_name": "b2", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "3340d86b1da9323067db8022f86dc97cfccee1d0", + "md5": "74ce2b26cebb32670634270dde1fdf33", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + }, + { + "path": "sorted01_old/b/b3.py", + "type": "file", + "name": "b3.py", + "base_name": "b3", + "extension": ".py", + "size": 200, + "date": "2017-09-26", + "sha1": "e49d4463662414bee5ad2d2e5c1fbd704f33b84e", + "md5": "8d458f54d32959b03dff37ef485b29c6", + "mime_type": "text/plain", + "file_type": "ASCII text, with CRLF line terminators", + "programming_language": "Python", + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": true, + "is_script": false, + "licenses": [ + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive", + "owner": "Apache Software Foundation", + "homepage_url": "http://www.apache.org/licenses/", + "text_url": "http://www.apache.org/licenses/LICENSE-2.0", + "reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:apache-2.0", + "spdx_license_key": "Apache-2.0", + "spdx_url": "https://spdx.org/licenses/Apache-2.0", + "start_line": 3, + "end_line": 3, + "matched_rule": { + "identifier": "apache-2.0_57.RULE", + "license_choice": false, + "licenses": [ + "apache-2.0" + ] + } + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017 Acme Software Inc. and others." + ], + "holders": [ + "Acme Software Inc. and others." + ], + "authors": [], + "start_line": 2, + "end_line": 2 + } + ], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + } + ] +} diff --git a/tests/test_cli.py b/tests/test_cli.py index 1d506d5e..cdc1ab44 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -107,6 +107,8 @@ def test_json_output_option_selected_all_selected(self): assert json_result.get('deltacode_errors') == [] + assert json_result.get('deltas_count') == 8 + moved_expected = { "factors": ['moved'], "score": 0, @@ -265,6 +267,8 @@ def test_json_output_option_selected_all_not_selected(self): assert json_result.get('deltacode_errors') == [] + assert json_result.get('deltas_count') == 1 + moved_expected = { "factors": ["moved"], "score": 0, @@ -414,6 +418,32 @@ def test_no_output_option_selected_all_not_selected(self): assert '"sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9"' not in result.output assert '"original_path": "1_file_moved_new/a/a3.py"' not in result .output + def test_json_deltas_count_all_selected(self): + new_scan = self.get_test_loc('cli/scan_sorted01_new.json') + old_scan = self.get_test_loc('cli/scan_sorted01_old.json') + + result_file = self.get_temp_file('json') + + runner = CliRunner() + result = runner.invoke(cli.cli, ['-n', new_scan, '-o', old_scan, '-j', result_file, '-a']) + + json_result = json.load(open(result_file)) + + assert json_result.get('deltas_count') == 7 + + def test_json_deltas_count_all_not_selected(self): + new_scan = self.get_test_loc('cli/scan_sorted01_new.json') + old_scan = self.get_test_loc('cli/scan_sorted01_old.json') + + result_file = self.get_temp_file('json') + + runner = CliRunner() + result = runner.invoke(cli.cli, ['-n', new_scan, '-o', old_scan, '-j', result_file]) + + json_result = json.load(open(result_file)) + + assert json_result.get('deltas_count') == 4 + def test_help(self): runner = CliRunner() result = runner.invoke(cli.cli, ['--help'])