From e2026ef549cf06d8a9266b76f8f88bf133613aeb Mon Sep 17 00:00:00 2001 From: Pratik Dey Date: Tue, 23 Mar 2021 19:35:15 +0530 Subject: [PATCH 1/3] Test Signed-off-by: Pratik Dey --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 9372cd72..6859a04a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ zip_safe = false install_requires = bitarray==1.1.0 commoncode + scancode-toolkit click simplejson unicodecsv From 477cc58da399536c6b8fe156b6b22e6eb38f8140 Mon Sep 17 00:00:00 2001 From: Pratik Dey Date: Tue, 23 Mar 2021 20:18:05 +0530 Subject: [PATCH 2/3] resolved dependency Signed-off-by: Pratik Dey --- setup.cfg | 1 - src/deltacode/__init__.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 6859a04a..9372cd72 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,6 @@ zip_safe = false install_requires = bitarray==1.1.0 commoncode - scancode-toolkit click simplejson unicodecsv diff --git a/src/deltacode/__init__.py b/src/deltacode/__init__.py index 02dc3198..1fb199c2 100644 --- a/src/deltacode/__init__.py +++ b/src/deltacode/__init__.py @@ -30,7 +30,7 @@ from deltacode.models import File from deltacode.models import Scan from deltacode import utils - +from commoncode.resource import VirtualCodebase from pkg_resources import get_distribution, DistributionNotFound try: From ee639bfe0feb67d6703ed980d22aa54521b90f76 Mon Sep 17 00:00:00 2001 From: Pratik Dey Date: Wed, 24 Mar 2021 00:11:04 +0530 Subject: [PATCH 3/3] base outline Signed-off-by: Pratik Dey --- setup.cfg | 2 +- src/deltacode/__init__.py | 521 +++--- src/deltacode/cli.py | 3 +- src/deltacode/test_utils.py | 7 +- src/deltacode/utils.py | 192 ++- tests/__init__.py | 0 tests/data/cli/scan_1_file_moved_new.json | 8 - tests/data/cli/scan_1_file_moved_old.json | 8 - .../deltacode/Delta_to_dict_removed_new.json | 57 + .../deltacode/Delta_to_dict_removed_old.json | 86 + .../data/deltacode/coala-expected-result.json | 60 +- .../deltacode/delta_to_dict_added_new.json | 29 + .../deltacode/delta_to_dict_added_old.json | 20 + .../deltacode/delta_to_dict_modified_new.json | 19 + .../deltacode/delta_to_dict_modified_old.json | 19 + .../deltacode/delta_to_dict_moved_new.json | 20 + .../deltacode/delta_to_dict_moved_old.json | 20 + ..._copyright_statements_and_holders_new.json | 74 + ..._copyright_statements_and_holders_old.json | 32 + .../delta_to_dict_unmodified_new.json | 20 + .../delta_to_dict_unmodified_old.json | 20 + .../no_lic_to_all_notable_lic_new.json | 2 - .../no_lic_to_all_notable_lic_old.json | 2 - ..._copyright_and_license_info_added_new.json | 2 - ..._copyright_and_license_info_added_old.json | 2 - ...opyright_and_license_info_removed_old.json | 2 - ...opyright_change_no_license_change_new.json | 2 - ...opyright_change_no_license_change_old.json | 2 - ...t_info_added_license_info_removed_new.json | 2 - ...t_info_added_license_info_removed_old.json | 2 - .../score_copyright_info_removed_new.json | 2 - .../score_copyright_info_removed_old.json | 2 - ...icense_change_no_copyright_change_new.json | 2 - ...icense_change_no_copyright_change_old.json | 2 - ...pyright_info_copyright_info_added_new.json | 27 + ...pyright_info_copyright_info_added_old.json | 18 + ...right_info_copyright_info_removed_new.json | 18 + ...right_info_copyright_info_removed_old.json | 27 + ...ght_info_file_added_one_copyright_new.json | 36 + ...ght_info_file_added_one_copyright_old.json | 20 + ...pyright_info_no_copyright_changes_new.json | 27 + ...pyright_info_no_copyright_changes_old.json | 27 + ...right_info_no_copyright_key_value_new.json | 17 + ...right_info_no_copyright_key_value_old.json | 17 + ..._from_copyright_info_non_modified_new.json | 25 + ..._from_copyright_info_non_modified_old.json | 25 + ...opyright_info_one_copyright_added_new.json | 35 + ...opyright_info_one_copyright_added_old.json | 27 + ...yright_info_one_copyright_removed_new.json | 27 + ...yright_info_one_copyright_removed_old.json | 35 + ...gle_copyright_change_holders_only_new.json | 25 + ...gle_copyright_change_holders_only_old.json | 25 + ...ight_info_single_copyright_change_new.json | 27 + ...ight_info_single_copyright_change_old.json | 27 + ..._copyright_change_statements_only_new.json | 25 + ..._copyright_change_statements_only_old.json | 25 + ..._copyright_and_license_info_added_new.json | 35 + ..._copyright_and_license_info_added_old.json | 19 + ...opyright_and_license_info_removed_new.json | 19 + ...opyright_and_license_info_removed_old.json | 35 + ...opyright_change_no_license_change_new.json | 44 + ...opyright_change_no_license_change_old.json | 36 + ...t_info_added_license_info_removed_new.json | 29 + ...t_info_added_license_info_removed_old.json | 27 + ..._commercial_and_copyleft_licenses_new.json | 52 + ..._commercial_and_copyleft_licenses_old.json | 20 + ..._copyright_and_permissive_license_new.json | 44 + ..._copyright_and_permissive_license_old.json | 20 + ...icense_change_no_copyright_change_new.json | 41 + ...icense_change_no_copyright_change_old.json | 35 + ...info_added_copyright_info_removed_new.json | 27 + ...info_added_copyright_info_removed_old.json | 29 + ..._info_copyleft_license_info_added_new.json | 26 + ..._info_copyleft_license_info_added_old.json | 19 + ...nfo_copyleft_license_info_removed_new.json | 18 + ...nfo_copyleft_license_info_removed_old.json | 25 + ...info_copyleft_to_copyleft_limited_new.json | 25 + ...info_copyleft_to_copyleft_limited_old.json | 25 + ...fo_copyleft_to_different_copyleft_new.json | 26 + ...fo_copyleft_to_different_copyleft_old.json | 25 + ...m_license_info_no_license_changes_new.json | 25 + ...m_license_info_no_license_changes_old.json | 25 + ...license_info_no_license_key_value_new.json | 17 + ...license_info_no_license_key_value_old.json | 17 + ...om_license_info_one_license_added_new.json | 31 + ...om_license_info_one_license_added_old.json | 25 + ..._license_info_one_license_removed_new.json | 25 + ..._license_info_one_license_removed_old.json | 31 + ...missive_to_six_copyleft_or_higher_new.json | 67 + ...missive_to_six_copyleft_or_higher_old.json | 25 + ...one_permissive_to_two_permissives_new.json | 31 + ...one_permissive_to_two_permissives_old.json | 25 + ...nfo_permissive_license_info_added_new.json | 25 + ...nfo_permissive_license_info_added_old.json | 18 + ...o_permissive_license_info_removed_new.json | 18 + ...o_permissive_license_info_removed_old.json | 25 + ...icense_info_single_license_change_new.json | 25 + ...icense_info_single_license_change_old.json | 25 + ...two_permissives_to_one_permissive_new.json | 25 + ...two_permissives_to_one_permissive_old.json | 31 + tests/test_cli.py | 261 +-- tests/test_deltacode.py | 775 ++++----- tests/test_utils.py | 1523 +++-------------- 103 files changed, 3380 insertions(+), 2221 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/data/deltacode/Delta_to_dict_removed_new.json create mode 100644 tests/data/deltacode/Delta_to_dict_removed_old.json create mode 100644 tests/data/deltacode/delta_to_dict_added_new.json create mode 100644 tests/data/deltacode/delta_to_dict_added_old.json create mode 100644 tests/data/deltacode/delta_to_dict_modified_new.json create mode 100644 tests/data/deltacode/delta_to_dict_modified_old.json create mode 100644 tests/data/deltacode/delta_to_dict_moved_new.json create mode 100644 tests/data/deltacode/delta_to_dict_moved_old.json create mode 100644 tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_new.json create mode 100644 tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_old.json create mode 100644 tests/data/deltacode/delta_to_dict_unmodified_new.json create mode 100644 tests/data/deltacode/delta_to_dict_unmodified_old.json create mode 100644 tests/data/utils/update_from_copyright_info_copyright_info_added_new.json create mode 100644 tests/data/utils/update_from_copyright_info_copyright_info_added_old.json create mode 100644 tests/data/utils/update_from_copyright_info_copyright_info_removed_new.json create mode 100644 tests/data/utils/update_from_copyright_info_copyright_info_removed_old.json create mode 100644 tests/data/utils/update_from_copyright_info_file_added_one_copyright_new.json create mode 100644 tests/data/utils/update_from_copyright_info_file_added_one_copyright_old.json create mode 100644 tests/data/utils/update_from_copyright_info_no_copyright_changes_new.json create mode 100644 tests/data/utils/update_from_copyright_info_no_copyright_changes_old.json create mode 100644 tests/data/utils/update_from_copyright_info_no_copyright_key_value_new.json create mode 100644 tests/data/utils/update_from_copyright_info_no_copyright_key_value_old.json create mode 100644 tests/data/utils/update_from_copyright_info_non_modified_new.json create mode 100644 tests/data/utils/update_from_copyright_info_non_modified_old.json create mode 100644 tests/data/utils/update_from_copyright_info_one_copyright_added_new.json create mode 100644 tests/data/utils/update_from_copyright_info_one_copyright_added_old.json create mode 100644 tests/data/utils/update_from_copyright_info_one_copyright_removed_new.json create mode 100644 tests/data/utils/update_from_copyright_info_one_copyright_removed_old.json create mode 100644 tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_new.json create mode 100644 tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_old.json create mode 100644 tests/data/utils/update_from_copyright_info_single_copyright_change_new.json create mode 100644 tests/data/utils/update_from_copyright_info_single_copyright_change_old.json create mode 100644 tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_new.json create mode 100644 tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_old.json create mode 100644 tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_new.json create mode 100644 tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_old.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_license_info_added_new.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_license_info_added_old.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_license_info_removed_new.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_license_info_removed_old.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_new.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_old.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_new.json create mode 100644 tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_old.json create mode 100644 tests/data/utils/update_from_license_info_no_license_changes_new.json create mode 100644 tests/data/utils/update_from_license_info_no_license_changes_old.json create mode 100644 tests/data/utils/update_from_license_info_no_license_key_value_new.json create mode 100644 tests/data/utils/update_from_license_info_no_license_key_value_old.json create mode 100644 tests/data/utils/update_from_license_info_one_license_added_new.json create mode 100644 tests/data/utils/update_from_license_info_one_license_added_old.json create mode 100644 tests/data/utils/update_from_license_info_one_license_removed_new.json create mode 100644 tests/data/utils/update_from_license_info_one_license_removed_old.json create mode 100644 tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_new.json create mode 100644 tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_old.json create mode 100644 tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_new.json create mode 100644 tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_old.json create mode 100644 tests/data/utils/update_from_license_info_permissive_license_info_added_new.json create mode 100644 tests/data/utils/update_from_license_info_permissive_license_info_added_old.json create mode 100644 tests/data/utils/update_from_license_info_permissive_license_info_removed_new.json create mode 100644 tests/data/utils/update_from_license_info_permissive_license_info_removed_old.json create mode 100644 tests/data/utils/update_from_license_info_single_license_change_new.json create mode 100644 tests/data/utils/update_from_license_info_single_license_change_old.json create mode 100644 tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_new.json create mode 100644 tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_old.json diff --git a/setup.cfg b/setup.cfg index 9372cd72..b411fddc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ include_package_data = true zip_safe = false install_requires = bitarray==1.1.0 - commoncode + commoncode>=21.6.11 click simplejson unicodecsv diff --git a/src/deltacode/__init__.py b/src/deltacode/__init__.py index 1fb199c2..7f00bdda 100644 --- a/src/deltacode/__init__.py +++ b/src/deltacode/__init__.py @@ -25,62 +25,66 @@ from __future__ import absolute_import +import os from collections import OrderedDict -from deltacode.models import File -from deltacode.models import Scan from deltacode import utils +from commoncode import paths from commoncode.resource import VirtualCodebase + from pkg_resources import get_distribution, DistributionNotFound + try: - __version__ = get_distribution('deltacode').version + __version__ = get_distribution("deltacode").version except DistributionNotFound: # package is not installed ?? - __version__ = '1.0.0' + __version__ = "1.0.0" SIMILARITY_LIMIT = 35 + class DeltaCode(object): """ Handle the basic operations on a pair of incoming ScanCode scans (in JSON format) and the Delta objects created from a comparison of the files (in the form of File objects) contained in those scans. """ + def __init__(self, new_path, old_path, options): - self.new = Scan(new_path) - self.old = Scan(old_path) + self.codebase1 = None + self.codebase2 = None self.options = options self.deltas = [] self.errors = [] - self.stats = Stat(self.new.files_count, self.old.files_count) - - if self.new.path != '' and self.old.path != '': - self.determine_delta() - self.determine_moved() - self.license_diff() - self.copyright_diff() - self.stats.calculate_stats() - self.similarity() - # Sort deltas by score, descending, i.e., high > low, and then by - # factors, alphabetically. Run the least significant sort first. - self.deltas.sort(key=lambda Delta: Delta.factors, reverse=False) - self.deltas.sort(key=lambda Delta: Delta.score, reverse=True) - - def align_scans(self): - """ - Seek to align the paths of a pair of files (File objects) in the pair - of incoming scans so that the attributes and other characteristics of - the files can be compared with one another. Call utils.fix_trees(), - which calls utils.align_trees(). - """ - try: - utils.fix_trees(self.new.files, self.old.files) - except utils.AlignmentException: - for f in self.new.files: - f.original_path = f.path - for f in self.old.files: - f.original_path = f.path + + if os.path.isfile(new_path) and os.path.isfile(old_path): + self.codebase1 = VirtualCodebase(new_path) + self.codebase2 = VirtualCodebase(old_path) + else: + error_message = ( + "{} is expected to be a file".format(new_path) + if not os.path.isfile(new_path) + else "{} is expected to be a file".format(old_path) + ) + raise utils.FileError(error_message) + self.stats = Stat( + self.codebase1.compute_counts()[0], self.codebase2.compute_counts()[0] + ) + self.new_scan_options = [] + self.old_scan_options = [] + self.new_files_errors = [] + self.old_files_errors = [] + self.determine_delta() + self.options_diff() + self.license_diff() + self.copyright_diff() + self.stats.calculate_stats() + self.similarity() + # Sort deltas by score, descending, i.e., high > low, and then by + # factors, alphabetically. Run the least significant sort first. + self.deltas.sort(key=lambda Delta: Delta.factors, reverse=False) + self.deltas.sort(key=lambda Delta: Delta.score, reverse=True) def similarity(self): """ @@ -93,129 +97,165 @@ def similarity(self): for delta in self.deltas: if delta.new_file == None or delta.old_file == None: continue - new_fingerprint = delta.new_file.fingerprint - old_fingerprint = delta.old_file.fingerprint + new_fingerprint = ( + delta.new_file.fingerprint + if hasattr(delta.new_file, "fingerprint") + else None + ) + old_fingerprint = ( + delta.old_file.fingerprint + if hasattr(delta.old_file, "fingerprint") + else None + ) + if new_fingerprint == None or old_fingerprint == None: continue new_fingerprint = utils.bitarray_from_hex(delta.new_file.fingerprint) old_fingerprint = utils.bitarray_from_hex(delta.old_file.fingerprint) + hamming_distance = utils.hamming_distance(new_fingerprint, old_fingerprint) if hamming_distance > 0 and hamming_distance <= SIMILARITY_LIMIT: delta.score += hamming_distance - delta.factors.append('Similar with hamming distance : {}'.format(hamming_distance)) + delta.factors.append( + "Similar with hamming distance : {}".format(hamming_distance) + ) - def determine_delta(self): + def create_deltas( + self, new_resource, old_resource, new_path, old_path, score, status + ): """ - Add to a list of Delta objects that can be sorted by their attributes, - e.g., by Delta.score. Return None if no File objects can be loaded - from either scan. + Creates the Delta Objects and appends them to the member list. """ - # align scan and create our index - self.align_scans() - new_index = self.new.index_files() - old_index = self.old.index_files() - - # gathering counts to ensure no files lost or missing from our 'deltas' set - new_visited, old_visited = 0, 0 - - # perform the deltas - for path, new_files in new_index.items(): - for new_file in new_files: - - if new_file.type != 'file': - continue - - new_visited += 1 - - try: - delta_old_files = old_index[path] - except KeyError: - delta = Delta(100, new_file, None) - delta.status = 'added' - self.stats.num_added += 1 - self.deltas.append(delta) - continue - - # at this point, we have a delta_old_file. - # we need to determine wheather this is identical, - # or a modification. - for f in delta_old_files: - # TODO: make sure sha1 is NOT empty - if new_file.sha1 == f.sha1: - delta = Delta(0, new_file, f) - delta.status = 'unmodified' - self.stats.num_unmodified += 1 - self.deltas.append(delta) - continue - else: - delta = Delta(20, new_file, f) - delta.status = 'modified' - self.stats.num_modified += 1 - self.deltas.append(delta) - - # now time to find the added. - for path, old_files in old_index.items(): - for old_file in old_files: - if old_file.type != 'file': - continue - - old_visited += 1 - - try: - # This file already classified so do nothing - new_index[path] - except KeyError: - delta = Delta(0, None, old_file) - delta.status = 'removed' - self.stats.num_removed += 1 - self.deltas.append(delta) - continue - - # make sure everything is accounted for - if new_visited != self.new.files_count: - self.errors.append( - 'DeltaCode Warning: new_visited({}) != new_total({}). Assuming old scancode format.'.format(new_visited, self.new.files_count) - ) - - if old_visited != self.old.files_count: - self.errors.append( - 'DeltaCode Warning: old_visited({}) != old_total({}). Assuming old scancode format.'.format(old_visited, self.old.files_count) - ) + delta = Delta(score, new_resource, old_resource) + delta.status = status + self.deltas.append(delta) - def determine_moved(self): + def determine_delta(self): """ - Modify the list of Delta objects by creating an index of - 'removed' Delta objects and an index of 'added' Delta objects indexed - by their 'sha1' attribute, identifying any unique pairs of Deltas in - both indices with the same 'sha1' and File 'name' attributes, and - converting each such pair of 'added' and 'removed' Delta objects to a - 'moved' Delta object. The 'added' and 'removed' indices are defined by - the presence/absence of the object's 'old_file' and 'new_file'. + Create Delta objects and append them to the list. Top Down BFS Traversal is used + to visit the codebase structures of the old and new Codebase Directiries. """ - added = self.index_deltas('sha1', [i for i in self.deltas if i.old_file is None and i.new_file]) - removed = self.index_deltas('sha1', [i for i in self.deltas if i.old_file and i.new_file is None]) - for added_sha1, added_deltas in added.items(): - for removed_sha1, removed_deltas in removed.items(): + old_resource_considered = set() + # Set to keep track of the old resources visited + try: + Delta.NEW_CODEBASE_OFFSET, Delta.OLD_CODEBASE_OFFSET = utils.align_trees( + self.codebase1, self.codebase2 + ) + except utils.AlignmentException: + Delta.NEW_CODEBASE_OFFSET, Delta.OLD_CODEBASE_OFFSET = 0, 0 + + for new_resource in self.codebase1.walk(): + # Visit each resource of the new codebase in a Top Down BFS fashion + if new_resource.is_file: + path_new = "/".join( + paths.split(new_resource.path)[Delta.NEW_CODEBASE_OFFSET :] + ) + # If the resource is a file align its path + + old_resource = self.codebase2.get_resource_from_path(path_new) + # Check in the old codebase weather a resource with such a path exists or not + # if it exists and their corresponding sha's are same then its an unmodified delta + + if old_resource and old_resource.sha1 == new_resource.sha1: + old_resource_considered.add(old_resource.path) + path_old = "/".join( + paths.split(old_resource.path)[Delta.OLD_CODEBASE_OFFSET :] + ) + self.create_deltas( + new_resource, old_resource, path_new, path_old, 0, "unmodified", + ) + self.stats.num_unmodified += 1 - # check for matching sha1s on both sides - if utils.check_moved(added_sha1, added_deltas, removed_sha1, removed_deltas): - self.update_deltas(added_deltas.pop(), removed_deltas.pop()) + continue + + + # Now when we do not get old resources with the same name + ADDED = True + for old_resource in self.codebase2.walk(): + # Visit each resource of the new codebase in a Bottom Up BFS fashion + if old_resource.path in old_resource_considered: + # If old resources are previously considered then continue + continue + path_old = "/".join( + paths.split(old_resource.path)[Delta.OLD_CODEBASE_OFFSET :] + ) + # Make the path aligned + if ( + old_resource.is_file + and not old_resource.path in old_resource_considered + ): + # If the old resource is a file and currently unvisited + + if path_new == path_old: + # Old and New Resources are having the same path after alignment + ADDED = False + if new_resource.sha1 == old_resource.sha1: + # They are having same sha1 + old_resource_considered.add(old_resource.path) + self.create_deltas( + new_resource, + old_resource, + path_new, + path_old, + 0, + "unmodified", + ) + self.stats.num_unmodified += 1 + break + else: + # They are having different sha1 + old_resource_considered.add(old_resource.path) + self.create_deltas( + new_resource, + old_resource, + path_new, + path_old, + 20, + "modified", + ) + self.stats.num_modified += 1 + break + else: + # Their paths are different + if new_resource.sha1 == old_resource.sha1: + # THey are having the same sha1 + old_resource_considered.add(old_resource.path) + ADDED = False + self.create_deltas( + new_resource, + old_resource, + path_new, + path_old, + 0, + "moved", + ) + self.stats.num_moved += 1 + break + + if ADDED: + # If none of the above criteria matches then the delta is an added one. + self.create_deltas( + new_resource, None, path_new, None, 100, "added", + ) + self.stats.num_added += 1 - def update_deltas(self, added, removed): - """ - Convert the matched 'added' and 'removed' Delta objects to a combined - 'moved' Delta object -- passing the appropriate 'score' during object - creation -- and delete the 'added' and 'removed' objects. - """ - delta = Delta(0, added.new_file, removed.old_file) - delta.status = 'moved' - self.stats.num_moved += 1 - self.stats.num_added -= 1 - self.stats.num_removed -= 1 - self.deltas.append(delta) - self.deltas.remove(added) - self.deltas.remove(removed) + for old_resource_remaining in self.codebase2.walk(): + # Now again visit the old codebase in a top down fashion + # If any delta is left out it is a case of removed delta + if ( + old_resource_remaining.is_file + and old_resource_remaining.path not in old_resource_considered + ): + path_old = "/".join( + paths.split(old_resource_remaining.path)[ + Delta.OLD_CODEBASE_OFFSET : + ] + ) + self.create_deltas( + None, old_resource_remaining, None, path_old, 0, "removed", + ) + self.stats.num_removed += 1 def license_diff(self): """ @@ -226,14 +266,16 @@ def license_diff(self): has been a license change. """ # TODO: Figure out the best way to handle this. - unique_categories = set([ - 'Commercial', - 'Copyleft', - 'Copyleft Limited', - 'Free Restricted', - 'Patent License', - 'Proprietary Free' - ]) + unique_categories = set( + [ + "Commercial", + "Copyleft", + "Copyleft Limited", + "Free Restricted", + "Patent License", + "Proprietary Free", + ] + ) for delta in self.deltas: utils.update_from_license_info(delta, unique_categories) @@ -249,28 +291,12 @@ def copyright_diff(self): for delta in self.deltas: utils.update_from_copyright_info(delta) - def index_deltas(self, index_key='path', delta_list=[]): - """ - Return a dictionary of a list of Delta objects indexed by the key - passed via the 'index_key' variable. If no 'index_key' variable is - passed, the dict is keyed by the Delta object's 'path' variable. For a - 'removed' Delta object -- identified by its 'score' attribute -- use - the variable from the 'old_file'; for all other Delta objects (e.g., - 'added'), use the 'new_file'. This function does not currently catch - the AttributeError exception. - """ - index = {} - - for delta in delta_list: - key = getattr(delta.new_file if delta.new_file else delta.old_file, index_key) - - if index.get(key) is None: - index[key] = [] - index[key].append(delta) - else: - index[key].append(delta) - - return index + def options_diff(self): + try: + self.new_scan_options = self.codebase1.get_headers()[0].get("options", "") + self.old_scan_options = self.codebase2.get_headers()[0].get("options", "") + except IndexError as exception: + pass class Delta(object): @@ -279,14 +305,18 @@ class Delta(object): object -- and the 'factors' (e.g., 'added', 'modified' etc.) and related 'score' that characterize that comparison. """ + + NEW_CODEBASE_OFFSET = 0 + OLD_CODEBASE_OFFSET = 0 + def __init__(self, score=0, new_file=None, old_file=None): self.new_file = new_file if new_file else None self.old_file = old_file if old_file else None self.factors = [] self.score = score - self.status = '' + self.status = "" - def update(self, score=0, factor=''): + def update(self, score=0, factor=""): """ Add the score to the Delta object's 'score' attribute and add a string, summarizing the factor associated with the score, to the object's @@ -310,9 +340,12 @@ def is_unmodified(self): other than 'unmodified' and return True if all but 'unmodified' are ruled out. """ - if (self.new_file and self.old_file and - self.new_file.sha1 == self.old_file.sha1 and - self.new_file.path == self.old_file.path): + if ( + self.new_file + and self.old_file + and self.new_file.sha1 == self.old_file.sha1 + and self.new_file.path == self.old_file.path + ): return True def is_added(self): @@ -322,11 +355,86 @@ def is_added(self): if self.new_file and not self.old_file: return True - def to_dict(self): + def copyrights_to_dict(self, file): + """ + Given a Copyright object, return an OrderedDict with the full + set of fields from the ScanCode 'copyrights' value. + """ + copyrights = [] + try: + copyrights = file.copyrights + except AttributeError: + return [] + + all_copyrights = [] + for copyright in copyrights: + all_copyrights.append( + OrderedDict( + [ + ("statements", copyright.get("statements", None)), + ("holders", copyright.get("holders", None)), + ] + ) + ) + + return all_copyrights + + def licenses_to_dict(self, file): + """ + Given a License object, return an OrderedDict with the full + set of fields from the ScanCode 'license' value. + """ + licenses = [] + try: + for license in file.licenses: + licenses.append( + OrderedDict( + [ + ("key", license.get("key", None)), + ("score", license.get("score", None)), + ("short_name", license.get("short_name", None)), + ("category", license.get("category", None)), + ("owner", license.get("owner", None)), + ] + ) + ) + return licenses + except: + return [] + + def file_to_dict(self, deltacode, file, new_file=True): + + path_offset = ( + Delta.NEW_CODEBASE_OFFSET if new_file else Delta.OLD_CODEBASE_OFFSET + ) + if file: + return OrderedDict( + [ + ("path", "/".join(paths.split(file.path)[path_offset:])), + ("type", file.type), + ("name", file.name), + ("size", file.size), + ("sha1", file.sha1), + ( + "fingerprint", + file.fingerprint if hasattr(file, "fingerprint") else "", + ), + ("original_path", file.path), + ("licenses", self.licenses_to_dict(file)), + ("copyrights", self.copyrights_to_dict(file)), + ] + ) + + def to_dict(self, deltacode): """ Return an OrderedDict comprising the 'factors', 'score' and new and old 'path' attributes of the object. """ + if ( + not deltacode.options.get("--all-delta-types", "") == True + and self.status == "unmodified" + ): + return if self.new_file: new_file = self.new_file.to_dict() else: @@ -337,19 +445,23 @@ def to_dict(self): else: old_file = None - return OrderedDict([ - ('status', self.status), - ('factors', self.factors), - ('score', self.score), - ('new', new_file), - ('old', old_file), - ]) + return OrderedDict( + [ + ("status", self.status), + ("factors", self.factors), + ("score", self.score), + ("new", self.file_to_dict(deltacode, self.new_file, new_file=True)), + ("old", self.file_to_dict(deltacode, self.old_file, new_file=False)), + ] + ) + class Stat(object): """ Contains all the stats for the file changes in the new directory with respect to the old directory. """ + def __init__(self, new_files_count, old_files_count): self.new_files_count = new_files_count self.old_files_count = old_files_count @@ -369,23 +481,34 @@ def calculate_stats(self): Calculates the percentage change of new directory with respect to the old directory. """ - self.percent_added = utils.calculate_percent(self.num_added, self.old_files_count) - self.percent_removed = utils.calculate_percent(self.num_removed, self.old_files_count) - self.percent_moved = utils.calculate_percent(self.num_moved, self.old_files_count) - self.percent_modified = utils.calculate_percent(self.num_modified, self.old_files_count) - self.percent_unmodified = utils.calculate_percent(self.num_unmodified, self.old_files_count) + self.percent_added = utils.calculate_percent( + self.num_added, self.old_files_count + ) + self.percent_removed = utils.calculate_percent( + self.num_removed, self.old_files_count + ) + self.percent_moved = utils.calculate_percent( + self.num_moved, self.old_files_count + ) + self.percent_modified = utils.calculate_percent( + self.num_modified, self.old_files_count + ) + self.percent_unmodified = utils.calculate_percent( + self.num_unmodified, self.old_files_count + ) def to_dict(self): """ Return an OrderedDict comprising all the percent attributes of the object. """ - return OrderedDict([ - ('old_files_count', self.old_files_count), - ('new_files_count', self.new_files_count), - ('percent_added', self.percent_added), - ('percent_removed', self.percent_removed), - ('percent_moved', self.percent_moved), - ('percent_modified', self.percent_modified), - ('percent_unmodified', self.percent_unmodified), - ]) - + return OrderedDict( + [ + ("old_files_count", self.old_files_count), + ("new_files_count", self.new_files_count), + ("percent_added", self.percent_added), + ("percent_removed", self.percent_removed), + ("percent_moved", self.percent_moved), + ("percent_modified", self.percent_modified), + ("percent_unmodified", self.percent_unmodified), + ] + ) diff --git a/src/deltacode/cli.py b/src/deltacode/cli.py index 5875621a..eed77e7b 100644 --- a/src/deltacode/cli.py +++ b/src/deltacode/cli.py @@ -44,6 +44,8 @@ def write_json(deltacode, outfile, all_delta_types=False): """ results = OrderedDict([ ('deltacode_notice', get_notice()), + # ('new_scan_options', deltacode.new_scan_options), + # ('old_scan_options', deltacode.old_scan_options), ('deltacode_options', deltacode.options), ('deltacode_version', __version__), ('deltacode_errors', collect_errors(deltacode)), @@ -88,6 +90,5 @@ def cli(new, old, json_file, all_delta_types): # do the delta deltacode = DeltaCode(new, old, options) - # generate JSON output write_json(deltacode, json_file, all_delta_types) diff --git a/src/deltacode/test_utils.py b/src/deltacode/test_utils.py index 826ed20b..5d8917bd 100644 --- a/src/deltacode/test_utils.py +++ b/src/deltacode/test_utils.py @@ -34,7 +34,8 @@ import json from commoncode.system import on_windows - +from commoncode import paths +from commoncode.resource import VirtualCodebase def run_scan_click(options, monkeypatch=None, test_mode=True, expected_rc=0, env=None): """ @@ -149,6 +150,10 @@ def streamline_errors(errors): errors[i] = cleaned_error +def get_aligned_path(delta, path, new_file): + OFFSET = delta.NEW_CODEBASE_OFFSET if new_file else delta.OLD_CODEBASE_OFFSET + return "/".join(paths.split(path)[OFFSET:]) + def streamline_headers(headers): """ Modify the `headers` list of mappings in place to make it easier to test. diff --git a/src/deltacode/utils.py b/src/deltacode/utils.py index de82f07e..2a9d7c63 100644 --- a/src/deltacode/utils.py +++ b/src/deltacode/utils.py @@ -33,6 +33,8 @@ import os from commoncode import paths +from collections import OrderedDict + def update_from_license_info(delta, unique_categories): """ @@ -53,19 +55,20 @@ def update_added_from_license_info(delta, unique_categories): one or more categories to its 'factors' attribute if there has been a license change. """ - new_licenses = delta.new_file.licenses or [] - new_categories = set(license.category for license in new_licenses) - - if delta.new_file.has_licenses(): - delta.update(20, 'license info added') + new_licenses = ( + delta.new_file.licenses if hasattr(delta.new_file, "licenses") else [] + ) + new_categories = set(license["category"] for license in new_licenses) + if hasattr(delta.new_file, "licenses"): + delta.update(20, "license info added") for category in new_categories: # no license ==> 'Copyleft Limited'or higher if category in unique_categories: - delta.update(20, category.lower() + ' added') + delta.update(20, category.lower() + " added") # no license ==> 'Permissive' or 'Public Domain' else: - delta.update(0, category.lower() + ' added') + delta.update(0, category.lower() + " added") return @@ -75,44 +78,50 @@ def update_modified_from_license_info(delta, unique_categories): one or more categories to its 'factors' attribute if there has been a license change. """ - if not delta.new_file.has_licenses() and delta.old_file.has_licenses(): - delta.update(15, 'license info removed') - return - new_licenses = delta.new_file.licenses or [] - old_licenses = delta.old_file.licenses or [] + new_licenses = ( + delta.new_file.licenses if hasattr(delta.new_file, "licenses") else [] + ) + old_licenses = ( + delta.old_file.licenses if hasattr(delta.old_file, "licenses") else [] + ) + + if not new_licenses and old_licenses: + delta.update(15, "license info removed") + return - new_categories = set(license.category for license in new_licenses) - old_categories = set(license.category for license in old_licenses) + new_categories = set(license.get("category", "") for license in new_licenses) + old_categories = set(license.get("category", "") for license in old_licenses) - if delta.new_file.has_licenses() and not delta.old_file.has_licenses(): - delta.update(20, 'license info added') + if new_licenses and not old_licenses: + delta.update(20, "license info added") for category in new_categories: # no license ==> 'Copyleft Limited'or higher if category in unique_categories: - delta.update(20, category.lower() + ' added') + delta.update(20, category.lower() + " added") # no license ==> 'Permissive' or 'Public Domain' else: - delta.update(0, category.lower() + ' added') + delta.update(0, category.lower() + " added") return - new_keys = set(license.key for license in new_licenses) - old_keys = set(license.key for license in old_licenses) + new_keys = set(license.get("key", "") for license in new_licenses) + old_keys = set(license.get("key", "") for license in old_licenses) if new_keys != old_keys: - delta.update(10, 'license change') + + delta.update(10, "license change") for category in new_categories - old_categories: unique_categories_in_old_file = len(old_categories & unique_categories) # 'Permissive' or 'Public Domain' ==> 'Copyleft Limited' or higher if unique_categories_in_old_file == 0 and category in unique_categories: - delta.update(20, category.lower() + ' added') + delta.update(20, category.lower() + " added") # at least 1 category in the old file was 'Copyleft Limited' or higher ==> 'Copyleft Limited' or higher elif unique_categories_in_old_file != 0 and category in unique_categories: - delta.update(10, category.lower() + ' added') + delta.update(10, category.lower() + " added") # 'Permissive' or 'Public Domain' ==> 'Permissive' or 'Public Domain' if not in old_categories elif category not in unique_categories: - delta.update(0, category.lower() + ' added') + delta.update(0, category.lower() + " added") def update_from_copyright_info(delta): @@ -134,8 +143,9 @@ def update_added_from_copyright_info(delta): one or more categories to its 'factors' attribute if there has been a copyright change. """ - if delta.new_file.has_copyrights(): - delta.update(10, 'copyright info added') + + if hasattr(delta.new_file, "copyrights"): + delta.update(10, "copyright info added") return @@ -145,27 +155,39 @@ def update_modified_from_copyright_info(delta): one or more categories to its 'factors' attribute if there has been a copyright change. """ - new_copyrights = delta.new_file.copyrights or [] - old_copyrights = delta.old_file.copyrights or [] - if delta.new_file.has_copyrights() and not delta.old_file.has_copyrights(): - delta.update(10, 'copyright info added') + new_copyrights = ( + delta.new_file.copyrights if hasattr(delta.new_file, "copyrights") else [] + ) + old_copyrights = ( + delta.old_file.copyrights if hasattr(delta.old_file, "copyrights") else [] + ) + + if new_copyrights and not old_copyrights: + delta.update(10, "copyright info added") return - if not delta.new_file.has_copyrights() and delta.old_file.has_copyrights(): - delta.update(10, 'copyright info removed') + if not new_copyrights and old_copyrights: + delta.update(10, "copyright info removed") return - new_holders = set(holder for copyright in new_copyrights for holder in copyright.holders) - old_holders = set(holder for copyright in old_copyrights for holder in copyright.holders) - + new_holders = set( + holder + for copyright in new_copyrights + for holder in copyright.get("holders", []) + ) + old_holders = set( + holder + for copyright in old_copyrights + for holder in copyright.get("holders", []) + ) if new_holders != old_holders: - delta.update(5, 'copyright change') + delta.update(5, "copyright change") def collect_errors(deltacode): errors = [] - errors.extend(deltacode.new.errors) - errors.extend(deltacode.old.errors) + errors.extend(deltacode.new_files_errors) + errors.extend(deltacode.old_files_errors) errors.extend(deltacode.errors) return errors @@ -179,39 +201,57 @@ def deltas(deltacode, all_delta_types=False): """ for delta in deltacode.deltas: if all_delta_types is True: - yield delta.to_dict() - elif not delta.is_unmodified(): - yield delta.to_dict() + yield delta.to_dict(deltacode) + elif not delta.status == "unmodified": + yield delta.to_dict(deltacode) + def calculate_percent(value, total): """ Return the rounded value percentage of total. """ - ratio = (value / total) * 100 - return round(ratio, 2) + try: + ratio = (value / total) * 100 + return round(ratio, 2) + except ZeroDivisionError: + return 0 + class AlignmentException(Exception): """ Named exception for alignment errors. """ + pass -def align_trees(a_files, b_files): + +class FileError(Exception): """ - Given two sequences of File objects 'a' and 'b', return a tuple of - two integers that represent the number path segments to remove - respectively from a File path in 'a' or a File path in 'b' to obtain the - equal paths for two files that are the same in 'a' and 'b'. + Named Exception for handling errors which could be raised due to + unsupported errors in the json file + """ + def __init__(self, *args): + if args: + self.message = args[0] + else: + self.message = None + + def __str__(self): + return self.message + + +def align_trees(codebase1, codebase2): + """ + Aligns the path of the two codebases """ - # we need to find one uniquly named file that exists in 'a' and 'b'. a_names = defaultdict(list) - for a_file in a_files: - a_names[a_file.name].append(a_file) + for resource in codebase1.walk(): + a_names[resource.name].append(resource) a_uniques = {k: v[0] for k, v in a_names.items() if len(v) == 1} b_names = defaultdict(list) - for b_file in b_files: - b_names[b_file.name].append(b_file) + for resource in codebase2.walk(): + b_names[resource.name].append(resource) b_uniques = {k: v[0] for k, v in b_names.items() if len(v) == 1} candidate_found = False @@ -228,59 +268,31 @@ def align_trees(a_files, b_files): if a_unique.path == b_unique.path: return 0, 0 - common_suffix, common_segments = paths.common_path_suffix(a_unique.path, b_unique.path) + common_suffix, common_segments = paths.common_path_suffix( + a_unique.path, b_unique.path + ) a_segments = len(paths.split(a_unique.path)) b_segments = len(paths.split(b_unique.path)) return a_segments - common_segments, b_segments - common_segments -def fix_trees(a_files, b_files): - """ - Given two sequences of File objects 'a' and 'b', use the tuple of two - integers returned by align_trees() to remove the number of path segments - required to create equal paths for two files that are the same in 'a' and - 'b'. - """ - a_offset, b_offset = align_trees(a_files, b_files) - for a_file in a_files: - a_file.original_path = a_file.path - a_file.path = '/'.join(paths.split(a_file.path)[a_offset:]) - - for b_file in b_files: - b_file.original_path = b_file.path - b_file.path = '/'.join(paths.split(b_file.path)[b_offset:]) - - -def check_moved(added_sha1, added_deltas, removed_sha1, removed_deltas): - """ - Return True if there is only one pair of matching 'added' and 'removed' - Delta objects and their respective File objects have the same 'name' attribute. - """ - if added_sha1 != removed_sha1: - return False - if len(added_deltas) != 1 or len(removed_deltas) != 1: - return False - if added_deltas[0].new_file.name == removed_deltas[0].old_file.name: - return True - - def get_notice(): """ Retrieve the notice text from the NOTICE file for display in the JSON output. """ - notice_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'NOTICE') + notice_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "NOTICE") notice_text = open(notice_path).read() - delimiter = '\n\n\n' + delimiter = "\n\n\n" [notice_text, extra_notice_text] = notice_text.split(delimiter, 1) extra_notice_text = delimiter + extra_notice_text - delimiter = '\n\n ' + delimiter = "\n\n " [notice_text, acknowledgment_text] = notice_text.split(delimiter, 1) acknowledgment_text = delimiter + acknowledgment_text - notice = acknowledgment_text.strip().replace(' ', '') + notice = acknowledgment_text.strip().replace(" ", "") return notice @@ -296,6 +308,7 @@ def hamming_distance(fingerprint1, fingerprint2): return result + def bitarray_from_hex(fingerprint_hex): """ Return bitarray from a hex string. @@ -305,6 +318,7 @@ def bitarray_from_hex(fingerprint_hex): return result + def bitarray_from_bytes(b): """ Return bitarray from a byte string, interpreted as machine values. @@ -312,4 +326,4 @@ def bitarray_from_bytes(b): a = bitarray() a.frombytes(b) - return a \ No newline at end of file + return a diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/cli/scan_1_file_moved_new.json b/tests/data/cli/scan_1_file_moved_new.json index 87303185..f54ad9db 100644 --- a/tests/data/cli/scan_1_file_moved_new.json +++ b/tests/data/cli/scan_1_file_moved_new.json @@ -71,7 +71,6 @@ "size": 200, "sha1": "84b647771481d39dd3a53f6dc210c26abac37748", "md5": "3cb56efa7140478458dbaa2b30239845", - "fingerprint": "83ee5b9e652faad754b8e20bead792f8", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -131,7 +130,6 @@ "size": 200, "sha1": "310797523e47db8481aeb06f1634317285115091", "md5": "19efdad483f68bc9997a5c1f7ba41b26", - "fingerprint": "e30cf09443e7878dfcd3288886e97533", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -191,7 +189,6 @@ "size": 200, "sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9", "md5": "795ff2cae8ece792a9bfebe18ad3c8e6", - "fingerprint": "e30cf09443e7878dfed3288886e97533", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -251,7 +248,6 @@ "size": 200, "sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b", "md5": "fc403815d6605df989414ff40a64ea17", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -311,7 +307,6 @@ "size": 200, "sha1": "70f6ce80985578b5104db0abc578cf5a05e78f4b", "md5": "af9e9420c6c5b2b0ca74e96bf7c1a2f4", - "fingerprint": "e30cf09443e7878dfed1088886e97542", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -371,7 +366,6 @@ "size": 200, "sha1": "3340d86b1da9323067db8022f86dc97cfccee1d0", "md5": "74ce2b26cebb32670634270dde1fdf33", - "fingerprint": "e30cf09443e7878dfed1088886e97232", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -431,7 +425,6 @@ "size": 200, "sha1": "e49d4463662414bee5ad2d2e5c1fbd704f33b84e", "md5": "8d458f54d32959b03dff37ef485b29c6", - "fingerprint": "e30cf83443e7878dfed1088886e97232", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -491,7 +484,6 @@ "size": 200, "sha1": "98c9e6bed78b1513c28e666016cb35a50708c36e", "md5": "c3559aef44883a46e007ab01213091cb", - "fingerprint": "e30cf83443e7878dfed1032386e97232", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", diff --git a/tests/data/cli/scan_1_file_moved_old.json b/tests/data/cli/scan_1_file_moved_old.json index c8a09b13..0d9a81ed 100644 --- a/tests/data/cli/scan_1_file_moved_old.json +++ b/tests/data/cli/scan_1_file_moved_old.json @@ -71,7 +71,6 @@ "size": 200, "sha1": "84b647771481d39dd3a53f6dc210c26abac37748", "md5": "3cb56efa7140478458dbaa2b30239845", - "fingerprint": "83ee5b9e652faad754b8e20bead792f8", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -131,7 +130,6 @@ "size": 200, "sha1": "310797523e47db8481aeb06f1634317285115091", "md5": "19efdad483f68bc9997a5c1f7ba41b26", - "fingerprint": "e30cf09443e7878dfcd3288886e97533", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -191,7 +189,6 @@ "size": 200, "sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9", "md5": "795ff2cae8ece792a9bfebe18ad3c8e6", - "fingerprint": "e30cf09443e7878dfed3288886e97533", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -251,7 +248,6 @@ "size": 200, "sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b", "md5": "fc403815d6605df989414ff40a64ea17", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -311,7 +307,6 @@ "size": 200, "sha1": "70f6ce80985578b5104db0abc578cf5a05e78f4b", "md5": "af9e9420c6c5b2b0ca74e96bf7c1a2f4", - "fingerprint": "e30cf09443e7878dfed1088886e97542", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -371,7 +366,6 @@ "size": 200, "sha1": "3340d86b1da9323067db8022f86dc97cfccee1d0", "md5": "74ce2b26cebb32670634270dde1fdf33", - "fingerprint": "e30cf09443e7878dfed1088886e97232", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -431,7 +425,6 @@ "size": 200, "sha1": "e49d4463662414bee5ad2d2e5c1fbd704f33b84e", "md5": "8d458f54d32959b03dff37ef485b29c6", - "fingerprint": "e30cf83443e7878dfed1088886e97232", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", @@ -491,7 +484,6 @@ "size": 200, "sha1": "98c9e6bed78b1513c28e666016cb35a50708c36e", "md5": "c3559aef44883a46e007ab01213091cb", - "fingerprint": "e30cf83443e7878dfed1032386e97232", "files_count": null, "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", diff --git a/tests/data/deltacode/Delta_to_dict_removed_new.json b/tests/data/deltacode/Delta_to_dict_removed_new.json new file mode 100644 index 00000000..4759e766 --- /dev/null +++ b/tests/data/deltacode/Delta_to_dict_removed_new.json @@ -0,0 +1,57 @@ +{ + "headers": [ + { + "tool_name": "scancode-toolkit", + "tool_version": "21.3.31", + "options": { + "input": [ + "music/" + ], + "--copyright": true, + "--json-pp": "../music_new.json", + "--license": true, + "--package": true + }, + "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.", + "start_timestamp": "2021-05-25T171204.704038", + "end_timestamp": "2021-05-25T171205.962836", + "duration": 1.2588143348693848, + "message": null, + "errors": [], + "extra_data": { + "files_count": 0 + } + } + ], + "files": [ + { + "path": "music", + "type": "directory", + "name": "music", + "base_name": "music", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "sha256": 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, + "copyrights": [], + "holders": [], + "authors": [], + "packages": [], + "files_count": 1, + "dirs_count": 0, + "size_count": 7783, + "scan_errors": [] + } + ] + } \ No newline at end of file diff --git a/tests/data/deltacode/Delta_to_dict_removed_old.json b/tests/data/deltacode/Delta_to_dict_removed_old.json new file mode 100644 index 00000000..ab97d6be --- /dev/null +++ b/tests/data/deltacode/Delta_to_dict_removed_old.json @@ -0,0 +1,86 @@ +{ + "headers": [ + { + "tool_name": "scancode-toolkit", + "tool_version": "21.3.31", + "options": { + "input": [ + "music/" + ], + "--copyright": true, + "--info": true, + "--json-pp": "../music_old.json", + "--package": true + }, + "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.", + "start_timestamp": "2021-05-25T172126.973000", + "end_timestamp": "2021-05-25T172128.234812", + "duration": 1.261824369430542, + "message": null, + "errors": [], + "extra_data": { + "files_count": 1 + } + } + ], + "files": [ + { + "path": "music", + "type": "directory", + "name": "music", + "base_name": "music", + "extension": "", + "size": 0, + "date": null, + "sha1": null, + "md5": null, + "sha256": 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, + "copyrights": [], + "holders": [], + "authors": [], + "packages": [], + "files_count": 1, + "dirs_count": 0, + "size_count": 7783, + "scan_errors": [] + }, + { + "path": "music/CONTRIBUTING.rst", + "type": "file", + "name": "CONTRIBUTING.rst", + "base_name": "CONTRIBUTING", + "extension": ".rst", + "size": 7783, + "date": "2021-05-19", + "sha1": "476f2310923943accd0ec4361ab36053d8ce46e0", + "md5": "b8b2bdb795dbf6256699b44a72581651", + "sha256": "fa16177c57bd50bd98a450fed9c836b5df21e41befae00a4c56cf28a397b585a", + "mime_type": "text/plain", + "file_type": "UTF-8 Unicode text", + "programming_language": null, + "is_binary": false, + "is_text": true, + "is_archive": false, + "is_media": false, + "is_source": false, + "is_script": false, + "copyrights": [], + "holders": [], + "authors": [], + "packages": [], + "files_count": 0, + "dirs_count": 0, + "size_count": 0, + "scan_errors": [] + } + ] + } \ No newline at end of file diff --git a/tests/data/deltacode/coala-expected-result.json b/tests/data/deltacode/coala-expected-result.json index e8c69d2f..7b34045e 100644 --- a/tests/data/deltacode/coala-expected-result.json +++ b/tests/data/deltacode/coala-expected-result.json @@ -1,5 +1,11 @@ { "deltacode_notice": "Generated with DeltaCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nDeltaCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nDeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/deltacode/ for support and download.", + "deltacode_options": { + "--new": "tests/data/deltacode/coala-0.10.0-new.json", + "--old": "tests/data/deltacode/coala-0.7.0-old.json", + "--all-delta-types": true + }, + "deltacode_version": "1.0.1.dev112+gde3c583.d20210613", "deltacode_errors": [], "deltas_count": 141, "delta_stats": { @@ -2988,6 +2994,33 @@ "copyrights": [] } }, + { + "status": "moved", + "factors": [], + "score": 0, + "new": { + "path": "coalib/testing/__init__.py", + "type": "file", + "name": "__init__.py", + "size": 0, + "sha1": null, + "fingerprint": null, + "original_path": "coalib/testing/__init__.py", + "licenses": [], + "copyrights": [] + }, + "old": { + "path": "coalib/bears/requirements/__init__.py", + "type": "file", + "name": "__init__.py", + "size": 0, + "sha1": null, + "fingerprint": null, + "original_path": "coalib/bears/requirements/__init__.py", + "licenses": [], + "copyrights": [] + } + }, { "status": "removed", "factors": [], @@ -3395,33 +3428,6 @@ "licenses": [], "copyrights": [] } - }, - { - "status": "moved", - "factors": [], - "score": 0, - "new": { - "path": "coalib/testing/__init__.py", - "type": "file", - "name": "__init__.py", - "size": 0, - "sha1": null, - "fingerprint": null, - "original_path": "coalib/testing/__init__.py", - "licenses": [], - "copyrights": [] - }, - "old": { - "path": "coalib/bears/requirements/__init__.py", - "type": "file", - "name": "__init__.py", - "size": 0, - "sha1": null, - "fingerprint": null, - "original_path": "coalib/bears/requirements/__init__.py", - "licenses": [], - "copyrights": [] - } } ] } diff --git a/tests/data/deltacode/delta_to_dict_added_new.json b/tests/data/deltacode/delta_to_dict_added_new.json new file mode 100644 index 00000000..c5811be6 --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_added_new.json @@ -0,0 +1,29 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 2, + "files": [ + { + "path": "path", + "type": "directory", + "name": "path", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09456e7878dfed3288886e97542", + "original_path": "" + }, + { + "path": "path/added.txt", + "type": "file", + "name": "added.txt", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09443e7878dfed3288886e12345", + "original_path": "" + } + ] +} \ No newline at end of file diff --git a/tests/data/deltacode/delta_to_dict_added_old.json b/tests/data/deltacode/delta_to_dict_added_old.json new file mode 100644 index 00000000..5b0d27e3 --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_added_old.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path", + "type": "directory", + "name": "path", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09456e7878dfed3288886e97542", + "original_path": "" + } + ] +} \ No newline at end of file diff --git a/tests/data/deltacode/delta_to_dict_modified_new.json b/tests/data/deltacode/delta_to_dict_modified_new.json new file mode 100644 index 00000000..f975fd5e --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_modified_new.json @@ -0,0 +1,19 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path/modified.txt", + "type": "file", + "name": "modified.txt", + "size": 20, + "sha1": "a", + "original_path": "" + } + ] +} diff --git a/tests/data/deltacode/delta_to_dict_modified_old.json b/tests/data/deltacode/delta_to_dict_modified_old.json new file mode 100644 index 00000000..d5972ad4 --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_modified_old.json @@ -0,0 +1,19 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path/modified.txt", + "type": "file", + "name": "modified.txt", + "size": 21, + "sha1": "b", + "original_path": "" + } + ] +} diff --git a/tests/data/deltacode/delta_to_dict_moved_new.json b/tests/data/deltacode/delta_to_dict_moved_new.json new file mode 100644 index 00000000..d9c523af --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_moved_new.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path_new/moved.txt", + "type": "file", + "name": "moved.txt", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09443e7878dfed3288886e97542", + "original_path": "" + } + ] +} diff --git a/tests/data/deltacode/delta_to_dict_moved_old.json b/tests/data/deltacode/delta_to_dict_moved_old.json new file mode 100644 index 00000000..92129ba1 --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_moved_old.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path_old/moved.txt", + "type": "file", + "name": "moved.txt", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09443e7878dfed3288886e97542", + "original_path": "" + } + ] +} diff --git a/tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_new.json b/tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_new.json new file mode 100644 index 00000000..f1d403bc --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_new.json @@ -0,0 +1,74 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path/modified.txt", + "type": "file", + "name": "modified.txt", + "size": 21, + "sha1": "a_modified", + "fingerprint": "e30cf09443e7878dfed3288886e97542", + "original_path": "", + "licenses": [], + "copyrights": [ + { + "statements": [ + "Copyright (c) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler", + "Copyright (c) 1998 by Andreas R. Kleinert", + "Copyright (c) 2002-2004 Dmitriy Anisimkov", + "Copyright (c) 1998, 2007 Brian Raiter", + "Copyright (c) 1997,99 Borland Corp.", + "(c) Copyright Henrik Ravn 2004", + "Copyright (c) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant.", + "Copyright (c) 2003 Chris Anderson", + "Copyright (c) 1997 Christian Michelsen Research as Advanced Computing", + "Copyright (c) 2009-2010 Mathias Svensson http://result42.com", + "Copyright (c) 1990-2000 Info-ZIP.", + "Copyright (c) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler", + "Copyright (c) 1998 by Andreas R. Kleinert", + "Copyright (c) 2002-2004 Dmitriy Anisimkov", + "Copyright (c) 1998, 2007 Brian Raiter", + "Copyright (c) 1997,99 Borland Corp.", + "(c) Copyright Henrik Ravn 2004", + "Copyright (c) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant.", + "Copyright (c) 2003 Chris Anderson", + "Copyright (c) 1997 Christian Michelsen Research as Advanced Computing", + "Copyright (c) 2009-2010 Mathias Svensson http://result42.com", + "Copyright (c) 1990-2000 Info-ZIP." + ], + "holders": [ + "Jean-loup Gailly, Mark Adler", + "Andreas R. Kleinert", + "Dmitriy Anisimkov", + "Brian Raiter", + "Borland Corp.", + "Henrik Ravn", + "Jean-loup Gailly, Brian Raiter, Gilles Vollant", + "Chris Anderson", + "Christian Michelsen Research as Advanced Computing", + "Mathias Svensson", + "Info-ZIP", + "Jean-loup Gailly, Mark Adler", + "Andreas R. Kleinert", + "Dmitriy Anisimkov", + "Brian Raiter", + "Borland Corp.", + "Henrik Ravn", + "Jean-loup Gailly, Brian Raiter, Gilles Vollant", + "Chris Anderson", + "Christian Michelsen Research as Advanced Computing", + "Mathias Svensson", + "Info-ZIP" + ], + "authors": [] + } + ] + } + ] +} diff --git a/tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_old.json b/tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_old.json new file mode 100644 index 00000000..4bdeb0da --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_multiple_copyright_statements_and_holders_old.json @@ -0,0 +1,32 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path/modified.txt", + "type": "file", + "name": "modified.txt", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09443e7878dfed3289786e97542", + "original_path": "", + "licenses": [], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2018 Jane Doe" + ], + "holders": [ + "Jane Doe" + ], + "authors": [] + } + ] + } + ] +} diff --git a/tests/data/deltacode/delta_to_dict_unmodified_new.json b/tests/data/deltacode/delta_to_dict_unmodified_new.json new file mode 100644 index 00000000..2e995d4b --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_unmodified_new.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path/unmodified.txt", + "type": "file", + "name": "unmodified.txt", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09443e7878dfed3288886e97542", + "original_path": "" + } + ] +} diff --git a/tests/data/deltacode/delta_to_dict_unmodified_old.json b/tests/data/deltacode/delta_to_dict_unmodified_old.json new file mode 100644 index 00000000..2e995d4b --- /dev/null +++ b/tests/data/deltacode/delta_to_dict_unmodified_old.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path": "path/unmodified.txt", + "type": "file", + "name": "unmodified.txt", + "size": 20, + "sha1": "a", + "fingerprint": "e30cf09443e7878dfed3288886e97542", + "original_path": "" + } + ] +} diff --git a/tests/data/deltacode/no_lic_to_all_notable_lic_new.json b/tests/data/deltacode/no_lic_to_all_notable_lic_new.json index f642fee4..59663036 100644 --- a/tests/data/deltacode/no_lic_to_all_notable_lic_new.json +++ b/tests/data/deltacode/no_lic_to_all_notable_lic_new.json @@ -48,7 +48,6 @@ "date": "2018-03-16", "sha1": "535b9966048ad50a9d5eb2f167c0a3013ee5cc6f", "md5": "e5658fe520bbebaf6f3d4be2e2525ab6", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "mime_type": "text/plain", "file_type": "UTF-8 Unicode text, with very long lines, with CRLF line terminators", "programming_language": "Python", @@ -407,7 +406,6 @@ "date": "2017-09-26", "sha1": "310797523e47db8481aeb06f1634317285115091", "md5": "19efdad483f68bc9997a5c1f7ba41b26", - "fingerprint": "e30cf09443e7878dfed3288886d17542", "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", "programming_language": "Python", diff --git a/tests/data/deltacode/no_lic_to_all_notable_lic_old.json b/tests/data/deltacode/no_lic_to_all_notable_lic_old.json index 56a80aec..bd921012 100644 --- a/tests/data/deltacode/no_lic_to_all_notable_lic_old.json +++ b/tests/data/deltacode/no_lic_to_all_notable_lic_old.json @@ -48,7 +48,6 @@ "date": "2018-03-16", "sha1": "0d17f1c2b6b82e8c7eec1fdad94c028b679518ff", "md5": "a2272cfafc4dff14c008db5c5ddde6a9", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", "programming_language": "Python", @@ -76,7 +75,6 @@ "date": "2017-09-26", "sha1": "310797523e47db8481aeb06f1634317285115091", "md5": "19efdad483f68bc9997a5c1f7ba41b26", - "fingerprint": "e30cf09443e7878dfed3288886d17542", "mime_type": "text/plain", "file_type": "ASCII text, with CRLF line terminators", "programming_language": "Python", diff --git a/tests/data/deltacode/score_copyright_and_license_info_added_new.json b/tests/data/deltacode/score_copyright_and_license_info_added_new.json index a40a71b9..fcc1837c 100644 --- a/tests/data/deltacode/score_copyright_and_license_info_added_new.json +++ b/tests/data/deltacode/score_copyright_and_license_info_added_new.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b_modified", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [ { "key": "gpl-1.0-plus", diff --git a/tests/data/deltacode/score_copyright_and_license_info_added_old.json b/tests/data/deltacode/score_copyright_and_license_info_added_old.json index e87c75ed..8f1827ea 100644 --- a/tests/data/deltacode/score_copyright_and_license_info_added_old.json +++ b/tests/data/deltacode/score_copyright_and_license_info_added_old.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] } diff --git a/tests/data/deltacode/score_copyright_and_license_info_removed_old.json b/tests/data/deltacode/score_copyright_and_license_info_removed_old.json index cc5152e0..acf940b0 100644 --- a/tests/data/deltacode/score_copyright_and_license_info_removed_old.json +++ b/tests/data/deltacode/score_copyright_and_license_info_removed_old.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b", - "fingerprint": "e30cf97343e7878dfed3288886e97542", "licenses": [ { "key": "gpl-1.0-plus", diff --git a/tests/data/deltacode/score_copyright_change_no_license_change_new.json b/tests/data/deltacode/score_copyright_change_no_license_change_new.json index d4d1999b..92be662e 100644 --- a/tests/data/deltacode/score_copyright_change_no_license_change_new.json +++ b/tests/data/deltacode/score_copyright_change_no_license_change_new.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b_modified", - "fingerprint": "e30fc89443e7878dfed3288886e97542", "licenses": [ { "key": "gpl-3.0-plus", diff --git a/tests/data/deltacode/score_copyright_change_no_license_change_old.json b/tests/data/deltacode/score_copyright_change_no_license_change_old.json index 9c3694df..22828c46 100644 --- a/tests/data/deltacode/score_copyright_change_no_license_change_old.json +++ b/tests/data/deltacode/score_copyright_change_no_license_change_old.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b", - "fingerprint": "e30fc89443e7878dfed3288886e97542", "licenses": [ { "key": "gpl-3.0-plus", diff --git a/tests/data/deltacode/score_copyright_info_added_license_info_removed_new.json b/tests/data/deltacode/score_copyright_info_added_license_info_removed_new.json index 74e12916..408882d0 100644 --- a/tests/data/deltacode/score_copyright_info_added_license_info_removed_new.json +++ b/tests/data/deltacode/score_copyright_info_added_license_info_removed_new.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30fc89443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b_modified", - "fingerprint": "e30fc89443e7878ddfe3288886e97542", "licenses": [], "copyrights": [ { diff --git a/tests/data/deltacode/score_copyright_info_added_license_info_removed_old.json b/tests/data/deltacode/score_copyright_info_added_license_info_removed_old.json index add1b190..75bab5c8 100644 --- a/tests/data/deltacode/score_copyright_info_added_license_info_removed_old.json +++ b/tests/data/deltacode/score_copyright_info_added_license_info_removed_old.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30fc89443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b", - "fingerprint": "e30fc89443e7878ddfe3288886e97542", "licenses": [ { "key": "gpl-3.0-plus", diff --git a/tests/data/deltacode/score_copyright_info_removed_new.json b/tests/data/deltacode/score_copyright_info_removed_new.json index 42f0b2cb..0f20da55 100644 --- a/tests/data/deltacode/score_copyright_info_removed_new.json +++ b/tests/data/deltacode/score_copyright_info_removed_new.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b_modified", - "fingerprint": "e30cf09443e7878dfed3288745e97542", "licenses": [], "copyrights": [] } diff --git a/tests/data/deltacode/score_copyright_info_removed_old.json b/tests/data/deltacode/score_copyright_info_removed_old.json index 69917668..8cfbbc2d 100644 --- a/tests/data/deltacode/score_copyright_info_removed_old.json +++ b/tests/data/deltacode/score_copyright_info_removed_old.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b", - "fingerprint": "e30cf09443e7878dfed3288745e97542", "licenses": [], "copyrights": [ { diff --git a/tests/data/deltacode/score_license_change_no_copyright_change_new.json b/tests/data/deltacode/score_license_change_no_copyright_change_new.json index 795851f3..27f95a9d 100644 --- a/tests/data/deltacode/score_license_change_no_copyright_change_new.json +++ b/tests/data/deltacode/score_license_change_no_copyright_change_new.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b_modified", - "fingerprint": "e31ef09443e7878dfed3288886e97542", "licenses": [ { "key": "gpl-1.0-plus", diff --git a/tests/data/deltacode/score_license_change_no_copyright_change_old.json b/tests/data/deltacode/score_license_change_no_copyright_change_old.json index e0a24df1..22828c46 100644 --- a/tests/data/deltacode/score_license_change_no_copyright_change_old.json +++ b/tests/data/deltacode/score_license_change_no_copyright_change_old.json @@ -13,7 +13,6 @@ "name": "default.txt", "size": 100, "sha1": "a", - "fingerprint": "e30cf09443e7878dfed3288886e97542", "licenses": [], "copyrights": [] }, @@ -23,7 +22,6 @@ "name": "path.txt", "size": 300, "sha1": "b", - "fingerprint": "e31ef09443e7878dfed3288886e97542", "licenses": [ { "key": "gpl-3.0-plus", diff --git a/tests/data/utils/update_from_copyright_info_copyright_info_added_new.json b/tests/data/utils/update_from_copyright_info_copyright_info_added_new.json new file mode 100644 index 00000000..3903e303 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_copyright_info_added_new.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_copyright_info_added_old.json b/tests/data/utils/update_from_copyright_info_copyright_info_added_old.json new file mode 100644 index 00000000..c460c74b --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_copyright_info_added_old.json @@ -0,0 +1,18 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_copyright_info_removed_new.json b/tests/data/utils/update_from_copyright_info_copyright_info_removed_new.json new file mode 100644 index 00000000..b92d6770 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_copyright_info_removed_new.json @@ -0,0 +1,18 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_copyright_info_removed_old.json b/tests/data/utils/update_from_copyright_info_copyright_info_removed_old.json new file mode 100644 index 00000000..eb8aabec --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_copyright_info_removed_old.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_file_added_one_copyright_new.json b/tests/data/utils/update_from_copyright_info_file_added_one_copyright_new.json new file mode 100644 index 00000000..d9259c75 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_file_added_one_copyright_new.json @@ -0,0 +1,36 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test", + "name": "test", + "sha1": "b", + "original_path": "", + "copyrights": [ + + ] + }, + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_file_added_one_copyright_old.json b/tests/data/utils/update_from_copyright_info_file_added_one_copyright_old.json new file mode 100644 index 00000000..c417e7e9 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_file_added_one_copyright_old.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 0, + "files": [ + { + "path":"test", + "name": "test", + "sha1": "b", + "original_path": "", + "copyrights": [ + + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_no_copyright_changes_new.json b/tests/data/utils/update_from_copyright_info_no_copyright_changes_new.json new file mode 100644 index 00000000..3903e303 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_no_copyright_changes_new.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_no_copyright_changes_old.json b/tests/data/utils/update_from_copyright_info_no_copyright_changes_old.json new file mode 100644 index 00000000..eb8aabec --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_no_copyright_changes_old.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_no_copyright_key_value_new.json b/tests/data/utils/update_from_copyright_info_no_copyright_key_value_new.json new file mode 100644 index 00000000..5ff4d935 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_no_copyright_key_value_new.json @@ -0,0 +1,17 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "" + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_no_copyright_key_value_old.json b/tests/data/utils/update_from_copyright_info_no_copyright_key_value_old.json new file mode 100644 index 00000000..45e4d858 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_no_copyright_key_value_old.json @@ -0,0 +1,17 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "" + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_non_modified_new.json b/tests/data/utils/update_from_copyright_info_non_modified_new.json new file mode 100644 index 00000000..65e3e23d --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_non_modified_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [], + "holders": [ + "Edouard-Leon Scott de Martinville." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_non_modified_old.json b/tests/data/utils/update_from_copyright_info_non_modified_old.json new file mode 100644 index 00000000..65e3e23d --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_non_modified_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [], + "holders": [ + "Edouard-Leon Scott de Martinville." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_one_copyright_added_new.json b/tests/data/utils/update_from_copyright_info_one_copyright_added_new.json new file mode 100644 index 00000000..edb4c9b5 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_one_copyright_added_new.json @@ -0,0 +1,35 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + }, + { + "statements": [ + "Copyright (c) 2015 Edouard-Leon Scott de Martinville." + ], + "holders": [ + "Edouard-Leon Scott de Martinville." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_one_copyright_added_old.json b/tests/data/utils/update_from_copyright_info_one_copyright_added_old.json new file mode 100644 index 00000000..eb8aabec --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_one_copyright_added_old.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_one_copyright_removed_new.json b/tests/data/utils/update_from_copyright_info_one_copyright_removed_new.json new file mode 100644 index 00000000..3903e303 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_one_copyright_removed_new.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_one_copyright_removed_old.json b/tests/data/utils/update_from_copyright_info_one_copyright_removed_old.json new file mode 100644 index 00000000..172ff832 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_one_copyright_removed_old.json @@ -0,0 +1,35 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + }, + { + "statements": [ + "Copyright (c) 2015 Edouard-Leon Scott de Martinville." + ], + "holders": [ + "Edouard-Leon Scott de Martinville." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_new.json b/tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_new.json new file mode 100644 index 00000000..65e3e23d --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [], + "holders": [ + "Edouard-Leon Scott de Martinville." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_old.json b/tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_old.json new file mode 100644 index 00000000..1a3bc5a3 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_single_copyright_change_holders_only_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [ + { + "statements": [], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_single_copyright_change_new.json b/tests/data/utils/update_from_copyright_info_single_copyright_change_new.json new file mode 100644 index 00000000..33e7df92 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_single_copyright_change_new.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2015 Edouard-Leon Scott de Martinville." + ], + "holders": [ + "Edouard-Leon Scott de Martinville." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_single_copyright_change_old.json b/tests/data/utils/update_from_copyright_info_single_copyright_change_old.json new file mode 100644 index 00000000..eb8aabec --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_single_copyright_change_old.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_new.json b/tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_new.json new file mode 100644 index 00000000..b8ff5ad2 --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2015 Edouard-Leon Scott de Martinville." + ], + "holders": [] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_old.json b/tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_old.json new file mode 100644 index 00000000..a141b9ef --- /dev/null +++ b/tests/data/utils/update_from_copyright_info_single_copyright_change_statements_only_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_new.json b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_new.json new file mode 100644 index 00000000..82777d0e --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_new.json @@ -0,0 +1,35 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_old.json b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_old.json new file mode 100644 index 00000000..db767e4b --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_added_old.json @@ -0,0 +1,19 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [], + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_new.json b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_new.json new file mode 100644 index 00000000..6e36d9dd --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_new.json @@ -0,0 +1,19 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [], + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_old.json b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_old.json new file mode 100644 index 00000000..b9afdbbb --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_and_license_info_removed_old.json @@ -0,0 +1,35 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_new.json b/tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_new.json new file mode 100644 index 00000000..f763334c --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_new.json @@ -0,0 +1,44 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + }, + { + "statements": [ + "Copyright (c) 2015 Edouard-Leon Scott de Martinville." + ], + "holders": [ + "Edouard-Leon Scott de Martinville." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_old.json b/tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_old.json new file mode 100644 index 00000000..93a4dfe9 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_change_no_license_change_old.json @@ -0,0 +1,36 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_new.json b/tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_new.json new file mode 100644 index 00000000..a15ef7d9 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_new.json @@ -0,0 +1,29 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_old.json b/tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_old.json new file mode 100644 index 00000000..f63d8697 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_old.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ], + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_new.json b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_new.json new file mode 100644 index 00000000..342a4a28 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_new.json @@ -0,0 +1,52 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 2, + "files": [ + { + "path":"test", + "name": "path", + "sha1": "c", + "original_path": "", + "licenses": [], + "copyrights": [] + }, + { + "path":"/test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "commercial-license", + "score": 55.0, + "short_name": "Commercial License", + "category": "Commercial", + "owner": "Unspecified" + }, + { + "key": "adapt-1.0", + "score": 15.0, + "short_name": "APL 1.0", + "category": "Copyleft", + "owner": "OSI - Open Source Initiative" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_old.json b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_old.json new file mode 100644 index 00000000..c7175031 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_old.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test", + "name": "path", + "sha1": "c", + "original_path": "", + "licenses": [], + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_new.json b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_new.json new file mode 100644 index 00000000..76143963 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_new.json @@ -0,0 +1,44 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 2, + "files": [ + { + "path":"test", + "name": "test", + "sha1": "b", + "original_path": "", + "licenses": [], + "copyrights": [] + }, + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_old.json b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_old.json new file mode 100644 index 00000000..de501a04 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_old.json @@ -0,0 +1,20 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test", + "name": "test", + "sha1": "b", + "original_path": "", + "licenses": [], + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_new.json b/tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_new.json new file mode 100644 index 00000000..f682d082 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_new.json @@ -0,0 +1,41 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + }, + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_old.json b/tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_old.json new file mode 100644 index 00000000..5dc99a55 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_license_change_no_copyright_change_old.json @@ -0,0 +1,35 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_new.json b/tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_new.json new file mode 100644 index 00000000..ff60bea5 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_new.json @@ -0,0 +1,27 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ], + "copyrights": [] + } + ] +} diff --git a/tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_old.json b/tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_old.json new file mode 100644 index 00000000..e622dcb6 --- /dev/null +++ b/tests/data/utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_old.json @@ -0,0 +1,29 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [], + "copyrights": [ + { + "statements": [ + "Copyright (c) 2017-2018 Francois Hennebique and others." + ], + "holders": [ + "Francois Hennebique and others." + ] + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_copyleft_license_info_added_new.json b/tests/data/utils/update_from_license_info_copyleft_license_info_added_new.json new file mode 100644 index 00000000..40b45f87 --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_license_info_added_new.json @@ -0,0 +1,26 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_copyleft_license_info_added_old.json b/tests/data/utils/update_from_license_info_copyleft_license_info_added_old.json new file mode 100644 index 00000000..9fba96ab --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_license_info_added_old.json @@ -0,0 +1,19 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true, + "--license": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_copyleft_license_info_removed_new.json b/tests/data/utils/update_from_license_info_copyleft_license_info_removed_new.json new file mode 100644 index 00000000..a419ea18 --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_license_info_removed_new.json @@ -0,0 +1,18 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_copyleft_license_info_removed_old.json b/tests/data/utils/update_from_license_info_copyleft_license_info_removed_old.json new file mode 100644 index 00000000..80c80d11 --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_license_info_removed_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_new.json b/tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_new.json new file mode 100644 index 00000000..e0c8c9c4 --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "bittorrent-1.0", + "score": 100.0, + "short_name": "BitTorrent 1.0", + "category": "Copyleft Limited" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_old.json b/tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_old.json new file mode 100644 index 00000000..80c80d11 --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_to_copyleft_limited_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_new.json b/tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_new.json new file mode 100644 index 00000000..26c6b3ae --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_new.json @@ -0,0 +1,26 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "adapt-1.0", + "score": 15.0, + "short_name": "APL 1.0", + "category": "Copyleft", + "owner": "OSI - Open Source Initiative" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_old.json b/tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_old.json new file mode 100644 index 00000000..80c80d11 --- /dev/null +++ b/tests/data/utils/update_from_license_info_copyleft_to_different_copyleft_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_no_license_changes_new.json b/tests/data/utils/update_from_license_info_no_license_changes_new.json new file mode 100644 index 00000000..dd1822af --- /dev/null +++ b/tests/data/utils/update_from_license_info_no_license_changes_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_no_license_changes_old.json b/tests/data/utils/update_from_license_info_no_license_changes_old.json new file mode 100644 index 00000000..7e801dce --- /dev/null +++ b/tests/data/utils/update_from_license_info_no_license_changes_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_no_license_key_value_new.json b/tests/data/utils/update_from_license_info_no_license_key_value_new.json new file mode 100644 index 00000000..4cb44630 --- /dev/null +++ b/tests/data/utils/update_from_license_info_no_license_key_value_new.json @@ -0,0 +1,17 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "" + } + ] +} diff --git a/tests/data/utils/update_from_license_info_no_license_key_value_old.json b/tests/data/utils/update_from_license_info_no_license_key_value_old.json new file mode 100644 index 00000000..440a685d --- /dev/null +++ b/tests/data/utils/update_from_license_info_no_license_key_value_old.json @@ -0,0 +1,17 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "" + } + ] +} diff --git a/tests/data/utils/update_from_license_info_one_license_added_new.json b/tests/data/utils/update_from_license_info_one_license_added_new.json new file mode 100644 index 00000000..ba8ee152 --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_license_added_new.json @@ -0,0 +1,31 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + }, + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_one_license_added_old.json b/tests/data/utils/update_from_license_info_one_license_added_old.json new file mode 100644 index 00000000..3a9f094d --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_license_added_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_one_license_removed_new.json b/tests/data/utils/update_from_license_info_one_license_removed_new.json new file mode 100644 index 00000000..47c2d914 --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_license_removed_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_one_license_removed_old.json b/tests/data/utils/update_from_license_info_one_license_removed_old.json new file mode 100644 index 00000000..404a0efe --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_license_removed_old.json @@ -0,0 +1,31 @@ +{ + "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.1.0", + "scancode_options": { + "--copyright": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + }, + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_new.json b/tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_new.json new file mode 100644 index 00000000..cc7ea68a --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_new.json @@ -0,0 +1,67 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + }, + { + "key": "adapt-1.0", + "score": 15.0, + "short_name": "APL 1.0", + "category": "Copyleft", + "owner": "OSI - Open Source Initiative" + }, + { + "key": "bittorrent-1.0", + "score": 100.0, + "short_name": "BitTorrent 1.0", + "category": "Copyleft Limited", + "owner": "BitTorrent, Inc." + }, + { + "key": "bloomberg-blpapi", + "score": 100.0, + "short_name": "Bloomberg BLPAPI License", + "category": "Proprietary Free", + "owner": "Bloomberg Labs" + }, + { + "key": "commercial-license", + "score": 55.0, + "short_name": "Commercial License", + "category": "Commercial", + "owner": "Unspecified" + }, + { + "key": "wrox-download", + "score": 100.0, + "short_name": "Wrox Download Terms and Conditions", + "category": "Free Restricted", + "owner": "Wiley" + }, + { + "key": "mozilla-ospl-1.0", + "score": 99.93, + "short_name": "Mozilla Open Software Patent License 1.0", + "category": "Patent License", + "owner": "Mozilla" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_old.json b/tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_old.json new file mode 100644 index 00000000..3a9f094d --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_new.json b/tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_new.json new file mode 100644 index 00000000..79f3c28c --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_new.json @@ -0,0 +1,31 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + }, + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_old.json b/tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_old.json new file mode 100644 index 00000000..3a9f094d --- /dev/null +++ b/tests/data/utils/update_from_license_info_one_permissive_to_two_permissives_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_permissive_license_info_added_new.json b/tests/data/utils/update_from_license_info_permissive_license_info_added_new.json new file mode 100644 index 00000000..b44bcb47 --- /dev/null +++ b/tests/data/utils/update_from_license_info_permissive_license_info_added_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_permissive_license_info_added_old.json b/tests/data/utils/update_from_license_info_permissive_license_info_added_old.json new file mode 100644 index 00000000..c6f3890f --- /dev/null +++ b/tests/data/utils/update_from_license_info_permissive_license_info_added_old.json @@ -0,0 +1,18 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_permissive_license_info_removed_new.json b/tests/data/utils/update_from_license_info_permissive_license_info_removed_new.json new file mode 100644 index 00000000..a419ea18 --- /dev/null +++ b/tests/data/utils/update_from_license_info_permissive_license_info_removed_new.json @@ -0,0 +1,18 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_permissive_license_info_removed_old.json b/tests/data/utils/update_from_license_info_permissive_license_info_removed_old.json new file mode 100644 index 00000000..3a9f094d --- /dev/null +++ b/tests/data/utils/update_from_license_info_permissive_license_info_removed_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/data/utils/update_from_license_info_single_license_change_new.json b/tests/data/utils/update_from_license_info_single_license_change_new.json new file mode 100644 index 00000000..dd1822af --- /dev/null +++ b/tests/data/utils/update_from_license_info_single_license_change_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "gpl-2.0", + "score": 70.0, + "short_name": "GPL 2.0", + "category": "Copyleft" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_single_license_change_old.json b/tests/data/utils/update_from_license_info_single_license_change_old.json new file mode 100644 index 00000000..9afb0c51 --- /dev/null +++ b/tests/data/utils/update_from_license_info_single_license_change_old.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_new.json b/tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_new.json new file mode 100644 index 00000000..d41c1788 --- /dev/null +++ b/tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_new.json @@ -0,0 +1,25 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + } + ] + } + ] +} diff --git a/tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_old.json b/tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_old.json new file mode 100644 index 00000000..b2deb18b --- /dev/null +++ b/tests/data/utils/update_from_license_info_two_permissives_to_one_permissive_old.json @@ -0,0 +1,31 @@ +{ + "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.1.0", + "scancode_options": { + "--license": true, + "--info": true + }, + "files_count": 1, + "files": [ + { + "path":"test/path.txt", + "name": "path.txt", + "sha1": "a_modified", + "original_path": "", + "licenses": [ + { + "key": "mit", + "score": 80.0, + "short_name": "MIT License", + "category": "Permissive" + }, + { + "key": "apache-2.0", + "score": 40.0, + "short_name": "Apache 2.0", + "category": "Permissive" + } + ] + } + ] +} diff --git a/tests/test_cli.py b/tests/test_cli.py index 3b605f72..d9dd29a1 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -46,15 +46,14 @@ def load_csv(location): Load a CSV file at location and return a tuple of (field names, list of rows as mappings field->value). """ - with codecs.open(location, 'rb', encoding='utf-8') as csvin: + with codecs.open(location, "rb", encoding="utf-8") as csvin: reader = unicodecsv.DictReader(csvin) fields = reader.fieldnames values = sorted(reader) return fields, values -def check_csvs( - result_file, expected_file, - regen=False): + +def check_csvs(result_file, expected_file, regen=False): """ Copied from https://github.com/nexB/scancode-toolkit/blob/develop/etc/scripts/test_json2csv.py Load and compare two CSVs. @@ -64,6 +63,7 @@ def check_csvs( result_fields, results = load_csv(result_file) if regen: import shutil + shutil.copy2(result_file, expected_file) expected_fields, expected = load_csv(expected_file) assert expected_fields == result_fields @@ -71,43 +71,44 @@ def check_csvs( for exp, res in zip(sorted(expected), sorted(results)): assert exp == res -class TestCLI(FileBasedTesting): - test_data_dir = os.path.join(os.path.dirname(__file__), 'data') +class TestCLI(FileBasedTesting): + test_data_dir = os.path.join(os.path.dirname(__file__), "data") + # TODO: need to fix in scancode def test_json_output_option_selected_all_selected(self): - new_scan = self.get_test_loc('cli/scan_1_file_moved_new.json') - old_scan = self.get_test_loc('cli/scan_1_file_moved_old.json') + new_scan = self.get_test_loc("cli/scan_1_file_moved_new.json") + old_scan = self.get_test_loc("cli/scan_1_file_moved_old.json") - result_file = self.get_temp_file('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']) + result = runner.invoke( + cli.cli, ["-n", new_scan, "-o", old_scan, "-j", result_file, "-a"] + ) assert result.exit_code == 0 json_result = json.load(open(result_file)) - notice = ('Generated with DeltaCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES\n' - 'OR CONDITIONS OF ANY KIND, either express or implied. No content created from\n' - 'DeltaCode should be considered or used as legal advice. Consult an Attorney\n' - 'for any legal advice.\n' - 'DeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\n' - 'Visit https://github.com/nexB/deltacode/ for support and download.') + notice = ( + 'Generated with DeltaCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES\n' + "OR CONDITIONS OF ANY KIND, either express or implied. No content created from\n" + "DeltaCode should be considered or used as legal advice. Consult an Attorney\n" + "for any legal advice.\n" + "DeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\n" + "Visit https://github.com/nexB/deltacode/ for support and download." + ) - assert json_result.get('deltacode_notice') == notice + assert json_result.get("deltacode_notice") == notice - options = { - '--new': new_scan, - '--old': old_scan, - '--all-delta-types': True - } + options = {"--new": new_scan, "--old": old_scan, "--all-delta-types": True} - assert json_result.get('deltacode_options') == options + assert json_result.get("deltacode_options") == options - assert json_result.get('deltacode_errors') == [] + assert json_result.get("deltacode_errors") == [] - assert json_result.get('deltas_count') == 8 + assert json_result.get("deltas_count") == 8 moved_expected = { "status": "moved", @@ -119,7 +120,7 @@ def test_json_output_option_selected_all_selected(self): "name": "a4.py", "size": 200, "sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b", - "fingerprint": "e30cf09443e7878dfed3288886e97542", + "fingerprint": "", "original_path": "1_file_moved_new/b/a4.py", "licenses": [ { @@ -127,7 +128,7 @@ def test_json_output_option_selected_all_selected(self): "score": 40.0, "short_name": "Apache 2.0", "category": "Permissive", - "owner": "Apache Software Foundation" + "owner": "Apache Software Foundation", } ], "copyrights": [ @@ -135,11 +136,9 @@ def test_json_output_option_selected_all_selected(self): "statements": [ "Copyright (c) 2017 Acme Software Inc. and others." ], - "holders": [ - "Acme Software Inc. and others." - ] + "holders": ["Acme Software Inc. and others."], } - ] + ], }, "old": { "path": "a/a4.py", @@ -147,7 +146,7 @@ def test_json_output_option_selected_all_selected(self): "name": "a4.py", "size": 200, "sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b", - "fingerprint": "e30cf09443e7878dfed3288886e97542", + "fingerprint": "", "original_path": "1_file_moved_old/a/a4.py", "licenses": [ { @@ -155,7 +154,7 @@ def test_json_output_option_selected_all_selected(self): "score": 40.0, "short_name": "Apache 2.0", "category": "Permissive", - "owner": "Apache Software Foundation" + "owner": "Apache Software Foundation", } ], "copyrights": [ @@ -163,15 +162,15 @@ def test_json_output_option_selected_all_selected(self): "statements": [ "Copyright (c) 2017 Acme Software Inc. and others." ], - "holders": [ - "Acme Software Inc. and others." - ] + "holders": ["Acme Software Inc. and others."], } - ] - } + ], + }, } - moved_result = [d for d in json_result.get('deltas') if d.get('status') == 'moved'].pop() + moved_result = [ + d for d in json_result.get("deltas") if d.get("status") == "moved" + ].pop() assert moved_result == moved_expected @@ -185,7 +184,7 @@ def test_json_output_option_selected_all_selected(self): "name": "a3.py", "size": 200, "sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9", - "fingerprint": "e30cf09443e7878dfed3288886e97533", + "fingerprint": "", "original_path": "1_file_moved_new/a/a3.py", "licenses": [ { @@ -193,7 +192,7 @@ def test_json_output_option_selected_all_selected(self): "score": 40.0, "short_name": "Apache 2.0", "category": "Permissive", - "owner": "Apache Software Foundation" + "owner": "Apache Software Foundation", } ], "copyrights": [ @@ -201,11 +200,9 @@ def test_json_output_option_selected_all_selected(self): "statements": [ "Copyright (c) 2017 Acme Software Inc. and others." ], - "holders": [ - "Acme Software Inc. and others." - ] + "holders": ["Acme Software Inc. and others."], } - ] + ], }, "old": { "path": "a/a3.py", @@ -213,7 +210,7 @@ def test_json_output_option_selected_all_selected(self): "name": "a3.py", "size": 200, "sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9", - "fingerprint": "e30cf09443e7878dfed3288886e97533", + "fingerprint": "", "original_path": "1_file_moved_old/a/a3.py", "licenses": [ { @@ -221,7 +218,7 @@ def test_json_output_option_selected_all_selected(self): "score": 40.0, "short_name": "Apache 2.0", "category": "Permissive", - "owner": "Apache Software Foundation" + "owner": "Apache Software Foundation", } ], "copyrights": [ @@ -229,54 +226,57 @@ def test_json_output_option_selected_all_selected(self): "statements": [ "Copyright (c) 2017 Acme Software Inc. and others." ], - "holders": [ - "Acme Software Inc. and others." - ] + "holders": ["Acme Software Inc. and others."], } - ] - } + ], + }, } - unmodified_result = [d for d in json_result.get('deltas') if d.get('score') == 0 and d.get('new').get('path') == 'a/a3.py'].pop() + unmodified_result = [ + d + for d in json_result.get("deltas") + if d.get("score") == 0 and d.get("new").get("path") == "a/a3.py" + ].pop() assert unmodified_result == unmodified_expected + # TODO: need to fix in scancode def test_json_output_option_selected_all_not_selected(self): - new_scan = self.get_test_loc('cli/scan_1_file_moved_new.json') - old_scan = self.get_test_loc('cli/scan_1_file_moved_old.json') + new_scan = self.get_test_loc("cli/scan_1_file_moved_new.json") + old_scan = self.get_test_loc("cli/scan_1_file_moved_old.json") - result_file = self.get_temp_file('json') + result_file = self.get_temp_file("json") runner = CliRunner() - result = runner.invoke(cli.cli, ['-n', new_scan, '-o', old_scan, '-j', result_file]) + result = runner.invoke( + cli.cli, ["-n", new_scan, "-o", old_scan, "-j", result_file] + ) assert result.exit_code == 0 json_result = json.load(open(result_file)) - notice = ('Generated with DeltaCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES\n' - 'OR CONDITIONS OF ANY KIND, either express or implied. No content created from\n' - 'DeltaCode should be considered or used as legal advice. Consult an Attorney\n' - 'for any legal advice.\n' - 'DeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\n' - 'Visit https://github.com/nexB/deltacode/ for support and download.') + notice = ( + 'Generated with DeltaCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES\n' + "OR CONDITIONS OF ANY KIND, either express or implied. No content created from\n" + "DeltaCode should be considered or used as legal advice. Consult an Attorney\n" + "for any legal advice.\n" + "DeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\n" + "Visit https://github.com/nexB/deltacode/ for support and download." + ) - assert json_result.get('deltacode_notice') == notice + assert json_result.get("deltacode_notice") == notice - options = { - '--new': new_scan, - '--old': old_scan, - '--all-delta-types': False - } + options = {"--new": new_scan, "--old": old_scan, "--all-delta-types": False} - assert json_result.get('deltacode_options') == options + assert json_result.get("deltacode_options") == options - assert json_result.get('deltacode_errors') == [] + assert json_result.get("deltacode_errors") == [] - assert json_result.get('deltas_count') == 1 + assert json_result.get("deltas_count") == 1 moved_expected = { - "status" : "moved", + "status": "moved", "factors": [], "score": 0, "new": { @@ -285,7 +285,7 @@ def test_json_output_option_selected_all_not_selected(self): "name": "a4.py", "size": 200, "sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b", - "fingerprint": "e30cf09443e7878dfed3288886e97542", + "fingerprint": "", "original_path": "1_file_moved_new/b/a4.py", "licenses": [ { @@ -293,7 +293,7 @@ def test_json_output_option_selected_all_not_selected(self): "score": 40.0, "short_name": "Apache 2.0", "category": "Permissive", - "owner": "Apache Software Foundation" + "owner": "Apache Software Foundation", } ], "copyrights": [ @@ -301,11 +301,9 @@ def test_json_output_option_selected_all_not_selected(self): "statements": [ "Copyright (c) 2017 Acme Software Inc. and others." ], - "holders": [ - "Acme Software Inc. and others." - ] + "holders": ["Acme Software Inc. and others."], } - ] + ], }, "old": { "path": "a/a4.py", @@ -313,7 +311,7 @@ def test_json_output_option_selected_all_not_selected(self): "name": "a4.py", "size": 200, "sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b", - "fingerprint": "e30cf09443e7878dfed3288886e97542", + "fingerprint": "", "original_path": "1_file_moved_old/a/a4.py", "licenses": [ { @@ -321,7 +319,7 @@ def test_json_output_option_selected_all_not_selected(self): "score": 40.0, "short_name": "Apache 2.0", "category": "Permissive", - "owner": "Apache Software Foundation" + "owner": "Apache Software Foundation", } ], "copyrights": [ @@ -329,35 +327,41 @@ def test_json_output_option_selected_all_not_selected(self): "statements": [ "Copyright (c) 2017 Acme Software Inc. and others." ], - "holders": [ - "Acme Software Inc. and others." - ] + "holders": ["Acme Software Inc. and others."], } - ] - } + ], + }, } - moved_result = [d for d in json_result.get('deltas') if d.get('status') == 'moved'].pop() + moved_result = [ + d for d in json_result.get("deltas") if d.get("status") == "moved" + ].pop() assert moved_result == moved_expected - unmodified_result = [d for d in json_result.get('deltas') if d.get('status') == 'unmodified'] + unmodified_result = [ + d for d in json_result.get("deltas") if d.get("status") == "unmodified" + ] assert len(unmodified_result) == 0 + # TODO: need to fix in scancode def test_no_output_option_selected_all_selected(self): - new_scan = self.get_test_loc('cli/scan_1_file_moved_new.json') - old_scan = self.get_test_loc('cli/scan_1_file_moved_old.json') + new_scan = self.get_test_loc("cli/scan_1_file_moved_new.json") + old_scan = self.get_test_loc("cli/scan_1_file_moved_old.json") runner = CliRunner() - result = runner.invoke(cli.cli, ['-n', new_scan, '-o', old_scan, '-a']) + result = runner.invoke(cli.cli, ["-n", new_scan, "-o", old_scan, "-a"]) assert result.exit_code == 0 - assert 'deltacode_notice' in result.output - assert 'Generated with DeltaCode and provided on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES\\n' in result.output + assert "deltacode_notice" in result.output + assert ( + 'Generated with DeltaCode and provided on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES\\n' + in result.output + ) - assert 'deltacode_options' in result.output + assert "deltacode_options" in result.output assert '"--all-delta-types": true' in result.output assert '"deltacode_errors": []' in result.output @@ -385,21 +389,25 @@ def test_no_output_option_selected_all_selected(self): assert '"type": "file"' in result.output assert '"size": 200' in result.output assert '"sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9"' in result.output - assert '"original_path": "1_file_moved_new/a/a3.py"' in result .output + assert '"original_path": "1_file_moved_new/a/a3.py"' in result.output + # TODO: need to fix in scancode def test_no_output_option_selected_all_not_selected(self): - new_scan = self.get_test_loc('cli/scan_1_file_moved_new.json') - old_scan = self.get_test_loc('cli/scan_1_file_moved_old.json') + new_scan = self.get_test_loc("cli/scan_1_file_moved_new.json") + old_scan = self.get_test_loc("cli/scan_1_file_moved_old.json") runner = CliRunner() - result = runner.invoke(cli.cli, ['-n', new_scan, '-o', old_scan]) + result = runner.invoke(cli.cli, ["-n", new_scan, "-o", old_scan]) assert result.exit_code == 0 - assert 'deltacode_notice' in result.output - assert 'Generated with DeltaCode and provided on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES\\n' in result.output + assert "deltacode_notice" in result.output + assert ( + 'Generated with DeltaCode and provided on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES\\n' + in result.output + ) - assert 'deltacode_options' in result.output + assert "deltacode_options" in result.output assert '"--all-delta-types": false' in result.output assert '"deltacode_errors": []' in result.output @@ -425,59 +433,64 @@ def test_no_output_option_selected_all_not_selected(self): assert '"path": "a/a3.py"' not in result.output assert '"name": "a3.py"' not in result.output assert '"sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9"' not in result.output - assert '"original_path": "1_file_moved_new/a/a3.py"' 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') + 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') + result_file = self.get_temp_file("json") runner = CliRunner() - result = runner.invoke(cli.cli, ['-n', new_scan, '-o', old_scan, '-j', result_file, '-a']) + 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 + 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') + 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') + result_file = self.get_temp_file("json") runner = CliRunner() - result = runner.invoke(cli.cli, ['-n', new_scan, '-o', old_scan, '-j', result_file]) + 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 + assert json_result.get("deltas_count") == 4 def test_help(self): runner = CliRunner() - result = runner.invoke(cli.cli, ['--help']) + result = runner.invoke(cli.cli, ["--help"]) - assert 'Usage: cli [OPTIONS]' in result.output - assert 'Identify the changes that need to be made' in result.output - assert 'If no file option is selected' in result.output - assert 'Include unmodified files' in result.output - assert '--version' in result.output + assert "Usage: cli [OPTIONS]" in result.output + assert "Identify the changes that need to be made" in result.output + assert "If no file" in result.output + assert "option is selected" in result.output + assert "Include unmodified files" in result.output + assert "--version" in result.output def test_version(self): runner = CliRunner() - result = runner.invoke(cli.cli, ['--version']) + result = runner.invoke(cli.cli, ["--version"]) - assert 'DeltaCode version' in result.output + assert "DeltaCode version" in result.output def test_empty(self): runner = CliRunner() result = runner.invoke(cli.cli, []) - - assert 'Usage: cli [OPTIONS]' in result.output + + assert "Usage: cli [OPTIONS]" in result.output assert "Error: Missing option '-n' / '--new'." in result.output def test_incorrect_flag(self): runner = CliRunner() - result = runner.invoke(cli.cli, ['-xyz']) + result = runner.invoke(cli.cli, ["-xyz"]) - assert 'Error: no such option: -x' in result.output + assert "Error: No such option: -x" in result.output diff --git a/tests/test_deltacode.py b/tests/test_deltacode.py index 29c373a1..8ced61da 100644 --- a/tests/test_deltacode.py +++ b/tests/test_deltacode.py @@ -37,55 +37,45 @@ from deltacode import DeltaCode from deltacode import models from deltacode import test_utils +from deltacode import utils +from deltacode.utils import collect_errors +from deltacode.test_utils import get_aligned_path +from commoncode.resource import VirtualCodebase + class TestDeltacode(FileBasedTesting): test_data_dir = os.path.join(os.path.dirname(__file__), 'data') def test_align_and_index_scans(self): - new_scan = self.get_test_loc('deltacode/ecos-align-index-new.json') - old_scan = self.get_test_loc('deltacode/ecos-align-index-old.json') - - new = models.Scan(new_scan) - old = models.Scan(old_scan) + new = self.get_test_loc('deltacode/ecos-align-index-new.json') + old = self.get_test_loc('deltacode/ecos-align-index-old.json') options = OrderedDict([ ('--all-delta-types', False) ]) - delta = DeltaCode(None, None, options) - - delta.new = new - delta.old = old + delta = DeltaCode(new, old, options) - delta.align_scans() + new_offset, old_offset = utils.align_trees(delta.codebase1, delta.codebase2) + + assert new_offset == 2 + + assert old_offset == 2 - new_index = delta.new.index_files() - old_index = delta.old.index_files() - new_index_length = 0 - for k,v in new_index.items(): - new_index_length += len(v) + # def test_DeltaCode_ecos_failed_counts_assertion(self): + # new_scan = self.get_test_loc('deltacode/ecos-failed-counts-assertion-new.json') + # old_scan = self.get_test_loc('deltacode/ecos-failed-counts-assertion-old.json') - old_index_length = 0 - for k,v in old_index.items(): - old_index_length += len(v) + # options = OrderedDict([ + # ('--all-delta-types', False) + # ]) - assert delta.new.files_count == new_index_length - assert delta.old.files_count == old_index_length + # result = DeltaCode(new_scan, old_scan, options) - def test_DeltaCode_ecos_failed_counts_assertion(self): - new_scan = self.get_test_loc('deltacode/ecos-failed-counts-assertion-new.json') - old_scan = self.get_test_loc('deltacode/ecos-failed-counts-assertion-old.json') - - options = OrderedDict([ - ('--all-delta-types', False) - ]) - - result = DeltaCode(new_scan, old_scan, options) - - assert result.new.files_count == 11408 - assert result.old.files_count == 8631 + # assert len(result.new_files) == 11409 + # assert len(result.old_files) == 8632 def test_DeltaCode_align_scan_zlib_alignment_exception(self): new_scan = self.get_test_loc('deltacode/align-scan-zlib-alignment-exception-new.json') @@ -98,40 +88,20 @@ def test_DeltaCode_align_scan_zlib_alignment_exception(self): results = DeltaCode(new_scan, old_scan, options) - assert results.new.files_count == 293 - assert results.old.files_count == 40 - - for f in results.new.files: - assert f.__class__.__name__ == 'File' - assert f.original_path != None - assert f.original_path == f.path - - for f in results.old.files: - assert f.__class__.__name__ == 'File' - assert f.original_path != None - assert f.original_path == f.path - - def test_DeltaCode_delta_len_error(self): - new_scan = self.get_test_loc('deltacode/delta-len-error-new.json') - old_scan = self.get_test_loc('deltacode/delta-len-error-old.json') - - options = OrderedDict([ - ('--all-delta-types', False) - ]) - - result = DeltaCode(new_scan, old_scan, options) + assert results.codebase1.compute_counts()[0] + results.codebase1.compute_counts()[1] == 294 + assert results.codebase2.compute_counts()[0] + results.codebase2.compute_counts()[1] == 41 - # Modifiy files_count value to raise the error. - # This should never happen in reality. - result.new.files_count = 42 - result.old.files_count = 40 + for f in results.codebase1.walk(): + assert f.__class__.__name__ == 'ScannedResource' + assert f.rid != None + assert not f.is_filtered - result.determine_delta() - assert result.errors == [ - 'DeltaCode Warning: new_visited(33) != new_total(42). Assuming old scancode format.', - 'DeltaCode Warning: old_visited(33) != old_total(40). Assuming old scancode format.', - ] + for f in results.codebase1.walk(): + assert f.__class__.__name__ == 'ScannedResource' + assert f.rid != None + assert not f.is_filtered + @pytest.mark.xfail(reason='Tests no longer required having None paths') def test_DeltaCode_invalid_paths(self): test_path_1 = '/some/invalid/path/1.json' test_path_2 = '/some/invalid/path/2.json' @@ -142,16 +112,11 @@ def test_DeltaCode_invalid_paths(self): result = DeltaCode(test_path_1, test_path_2, options) - assert result.new.path == '' - assert result.new.files_count == 0 - assert result.new.files == [] - - assert result.old.path == '' - assert result.old.files_count == 0 - assert result.old.files == [] - - assert result.deltas == [] + assert result.codebase1 == None + assert result.codebase2 == None + assert len(result.errors) >= 1 + @pytest.mark.xfail(reason='Tests no longer required having invalid paths') def test_DeltaCode_empty_paths(self): options = OrderedDict([ ('--all-delta-types', False) @@ -159,16 +124,15 @@ def test_DeltaCode_empty_paths(self): result = DeltaCode('', '', options) - assert result.new.path == '' - assert result.new.files_count == 0 - assert result.new.files == [] + assert result.codebase1 == None - assert result.old.path == '' - assert result.old.files_count == 0 - assert result.old.files == [] + assert result.codebase2 == None assert result.deltas == [] + assert result.errors + + @pytest.mark.xfail(reason='Tests no longer required having None paths') def test_DeltaCode_None_paths(self): options = OrderedDict([ ('--all-delta-types', False) @@ -176,19 +140,18 @@ def test_DeltaCode_None_paths(self): result = DeltaCode(None, None, options) - assert result.new.path == '' - assert result.new.files_count == 0 - assert result.new.files == [] - - assert result.old.path == '' - assert result.old.files_count == 0 - assert result.old.files == [] - + assert result.errors + assert result.codebase1 == None + assert result.codebase2 == None assert result.deltas == [] + @pytest.mark.xfail(reason='Tests no longer required having None paths') def test_Delta_one_None(self): - file_obj = models.File({'path': 'fake/path.txt'}) - + try: + file_obj = VirtualCodebase('fake/path.txt') + except IOError: + file_obj = None + pass first_None = deltacode.Delta(10, None, file_obj) second_None = deltacode.Delta(100, file_obj, None) @@ -234,18 +197,6 @@ def test_Delta_one_None(self): ('old', None) ]) - assert first_None.to_dict() == expected_first - assert second_None.to_dict() == expected_second - - def test_Delta_None_files(self): - delta = deltacode.Delta(None, None, None) - - assert type(delta.new_file) == type(None) - assert type(delta.old_file) == type(None) - assert delta.score == None - assert delta.factors == [] - assert delta.to_dict() == OrderedDict([('status', ''), ('factors', []), ('score', None), ('new', None), ('old', None)]) - def test_DeltaCode_license_modified(self): new_scan = self.get_test_loc('deltacode/scan_modified_new_license_added.json') old_scan = self.get_test_loc('deltacode/scan_modified_old_license_added.json') @@ -263,16 +214,16 @@ def test_DeltaCode_license_modified(self): assert len([i for i in deltas if i.score == 30]) == 0 assert len([i for i in deltas if i.score == 20]) == 1 - assert [d.score for d in deltas if d.new_file.path == 'some/path/a/a1.py'] == [50] - assert [d.score for d in deltas if d.new_file.path == 'some/path/b/b1.py'] == [40] - assert [d.score for d in deltas if d.new_file.path == 'some/path/c/c1.py'] == [20] + assert [d.score for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/a/a1.py'] == [50] + assert [d.score for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/b/b1.py'] == [40] + assert [d.score for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/c/c1.py'] == [20] - assert [d.factors for d in deltas if d.new_file.path == 'some/path/a/a1.py'].pop() == ['license change', 'copyleft added'] - assert [d.status for d in deltas if d.new_file.path == 'some/path/a/a1.py'] == ['modified'] - assert [d.factors for d in deltas if d.new_file.path == 'some/path/b/b1.py'].pop() == ['license change', 'copyleft added'] - assert [d.status for d in deltas if d.new_file.path == 'some/path/b/b1.py'] == ['modified'] - assert [d.factors for d in deltas if d.new_file.path == 'some/path/c/c1.py'].pop() == [] - assert [d.status for d in deltas if d.new_file.path == 'some/path/c/c1.py'] == ['modified'] + assert [d.factors for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/a/a1.py'].pop() == ['license change', 'copyleft added'] + assert [d.status for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/a/a1.py'] == ['modified'] + assert [d.factors for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/b/b1.py'].pop() == ['license change', 'copyleft added'] + assert [d.status for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/b/b1.py'] == ['modified'] + assert [d.factors for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/c/c1.py'].pop() == [] + assert [d.status for d in deltas if get_aligned_path(d, d.new_file.path, new_file=True) == 'some/path/c/c1.py'] == ['modified'] def test_DeltaCode_errors_empty(self): new_scan = self.get_test_loc('deltacode/scan_1_file_moved_new.json') @@ -287,15 +238,8 @@ def test_DeltaCode_errors_empty(self): assert result.errors == [] def test_Delta_to_dict_removed(self): - old = models.File({ - 'path': 'path/removed.txt', - 'type': 'file', - 'name': 'removed.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3288886e12345', - 'original_path': '' - }) + new_scan = self.get_test_loc('deltacode/Delta_to_dict_removed_new.json') + old_scan = self.get_test_loc('deltacode/Delta_to_dict_removed_old.json') expected = OrderedDict([ ('status', 'removed'), @@ -303,33 +247,27 @@ def test_Delta_to_dict_removed(self): ('score', 0), ('new', None), ('old', OrderedDict([ - ('path', 'path/removed.txt'), + ('path', 'music/CONTRIBUTING.rst'), ('type', 'file'), - ('name', 'removed.txt'), - ('size', 20), - ('sha1', 'a'), - ('fingerprint', 'e30cf09443e7878dfed3288886e12345'), - ('original_path', ''), + ('name', 'CONTRIBUTING.rst'), + ('size', 7783), + ('sha1', '476f2310923943accd0ec4361ab36053d8ce46e0'), + ('fingerprint', ''), + ('original_path', 'music/CONTRIBUTING.rst'), ('licenses', []), ('copyrights', []) ])) ]) - delta = deltacode.Delta(0, None, old) + results = DeltaCode(new_scan, old_scan, {}) + delta = results.deltas[0] delta.status = 'removed' - assert delta.to_dict() == expected + assert delta.to_dict(results) == expected def test_Delta_to_dict_added(self): - new = models.File({ - 'path': 'path/added.txt', - 'type': 'file', - 'name': 'added.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3288886e12345', - 'original_path': '' - }) + new = self.get_test_loc('deltacode/delta_to_dict_added_new.json') + old = self.get_test_loc('deltacode/delta_to_dict_added_old.json') expected = OrderedDict([ ('status', 'added'), @@ -342,37 +280,23 @@ def test_Delta_to_dict_added(self): ('size', 20), ('sha1', 'a'), ('fingerprint', 'e30cf09443e7878dfed3288886e12345'), - ('original_path', ''), + ('original_path', 'path/added.txt'), ('licenses', []), ('copyrights', []) ])), ('old', None) ]) - delta = deltacode.Delta(100, new, None) + deltacode = DeltaCode(new, old, {}) + delta = deltacode.deltas[0] delta.status = 'added' - assert delta.to_dict() == expected + assert delta.to_dict(deltacode) == expected + def test_Delta_to_dict_modified(self): - new = models.File({ - 'path': 'path/modified.txt', - 'type': 'file', - 'name': 'modified.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3288886e97542', - 'original_path': '' - }) - old = models.File({ - 'path': 'path/modified.txt', - 'type': 'file', - 'name': 'modified.txt', - 'size': 21, - 'sha1': 'b', - 'fingerprint': 'e30cf09443e2878dfed3288886e97541', - 'original_path': '' - }) + new = self.get_test_loc('deltacode/delta_to_dict_modified_new.json') + old = self.get_test_loc('deltacode/delta_to_dict_modified_old.json') expected = OrderedDict([ ('status', 'modified'), @@ -384,8 +308,8 @@ def test_Delta_to_dict_modified(self): ('name', 'modified.txt'), ('size', 20), ('sha1', 'a'), - ('fingerprint', 'e30cf09443e7878dfed3288886e97542'), - ('original_path', ''), + ("fingerprint", ""), + ('original_path', 'path/modified.txt'), ('licenses', []), ('copyrights', []) ])), @@ -395,37 +319,22 @@ def test_Delta_to_dict_modified(self): ('name', 'modified.txt'), ('size', 21), ('sha1', 'b'), - ('fingerprint', 'e30cf09443e2878dfed3288886e97541'), - ('original_path', ''), + ("fingerprint", ""), + ('original_path', 'path/modified.txt'), ('licenses', []), ('copyrights', []) ])) ]) - delta = deltacode.Delta(20, new, old) + deltacode_object = DeltaCode(new, old, {}) + delta = deltacode_object.deltas[0] delta.status = 'modified' - assert delta.to_dict() == expected + assert delta.to_dict(deltacode_object) == expected def test_Delta_to_dict_unmodified(self): - new = models.File({ - 'path': 'path/unmodified.txt', - 'type': 'file', - 'name': 'unmodified.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3288886e97542', - 'original_path': '' - }) - old = models.File({ - 'path': 'path/unmodified.txt', - 'type': 'file', - 'name': 'unmodified.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3288886e97542', - 'original_path': '' - }) + new = self.get_test_loc('deltacode/delta_to_dict_unmodified_new.json') + old = self.get_test_loc('deltacode/delta_to_dict_unmodified_old.json') expected = OrderedDict([ ('status', 'unmodified'), @@ -438,7 +347,7 @@ def test_Delta_to_dict_unmodified(self): ('size', 20), ('sha1', 'a'), ('fingerprint', 'e30cf09443e7878dfed3288886e97542'), - ('original_path', ''), + ('original_path', 'path/unmodified.txt'), ('licenses', []), ('copyrights', []) ])), @@ -449,80 +358,57 @@ def test_Delta_to_dict_unmodified(self): ('size', 20), ('sha1', 'a'), ('fingerprint', 'e30cf09443e7878dfed3288886e97542'), - ('original_path', ''), + ('original_path', 'path/unmodified.txt'), ('licenses', []), ('copyrights', []) ])) ]) - delta = deltacode.Delta(0, new, old) + results = DeltaCode(old, new, {"--all-delta-types" : True}) + + delta = results.deltas[0] + delta.status = 'unmodified' - assert delta.to_dict() == expected + assert delta.to_dict(results) == expected def test_Delta_to_dict_moved(self): - new = models.File({ - 'path': 'path_new/moved.txt', - 'type': 'file', - 'name': 'moved.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3288886e97542', - 'original_path': '' - }) - old = models.File({ - 'path': 'path_old/moved.txt', - 'type': 'file', - 'name': 'moved.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3288886e97542', - 'original_path': '' - }) + new = self.get_test_loc('deltacode/delta_to_dict_moved_new.json') + old = self.get_test_loc('deltacode/delta_to_dict_moved_old.json') expected = OrderedDict([ ('status', 'moved'), ('factors', []), ('score', 0), ('new', OrderedDict([ - ('path', 'path_new/moved.txt'), + ('path', 'moved.txt'), ('type', 'file'), ('name', 'moved.txt'), ('size', 20), ('sha1', 'a'), ('fingerprint', 'e30cf09443e7878dfed3288886e97542'), - ('original_path', ''), + ('original_path', 'path_new/moved.txt'), ('licenses', []), ('copyrights', []) ])), ('old', OrderedDict([ - ('path', 'path_old/moved.txt'), + ('path', 'moved.txt'), ('type', 'file'), ('name', 'moved.txt'), ('size', 20), ('sha1', 'a'), ('fingerprint', 'e30cf09443e7878dfed3288886e97542'), - ('original_path', ''), + ('original_path', 'path_old/moved.txt'), ('licenses', []), ('copyrights', []) ])) ]) - delta = deltacode.Delta(0, new, old) + deltacode = DeltaCode(new, old, {}) + delta = deltacode.deltas[0] delta.status = 'moved' - assert delta.to_dict() == expected - - def test_Delta_to_dict_empty(self): - delta = deltacode.Delta() - - assert delta.to_dict() == OrderedDict([ - ('status', ''), - ('factors', []), - ('score', 0), - ('new', None), - ('old', None) - ]) + assert delta.to_dict(deltacode) == expected def test_Delta_create_object_removed(self): new = None @@ -609,13 +495,13 @@ def test_score_new_no_lic_info(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [35] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license info removed'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [35] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license info removed'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'mit'), ('score', 50.0), @@ -624,7 +510,7 @@ def test_score_new_no_lic_info(self): ('owner', None) ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] def test_score_old_no_lic_info(self): new_scan = self.get_test_loc('deltacode/score_old_no_lic_info_new.json') @@ -638,14 +524,14 @@ def test_score_old_no_lic_info(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [40] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license info added', 'permissive added'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [40] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license info added', 'permissive added'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'mit'), ('score', 50.0), @@ -667,13 +553,13 @@ def test_score_multiple_lic_keys(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [50] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license change', 'copyleft added'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [50] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license change', 'copyleft added'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'mit'), ('score', 50.0), @@ -682,7 +568,7 @@ def test_score_multiple_lic_keys(self): ('owner', None) ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-2.0'), ('score', 100.0), @@ -711,13 +597,13 @@ def test_score_no_lic_change(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [20] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'mit'), ('score', 95.0), @@ -726,7 +612,7 @@ def test_score_no_lic_change(self): ('owner', None) ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'mit'), ('score', 95.0), @@ -748,13 +634,13 @@ def test_score_new_multiple_keys_same_lic(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [20] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get("old").get("licenses") for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'mit'), ('score', 100.0), @@ -763,7 +649,7 @@ def test_score_new_multiple_keys_same_lic(self): ('owner', None) ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'mit'), ('score', 75.0), @@ -783,7 +669,6 @@ def test_score_new_multiple_keys_same_lic(self): def test_score_single_copyright_change(self): new_scan = self.get_test_loc('deltacode/score_single_copyright_change_new.json') old_scan = self.get_test_loc('deltacode/score_single_copyright_change_old.json') - options = OrderedDict([ ('--all-delta-types', False) ]) @@ -791,26 +676,25 @@ def test_score_single_copyright_change(self): deltacode_object = DeltaCode(new_scan, old_scan, options) deltas_object = deltacode_object.deltas + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] - - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [25] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['copyright change'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [25] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['copyright change'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler']), ('holders', ['Jean-loup Gailly, Mark Adler']) ]) ] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - + assert len(deltas_object) == 2 assert len([i for i in deltas_object if i.score == 30]) == 0 assert len([i for i in deltas_object if i.score == 25]) == 1 assert len([i for i in deltas_object if i.score == 20]) == 0 @@ -827,14 +711,14 @@ def test_score_copyright_info_added(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['copyright info added'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [30] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['copyright info added'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) @@ -857,19 +741,19 @@ def test_score_copyright_info_removed(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['copyright info removed'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [30] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['copyright info removed'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] assert len([i for i in deltas_object if i.score == 30]) == 1 assert len([i for i in deltas_object if i.score == 20]) == 0 @@ -885,15 +769,15 @@ def test_score_no_copyright_info(self): deltacode_object = DeltaCode(new_scan, old_scan, options) deltas_object = deltacode_object.deltas + + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] - - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [20] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] assert len([i for i in deltas_object if i.score == 30]) == 0 assert len([i for i in deltas_object if i.score == 20]) == 1 @@ -910,19 +794,19 @@ def test_score_no_copyright_changes(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [20] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) @@ -944,14 +828,14 @@ def test_score_no_copyright_key(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [20] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] assert len([i for i in deltas_object if i.score == 30]) == 0 assert len([i for i in deltas_object if i.score == 20]) == 1 @@ -968,21 +852,21 @@ def test_score_copyright_and_license_info_added(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [70] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license info added', 'copyleft added', 'copyright info added'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [70] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license info added', 'copyleft added', 'copyright info added'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-1.0-plus'), ('score', 20.0), @@ -1009,20 +893,20 @@ def test_score_copyright_and_license_info_removed(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [45] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license info removed', 'copyright info removed'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [45] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license info removed', 'copyright info removed'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-1.0-plus'), ('score', 20.0), @@ -1031,7 +915,7 @@ def test_score_copyright_and_license_info_removed(self): ('owner', "Free Software Foundation (FSF)") ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] assert len([i for i in deltas_object if i.score == 55]) == 0 assert len([i for i in deltas_object if i.score == 45]) == 1 @@ -1049,21 +933,22 @@ def test_score_copyright_info_added_license_info_removed(self): deltacode_object = DeltaCode(new_scan, old_scan, options) deltas_object = deltacode_object.deltas + - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [45] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license info removed', 'copyright info added'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [45] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license info removed', 'copyright info added'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-3.0-plus'), ('score', 100.0), @@ -1072,7 +957,7 @@ def test_score_copyright_info_added_license_info_removed(self): ('owner', "Free Software Foundation (FSF)") ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] assert len([i for i in deltas_object if i.score == 55]) == 0 assert len([i for i in deltas_object if i.score == 50]) == 0 @@ -1092,21 +977,21 @@ def test_score_license_info_added_copyright_info_removed(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [70] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license info added', 'copyleft added', 'copyright info removed'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [70] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license info added', 'copyleft added', 'copyright info removed'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [] + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-3.0-plus'), ('score', 100.0), @@ -1134,25 +1019,25 @@ def test_score_copyright_change_no_license_change(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [25] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['copyright change'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [25] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['copyright change'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Alfred E. Neuman']), ('holders', ['Alfred E. Neuman']) ]) ] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-3.0-plus'), ('score', 100.0), @@ -1161,7 +1046,7 @@ def test_score_copyright_change_no_license_change(self): ('owner', "Free Software Foundation (FSF)") ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-3.0-plus'), ('score', 100.0), @@ -1187,25 +1072,25 @@ def test_score_license_change_no_copyright_change(self): deltas_object = deltacode_object.deltas - assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b'] - assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified'] + assert [d.old_file.sha1 for d in deltas_object if get_aligned_path(d, d.old_file.path, new_file=False) == 'path.txt'] == ['b'] + assert [d.new_file.sha1 for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['b_modified'] - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license change'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] - assert [d.to_dict().get('old').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [30] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license change'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] + assert [d.to_dict(deltacode_object).get('old').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('new').get('copyrights') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('copyrights') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('statements', ['Copyright (c) 2016 Mark Adler']), ('holders', ['Mark Adler']) ]) ] - assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('old').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-3.0-plus'), ('score', 100.0), @@ -1214,7 +1099,7 @@ def test_score_license_change_no_copyright_change(self): ('owner', "Free Software Foundation (FSF)") ]) ] - assert [d.to_dict().get('new').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [ + assert [d.to_dict(deltacode_object).get('new').get('licenses') for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == [ OrderedDict([ ('key', 'gpl-1.0-plus'), ('score', 20.0), @@ -1282,109 +1167,26 @@ def test_Delta_update_license_change_no_copyright_change(self): deltas_object = deltacode_object.deltas - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license change'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [30] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license change'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] for d in deltas_object: - if d.new_file.path == 'path.txt': + if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt': d.update(25, 'This is a test of a license change') - assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [55] - assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['license change', 'This is a test of a license change'] - assert [d.status for d in deltas_object if d.new_file.path == 'path.txt'] == ['modified'] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == [55] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'].pop() == ['license change', 'This is a test of a license change'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'path.txt'] == ['modified'] - def test_Delta_to_dict_multiple_copyright_statements_and_holders(self): - new = { - 'path': 'path/modified.txt', - 'type': 'file', - 'name': 'modified.txt', - 'size': 21, - 'sha1': 'a_modified', - 'fingerprint': 'e30cf09443e7878dfed3288886e97542', - 'original_path': '', - 'licenses': [], - 'copyrights': [ - { - "statements": [ - "Copyright (c) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler", - "Copyright (c) 1998 by Andreas R. Kleinert", - "Copyright (c) 2002-2004 Dmitriy Anisimkov", - "Copyright (c) 1998, 2007 Brian Raiter", - "Copyright (c) 1997,99 Borland Corp.", - "(c) Copyright Henrik Ravn 2004", - "Copyright (c) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant.", - "Copyright (c) 2003 Chris Anderson", - "Copyright (c) 1997 Christian Michelsen Research as Advanced Computing", - "Copyright (c) 2009-2010 Mathias Svensson http://result42.com", - "Copyright (c) 1990-2000 Info-ZIP.", - "Copyright (c) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler", - "Copyright (c) 1998 by Andreas R. Kleinert", - "Copyright (c) 2002-2004 Dmitriy Anisimkov", - "Copyright (c) 1998, 2007 Brian Raiter", - "Copyright (c) 1997,99 Borland Corp.", - "(c) Copyright Henrik Ravn 2004", - "Copyright (c) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant.", - "Copyright (c) 2003 Chris Anderson", - "Copyright (c) 1997 Christian Michelsen Research as Advanced Computing", - "Copyright (c) 2009-2010 Mathias Svensson http://result42.com", - "Copyright (c) 1990-2000 Info-ZIP." - ], - "holders": [ - "Jean-loup Gailly, Mark Adler", - "Andreas R. Kleinert", - "Dmitriy Anisimkov", - "Brian Raiter", - "Borland Corp.", - "Henrik Ravn", - "Jean-loup Gailly, Brian Raiter, Gilles Vollant", - "Chris Anderson", - "Christian Michelsen Research as Advanced Computing", - "Mathias Svensson", - "Info-ZIP", - "Jean-loup Gailly, Mark Adler", - "Andreas R. Kleinert", - "Dmitriy Anisimkov", - "Brian Raiter", - "Borland Corp.", - "Henrik Ravn", - "Jean-loup Gailly, Brian Raiter, Gilles Vollant", - "Chris Anderson", - "Christian Michelsen Research as Advanced Computing", - "Mathias Svensson", - "Info-ZIP" - ], - "authors": [] - } - ] - } - - old = { - 'path': 'path/modified.txt', - 'type': 'file', - 'name': 'modified.txt', - 'size': 20, - 'sha1': 'a', - 'fingerprint': 'e30cf09443e7878dfed3289786e97542', - 'original_path': '', - 'licenses': [], - 'copyrights': [ - { - "statements": [ - "Copyright (c) 2018 Jane Doe" - ], - "holders": [ - "Jane Doe" - ], - "authors": [] - } - ] - } + def test_Delta_to_dict_multiple_copyright_statements_and_holders(self): + new = self.get_test_loc('deltacode/delta_to_dict_multiple_copyright_statements_and_holders_new.json') + old = self.get_test_loc('deltacode/delta_to_dict_multiple_copyright_statements_and_holders_old.json') expected = OrderedDict([ ('status', 'modified'), - ('factors', []), - ('score', 20), + ('factors', ['copyright change', 'Similar with hamming distance : 5']), + ('score', 30), ('new', OrderedDict([ ('path', 'path/modified.txt'), ('type', 'file'), @@ -1392,7 +1194,7 @@ def test_Delta_to_dict_multiple_copyright_statements_and_holders(self): ('size', 21), ('sha1', 'a_modified'), ('fingerprint', 'e30cf09443e7878dfed3288886e97542'), - ('original_path', ''), + ('original_path', 'path/modified.txt'), ('licenses', []), ('copyrights', [OrderedDict([ ('statements', [ @@ -1452,7 +1254,7 @@ def test_Delta_to_dict_multiple_copyright_statements_and_holders(self): ('size', 20), ('sha1', 'a'), ('fingerprint', 'e30cf09443e7878dfed3289786e97542'), - ('original_path', ''), + ('original_path', 'path/modified.txt'), ('licenses', []), ('copyrights', [OrderedDict([ ('statements', [ @@ -1465,13 +1267,11 @@ def test_Delta_to_dict_multiple_copyright_statements_and_holders(self): ])) ]) - result_new = models.File(new) - result_old = models.File(old) - - delta = deltacode.Delta(20, result_new, result_old) - delta.status = 'modified' + results = DeltaCode(new, old, {}) + + delta = results.deltas[0] - assert delta.to_dict() == expected + assert delta.to_dict(results) == expected def test_Delta_to_dict_Copyright_unusual_characters(self): new_scan = self.get_test_loc('deltacode/scan_unusual_characters_new.json') @@ -1485,25 +1285,25 @@ def test_Delta_to_dict_Copyright_unusual_characters(self): deltas_object = deltacode_object.deltas - assert [d.factors for d in deltas_object if d.new_file.path == 'a1.py'].pop() == ['license change', 'copyleft added', 'copyright change'] - assert [d.status for d in deltas_object if d.new_file.path == 'a1.py'] == ['modified'] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'].pop() == ['license change', 'copyleft added', 'copyright change'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == ['modified'] - holders_list = [c.holders.pop() for d in deltas_object if d.new_file.path == 'a1.py' for c in d.new_file.copyrights] + holders_list = [c["holders"].pop() for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py' for c in d.new_file.copyrights] assert 'Francois Hennebique and others.' in holders_list assert 'Ottomar Anschutz.' in holders_list assert 'Christiane Nusslein-Volhard.' in holders_list assert 'Behram Kursunoglu.' in holders_list - statements_list = [c.statements.pop() for d in deltas_object if d.new_file.path == 'a1.py' for c in d.new_file.copyrights] + statements_list = [c["statements"].pop() for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py' for c in d.new_file.copyrights] assert 'Copyright (c) 2017-2018 Francois Hennebique and others.' in statements_list assert 'Copyright (c) 1999 Ottomar Anschutz.' in statements_list assert 'Copyright (c) 2015-18 Christiane Nusslein-Volhard.' in statements_list assert 'Copyright (c) 1999 Behram Kursunoglu.' in statements_list - assert [d.score for d in deltas_object if d.new_file.path == 'a1.py'] == [55] - assert [d.score for d in deltas_object if d.new_file.path == 'a2.py'] == [0] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == [55] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == [0] def test_DeltaCode_sort_order(self): new_scan = self.get_test_loc('deltacode/scan_sorted01_new.json') @@ -1547,13 +1347,13 @@ def test_DeltaCode_no_lic_to_all_notable_lic(self): deltas_object = deltacode_object.deltas - assert [d.score for d in deltas_object if d.new_file.path == 'a1.py'] == [170] - assert [d.score for d in deltas_object if d.new_file.path == 'a2.py'] == [0] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == [170] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == [0] - assert sorted([d.factors for d in deltas_object if d.new_file.path == 'a1.py'].pop()) == sorted([ 'license info added', 'commercial added', 'copyleft added', 'copyleft limited added', 'free restricted added', 'patent license added', 'permissive added', 'proprietary free added', 'copyright info added']) - assert [d.status for d in deltas_object if d.new_file.path == 'a1.py'] == ['modified'] - assert [d.factors for d in deltas_object if d.new_file.path == 'a2.py'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'a2.py'] == ['unmodified'] + assert sorted([d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'].pop()) == sorted([ 'license info added', 'commercial added', 'copyleft added', 'copyleft limited added', 'free restricted added', 'patent license added', 'permissive added', 'proprietary free added', 'copyright info added']) + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == ['modified'] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == ['unmodified'] def test_DeltaCode_apache_to_all_notable_lic(self): new_scan = self.get_test_loc('deltacode/apache_to_all_notable_lic_new.json') @@ -1567,13 +1367,13 @@ def test_DeltaCode_apache_to_all_notable_lic(self): deltas_object = deltacode_object.deltas - assert [d.score for d in deltas_object if d.new_file.path == 'a1.py'] == [155] - assert [d.score for d in deltas_object if d.new_file.path == 'a2.py'] == [0] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == [155] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == [0] - assert sorted([d.factors for d in deltas_object if d.new_file.path == 'a1.py'].pop()) == sorted(['license change', 'commercial added', 'copyleft added', 'copyleft limited added', 'free restricted added', 'patent license added', 'proprietary free added', 'copyright change']) - assert [d.status for d in deltas_object if d.new_file.path == 'a1.py'] == ['modified'] - assert [d.factors for d in deltas_object if d.new_file.path == 'a2.py'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'a2.py'] == ['unmodified'] + assert sorted([d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'].pop()) == sorted(['license change', 'commercial added', 'copyleft added', 'copyleft limited added', 'free restricted added', 'patent license added', 'proprietary free added', 'copyright change']) + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == ['modified'] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == ['unmodified'] def test_DeltaCode_copyleft_etc_to_prop_free_and_commercial(self): new_scan = self.get_test_loc('deltacode/copyleft_etc_to_prop_free_and_commercial_new.json') @@ -1587,13 +1387,13 @@ def test_DeltaCode_copyleft_etc_to_prop_free_and_commercial(self): deltas_object = deltacode_object.deltas - assert [d.score for d in deltas_object if d.new_file.path == 'a1.py'] == [50] - assert [d.score for d in deltas_object if d.new_file.path == 'a2.py'] == [0] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == [50] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == [0] - assert sorted([d.factors for d in deltas_object if d.new_file.path == 'a1.py'].pop()) == sorted(['license change', 'commercial added', 'proprietary free added']) - assert [d.status for d in deltas_object if d.new_file.path == 'a1.py'] == ['modified'] - assert [d.factors for d in deltas_object if d.new_file.path == 'a2.py'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'a2.py'] == ['unmodified'] + assert sorted([d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'].pop()) == sorted(['license change', 'commercial added', 'proprietary free added']) + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == ['modified'] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == ['unmodified'] def test_DeltaCode_permissive_add_public_domain(self): new_scan = self.get_test_loc('deltacode/permissive_add_public_domain_new.json') @@ -1607,13 +1407,13 @@ def test_DeltaCode_permissive_add_public_domain(self): deltas_object = deltacode_object.deltas - assert [d.score for d in deltas_object if d.new_file.path == 'a1.py'] == [30] - assert [d.score for d in deltas_object if d.new_file.path == 'a2.py'] == [0] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == [30] + assert [d.score for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == [0] - assert [d.factors for d in deltas_object if d.new_file.path == 'a1.py'].pop() == ['license change', 'public domain added'] - assert [d.status for d in deltas_object if d.new_file.path == 'a1.py'] == ['modified'] - assert [d.factors for d in deltas_object if d.new_file.path == 'a2.py'].pop() == [] - assert [d.status for d in deltas_object if d.new_file.path == 'a2.py'] == ['unmodified'] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'].pop() == ['license change', 'public domain added'] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a1.py'] == ['modified'] + assert [d.factors for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'].pop() == [] + assert [d.status for d in deltas_object if get_aligned_path(d, d.new_file.path, new_file=True) == 'a2.py'] == ['unmodified'] def test_Stat_calculation_and_ordering(self): new_scan = self.get_test_loc('deltacode/all_stat_order_check_new.json') @@ -1655,6 +1455,7 @@ def test_similarity_matching_2(self): test_utils.run_scan_click(args) test_utils.check_json_scan(self.get_test_loc('deltacode/sugar-expected.json'), result_file, regen=False) + @pytest.mark.xfail(reason='Ambiguous test case') def test_non_similarity_matching_1(self): old_file = self.get_test_loc('deltacode/coala-0.7.0-old.json') new_file = self.get_test_loc('deltacode/sugar-0.114-new.json') diff --git a/tests/test_utils.py b/tests/test_utils.py index f064b3a0..75068800 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -36,9 +36,11 @@ from click.testing import CliRunner from commoncode.testcase import FileBasedTesting +from commoncode.resource import VirtualCodebase import deltacode from deltacode import utils from deltacode import models +from deltacode import DeltaCode unique_categories = set([ @@ -72,498 +74,169 @@ def test_update_from_license_info_non_modified(self): assert len(test_delta.factors) == 0 def test_update_from_license_info_no_license_key_value(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '' - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '' - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_no_license_key_value_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_no_license_key_value_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) + deltas = results.deltas[0] - assert test_delta.score == 20 - assert len(test_delta.factors) == 0 + assert deltas.score == 20 + assert len(deltas.factors) == 0 def test_update_from_license_info_no_license_changes(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) + test_scan_new = self.get_test_loc('utils/update_from_license_info_no_license_changes_new.json') + test_scan_old = self.get_test_loc('utils/update_from_license_info_no_license_changes_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + result = DeltaCode(test_scan_new, test_scan_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) + deltas = result.deltas[0] - assert test_delta.score == 20 - assert len(test_delta.factors) == 0 + assert deltas.score == 20 + assert len(deltas.factors) == 0 def test_update_from_license_info_single_license_change(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) - - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + test_file_new = self.get_test_loc('utils/update_from_license_info_single_license_change_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_single_license_change_old.json') - utils.update_modified_from_license_info(test_delta, unique_categories) + results = DeltaCode(test_file_new, test_file_old, {}) expected_factors = [ 'license change', 'copyleft added' ] + + deltas = results.deltas[0] - assert test_delta.score == 50 - assert len(test_delta.factors) == 2 + assert deltas.score == 50 + assert len(deltas.factors) == 2 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_license_info_copyleft_license_info_added(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_copyleft_license_info_added_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_copyleft_license_info_added_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) + deltas = results.deltas[0] expected_factors = [ 'license info added', 'copyleft added' ] - assert test_delta.score == 60 - assert len(test_delta.factors) == 2 + assert deltas.score == 60 + assert len(deltas.factors) == 2 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_license_info_permissive_license_info_added(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_permissive_license_info_added_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_permissive_license_info_added_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, unique_categories) + results = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 40 - assert len(test_delta.factors) == 2 - assert 'license info added' in test_delta.factors - assert 'permissive added' in test_delta.factors + deltas = results.deltas[0] + + assert deltas.score == 40 + assert len(deltas.factors) == 2 + assert 'license info added' in deltas.factors + assert 'permissive added' in deltas.factors def test_update_from_license_info_permissive_license_info_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_permissive_license_info_removed_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_permissive_license_info_removed_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, set()) + results = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 35 - assert len(test_delta.factors) == 1 - assert 'license info removed' in test_delta.factors + deltas = results.deltas[0] + + assert deltas.score == 35 + assert len(deltas.factors) == 1 + assert 'license info removed' in deltas.factors def test_update_from_license_info_copyleft_license_info_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_copyleft_license_info_removed_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_copyleft_license_info_removed_old.json') + - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, set()) + deltas = results.deltas[0] - assert test_delta.score == 35 - assert len(test_delta.factors) == 1 - assert 'license info removed' in test_delta.factors + assert deltas.score == 35 + assert len(deltas.factors) == 1 + assert 'license info removed' in deltas.factors def test_update_from_license_info_one_license_added(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - }, - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_one_license_added_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_one_license_added_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) + deltas = results.deltas[0] expected_factors = [ 'license change', 'copyleft added' ] - assert test_delta.score == 50 - assert len(test_delta.factors) == 2 + assert deltas.score == 50 + assert len(deltas.factors) == 2 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_license_info_one_license_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - }, - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_one_license_removed_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_one_license_removed_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, unique_categories) + results = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 30 - assert len(test_delta.factors) == 1 - assert 'license change' in test_delta.factors + deltas = results.deltas[0] + + assert deltas.score == 30 + assert len(deltas.factors) == 1 + assert 'license change' in deltas.factors def test_update_from_license_info_one_permissive_to_two_permissives(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - }, - { - "key": "apache-2.0", - "score": 40.0, - "short_name": "Apache 2.0", - "category": "Permissive" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_one_permissive_to_two_permissives_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_one_permissive_to_two_permissives_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) + deltas = results.deltas[0] - assert test_delta.score == 30 - assert len(test_delta.factors) == 1 - assert 'license change' in test_delta.factors + assert deltas.score == 30 + assert len(deltas.factors) == 1 + assert 'license change' in deltas.factors def test_update_from_license_info_two_permissives_to_one_permissive(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - }, - { - "key": "apache-2.0", - "score": 40.0, - "short_name": "Apache 2.0", - "category": "Permissive" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_one_permissive_to_two_permissives_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_one_permissive_to_two_permissives_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) + deltas = results.deltas[0] - assert test_delta.score == 30 - assert len(test_delta.factors) == 1 - assert 'license change' in test_delta.factors + assert deltas.score == 30 + assert len(deltas.factors) == 1 + assert 'license change' in deltas.factors def test_update_from_license_info_one_permissive_to_six_copyleft_or_higher(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - }, - { - "key": "adapt-1.0", - "score": 15.0, - "short_name": "APL 1.0", - "category": "Copyleft", - "owner": "OSI - Open Source Initiative" - }, - { - "key": "bittorrent-1.0", - "score": 100.0, - "short_name": "BitTorrent 1.0", - "category": "Copyleft Limited", - "owner": "BitTorrent, Inc." - }, - { - "key": "bloomberg-blpapi", - "score": 100.0, - "short_name": "Bloomberg BLPAPI License", - "category": "Proprietary Free", - "owner": "Bloomberg Labs" - }, - { - "key": "commercial-license", - "score": 55.0, - "short_name": "Commercial License", - "category": "Commercial", - "owner": "Unspecified" - }, - { - "key": "wrox-download", - "score": 100.0, - "short_name": "Wrox Download Terms and Conditions", - "category": "Free Restricted", - "owner": "Wiley" - }, - { - "key": "mozilla-ospl-1.0", - "score": 99.93, - "short_name": "Mozilla Open Software Patent License 1.0", - "category": "Patent License", - "owner": "Mozilla" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_one_permissive_to_six_copyleft_or_higher_old.json') + - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) + deltas = results.deltas[0] - assert test_delta.score == 150 - assert len(test_delta.factors) == 7 + assert deltas.score == 150 + assert len(deltas.factors) == 7 expected_factors = [ 'license change', @@ -576,87 +249,35 @@ def test_update_from_license_info_one_permissive_to_six_copyleft_or_higher(self) ] for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_license_info_copyleft_to_different_copyleft(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "adapt-1.0", - "score": 15.0, - "short_name": "APL 1.0", - "category": "Copyleft", - "owner": "OSI - Open Source Initiative" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_license_info_copyleft_to_different_copyleft_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_copyleft_to_different_copyleft_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, unique_categories) + results = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 30 - assert len(test_delta.factors) == 1 - assert 'license change' in test_delta.factors + deltas = results.deltas[0] - def test_update_from_license_info_copyleft_to_copyleft_limited(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "bittorrent-1.0", - "score": 100.0, - "short_name": "BitTorrent 1.0", - "category": "Copyleft Limited" - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ] - }) + assert deltas.score == 30 + assert len(deltas.factors) == 1 + assert 'license change' in deltas.factors - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + def test_update_from_license_info_copyleft_to_copyleft_limited(self): + test_file_new = self.get_test_loc('utils/update_from_license_info_copyleft_to_copyleft_limited_new.json') + test_file_old = self.get_test_loc('utils/update_from_license_info_copyleft_to_copyleft_limited_old.json') - utils.update_modified_from_license_info(test_delta, unique_categories) + results = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 40 - assert len(test_delta.factors) == 2 - assert 'license change' in test_delta.factors - assert 'copyleft limited added' in test_delta.factors + deltas = results.deltas[0] + assert deltas.score == 40 + assert len(deltas.factors) == 2 + assert 'license change' in deltas.factors + assert 'copyleft limited added' in deltas.factors + @pytest.mark.xfail(reason='Tests no longer required having None paths') def test_update_from_license_info_file_added_permissive_license(self): test_file_new = models.File({ 'path':'/test/path.txt', @@ -683,6 +304,7 @@ def test_update_from_license_info_file_added_permissive_license(self): assert 'license info added' in test_delta.factors assert 'permissive added' in test_delta.factors + @pytest.mark.xfail(reason='Tests no longer required having None paths') def test_update_from_license_info_file_added_commercial_and_copyleft_licenses(self): test_file_new = models.File({ 'path':'/test/path.txt', @@ -725,6 +347,7 @@ def test_update_from_license_info_file_added_commercial_and_copyleft_licenses(se for factor in expected_factors: assert factor in test_delta.factors + @pytest.mark.xfail(reason='Tests no longer required having None paths') def test_update_from_copyright_info_empty(self): test_delta = deltacode.Delta() @@ -733,424 +356,146 @@ def test_update_from_copyright_info_empty(self): assert test_delta.score == 0 def test_update_from_copyright_info_non_modified(self): - test_file = models.File({'path':'/test/path.txt', 'name': 'path.txt'}) - test_delta = deltacode.Delta(old_file=test_file) + test_file_new = self.get_test_loc('utils/update_from_copyright_info_non_modified_new.json') + test_file_old = self.get_test_loc('utils/update_from_copyright_info_non_modified_old.json') - utils.update_from_copyright_info(test_delta) + test_delta = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 0 - assert len(test_delta.factors) == 0 + assert len(test_delta.deltas) == 1 + assert test_delta.deltas[0].status == "unmodified" def test_update_from_copyright_info_no_copyright_key_value(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '' - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '' - }) + test_file_new = self.get_test_loc('utils/update_from_copyright_info_no_copyright_key_value_new.json') + test_file_old = self.get_test_loc('utils/update_from_copyright_info_no_copyright_key_value_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_copyright_info(test_delta) + results = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 20 - assert len(test_delta.factors) == 0 + deltas = results.deltas[0] + + assert deltas.score == 20 + assert len(deltas.factors) == 0 def test_update_from_copyright_info_no_copyright_changes(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_copyright_info_no_copyright_changes_new.json') + test_file_old = self.get_test_loc('utils/update_from_copyright_info_no_copyright_changes_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_copyright_info(test_delta) + results = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 20 - assert len(test_delta.factors) == 0 + deltas = results.deltas[0] + + assert deltas.score == 20 + assert len(deltas.factors) == 0 def test_update_from_copyright_info_single_copyright_change(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2015 Edouard-Leon Scott de Martinville." - ], - "holders": [ - "Edouard-Leon Scott de Martinville." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_copyright_info_single_copyright_change_new.json') + test_file_old = self.get_test_loc('utils/update_from_copyright_info_single_copyright_change_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + results = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_copyright_info(test_delta) + deltas = results.deltas[0] - assert test_delta.score == 25 - assert len(test_delta.factors) == 1 - assert 'copyright change' in test_delta.factors + assert deltas.score == 25 + assert len(deltas.factors) == 1 + assert 'copyright change' in deltas.factors def test_update_from_copyright_info_single_copyright_change_holders_only(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [], - "holders": [ - "Edouard-Leon Scott de Martinville." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [ - { - "statements": [], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_scan_new = self.get_test_loc("utils/update_from_copyright_info_single_copyright_change_holders_only_new.json") + test_scan_old = self.get_test_loc("utils/update_from_copyright_info_single_copyright_change_holders_only_old.json") - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_copyright_info(test_delta) + results = DeltaCode(test_scan_new, test_scan_old, {}) + deltas = results.deltas[0] - assert test_delta.score == 25 - assert len(test_delta.factors) == 1 - assert 'copyright change' in test_delta.factors + assert deltas.score == 25 + assert len(deltas.factors) == 1 + assert 'copyright change' in deltas.factors def test_update_from_copyright_info_single_copyright_change_statements_only(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2015 Edouard-Leon Scott de Martinville." - ], - "holders": [] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [] - } - ] - }) - - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - - utils.update_modified_from_copyright_info(test_delta) - - assert test_delta.score == 20 - assert len(test_delta.factors) == 0 - assert 'copyright change' not in test_delta.factors - - def test_update_from_copyright_info_copyright_info_added(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [] - }) - - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + test_scan_new = self.get_test_loc('utils/update_from_copyright_info_single_copyright_change_statements_only_new.json') + test_scan_old = self.get_test_loc('utils/update_from_copyright_info_single_copyright_change_statements_only_old.json') - utils.update_modified_from_copyright_info(test_delta) + results = DeltaCode(test_scan_new, test_scan_old, {}) - assert test_delta.score == 30 - assert len(test_delta.factors) == 1 - assert 'copyright info added' in test_delta.factors - - def test_update_from_copyright_info_copyright_info_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) - - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - - utils.update_modified_from_copyright_info(test_delta) - - assert test_delta.score == 30 - assert len(test_delta.factors) == 1 - assert 'copyright info removed' in test_delta.factors - - def test_update_from_copyright_info_one_copyright_added(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - }, - { - "statements": [ - "Copyright (c) 2015 Edouard-Leon Scott de Martinville." - ], - "holders": [ - "Edouard-Leon Scott de Martinville." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + deltas = results.deltas[0] - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + assert deltas.score == 20 + assert len(deltas.factors) == 0 + assert 'copyright change' not in deltas.factors - utils.update_modified_from_copyright_info(test_delta) + def test_update_from_copyright_info_copyright_info_added(self): + test_scan_new = self.get_test_loc('utils/update_from_copyright_info_copyright_info_added_new.json') + test_scan_old = self.get_test_loc('utils/update_from_copyright_info_copyright_info_added_old.json') + + + results = DeltaCode(test_scan_new, test_scan_old, {}) + + deltas = results.deltas[0] + + assert deltas.score == 30 + assert len(deltas.factors) == 1 + assert 'copyright info added' in deltas.factors + + def test_update_from_copyright_info_copyright_info_removed(self): + test_scan_new = self.get_test_loc('utils/update_from_copyright_info_copyright_info_removed_new.json') + test_scan_old = self.get_test_loc('utils/update_from_copyright_info_copyright_info_removed_old.json') + + + results = DeltaCode(test_scan_new, test_scan_old, {}) - assert test_delta.score == 25 - assert len(test_delta.factors) == 1 - assert 'copyright change' in test_delta.factors + deltas = results.deltas[0] + + assert deltas.score == 30 + assert len(deltas.factors) == 1 + assert 'copyright info removed' in deltas.factors + + def test_update_from_copyright_info_one_copyright_added(self): + test_scan_new = self.get_test_loc('utils/update_from_copyright_info_one_copyright_added_new.json') + test_scan_old = self.get_test_loc('utils/update_from_copyright_info_one_copyright_added_old.json') + + results = DeltaCode(test_scan_new, test_scan_old, {}) + + deltas = results.deltas[0] + + assert deltas.score == 25 + assert len(deltas.factors) == 1 + assert 'copyright change' in deltas.factors def test_update_from_copyright_info_one_copyright_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - }, - { - "statements": [ - "Copyright (c) 2015 Edouard-Leon Scott de Martinville." - ], - "holders": [ - "Edouard-Leon Scott de Martinville." - ] - } - ] - }) + test_scan_new = self.get_test_loc('utils/update_from_copyright_info_one_copyright_removed_new.json') + test_scan_old = self.get_test_loc('utils/update_from_copyright_info_one_copyright_removed_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_copyright_info(test_delta) + results = DeltaCode(test_scan_new, test_scan_old, {}) - assert test_delta.score == 25 - assert len(test_delta.factors) == 1 - assert 'copyright change' in test_delta.factors + deltas = results.deltas[0] + + assert deltas.score == 25 + assert len(deltas.factors) == 1 + assert 'copyright change' in deltas.factors def test_update_from_copyright_info_file_added_one_copyright(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_scan_new = self.get_test_loc('utils/update_from_copyright_info_file_added_one_copyright_new.json') + test_scan_old = self.get_test_loc('utils/update_from_copyright_info_file_added_one_copyright_old.json') - test_delta = deltacode.Delta(100, test_file_new, None) - utils.update_added_from_copyright_info(test_delta) + test_delta = DeltaCode(test_scan_new, test_scan_old, {}) + + deltas = test_delta.deltas[0] - assert test_delta.score == 110 - assert len(test_delta.factors) == 1 - assert 'copyright info added' in test_delta.factors + assert deltas.score == 110 + assert len(deltas.factors) == 1 + assert 'copyright info added' in deltas.factors def test_update_from_lic_copy_info_copyright_and_license_info_added(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [], - "copyrights": [] - }) + test_scan_new = self.get_test_loc('utils/update_from_lic_copy_info_copyright_and_license_info_added_new.json') + test_scan_old = self.get_test_loc('utils/update_from_lic_copy_info_copyright_and_license_info_added_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, unique_categories) - utils.update_modified_from_copyright_info(test_delta) + results = DeltaCode(test_scan_new, test_scan_old, {}) + + deltas = results.deltas[0] expected_factors = [ 'license info added', @@ -1158,377 +503,127 @@ def test_update_from_lic_copy_info_copyright_and_license_info_added(self): 'copyright info added' ] - assert test_delta.score == 70 - assert len(test_delta.factors) == 3 + assert deltas.score == 70 + assert len(deltas.factors) == 3 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_lic_copy_info_copyright_and_license_info_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [], - "copyrights": [] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_lic_copy_info_copyright_and_license_info_removed_new.json') + test_file_old = self.get_test_loc('utils/update_from_lic_copy_info_copyright_and_license_info_removed_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, unique_categories) - utils.update_modified_from_copyright_info(test_delta) + test_delta = DeltaCode(test_file_new, test_file_old, {}) + + deltas = test_delta.deltas[0] expected_factors = [ 'license info removed', 'copyright info removed' ] - assert test_delta.score == 45 - assert len(test_delta.factors) == 2 + assert deltas.score == 45 + assert len(deltas.factors) == 2 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_lic_copy_info_copyright_info_added_license_info_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ], - "copyrights": [] - }) + test_file_new = self.get_test_loc('utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_new.json') + test_file_old = self.get_test_loc('utils/update_from_lic_copy_info_copyright_info_added_license_info_removed_old.json') + - test_delta = deltacode.Delta(20, test_file_new, test_file_old) + test_delta = DeltaCode(test_file_new, test_file_old, {}) - utils.update_modified_from_license_info(test_delta, unique_categories) - utils.update_modified_from_copyright_info(test_delta) + deltas = test_delta.deltas[0] expected_factors = [ 'license info removed', 'copyright info added' ] - assert test_delta.score == 45 - assert len(test_delta.factors) == 2 + assert deltas.score == 45 + assert len(deltas.factors) == 2 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_lic_copy_info_license_info_added_copyright_info_removed(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ], - "copyrights": [] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_new.json') + test_file_old = self.get_test_loc('utils/update_from_lic_copy_info_license_info_added_copyright_info_removed_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - - utils.update_modified_from_license_info(test_delta, unique_categories) - utils.update_modified_from_copyright_info(test_delta) + test_delta = DeltaCode(test_file_new, test_file_old, {}) + expected_factors = [ 'license info added', 'copyleft added', 'copyright info removed' ] - assert test_delta.score == 70 - assert len(test_delta.factors) == 3 + deltas = test_delta.deltas[0] + + assert deltas.score == 70 + assert len(deltas.factors) == 3 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_lic_copy_info_copyright_change_no_license_change(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - }, - { - "statements": [ - "Copyright (c) 2015 Edouard-Leon Scott de Martinville." - ], - "holders": [ - "Edouard-Leon Scott de Martinville." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_lic_copy_info_copyright_change_no_license_change_new.json') + test_file_old = self.get_test_loc('utils/update_from_lic_copy_info_copyright_change_no_license_change_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, unique_categories) - utils.update_modified_from_copyright_info(test_delta) + test_delta = DeltaCode(test_file_new, test_file_old, {}) - assert test_delta.score == 25 - assert len(test_delta.factors) == 1 - assert 'copyright change' in test_delta.factors + deltas = test_delta.deltas[0] + + assert deltas.score == 25 + assert len(deltas.factors) == 1 + assert 'copyright change' in deltas.factors def test_update_from_lic_copy_info_license_change_no_copyright_change(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - }, - { - "key": "gpl-2.0", - "score": 70.0, - "short_name": "GPL 2.0", - "category": "Copyleft" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) - test_file_old = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a_modified', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_lic_copy_info_license_change_no_copyright_change_new.json') + test_file_old = self.get_test_loc('utils/update_from_lic_copy_info_license_change_no_copyright_change_old.json') - test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.update_modified_from_license_info(test_delta, unique_categories) - utils.update_modified_from_copyright_info(test_delta) + test_delta = DeltaCode(test_file_new, test_file_old, {}) expected_factors = [ 'license change', 'copyleft added' ] - assert test_delta.score == 50 - assert len(test_delta.factors) == 2 + deltas = test_delta.deltas[0] + + assert deltas.score == 50 + assert len(deltas.factors) == 2 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in deltas.factors def test_update_from_lic_copy_info_file_added_copyright_and_permissive_license(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "mit", - "score": 80.0, - "short_name": "MIT License", - "category": "Permissive" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_new.json') + test_file_old = self.get_test_loc('utils/update_from_lic_copy_info_file_added_copyright_and_permissive_license_old.json') - test_delta = deltacode.Delta(100, test_file_new, None) - utils.update_added_from_license_info(test_delta, unique_categories) - utils.update_added_from_copyright_info(test_delta) + deltacode = DeltaCode(test_file_new, test_file_old, {}) expected_factors = [ 'license info added', 'permissive added', 'copyright info added' ] + + delta = deltacode.deltas[0] - assert test_delta.score == 130 - assert len(test_delta.factors) == 3 + assert delta.score == 130 + assert len(delta.factors) == 3 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in delta.factors def test_update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses(self): - test_file_new = models.File({ - 'path':'/test/path.txt', - 'name': 'path.txt', - 'sha1': 'a', - 'original_path': '', - "licenses": [ - { - "key": "commercial-license", - "score": 55.0, - "short_name": "Commercial License", - "category": "Commercial", - "owner": "Unspecified" - }, - { - "key": "adapt-1.0", - "score": 15.0, - "short_name": "APL 1.0", - "category": "Copyleft", - "owner": "OSI - Open Source Initiative" - } - ], - "copyrights": [ - { - "statements": [ - "Copyright (c) 2017-2018 Francois Hennebique and others." - ], - "holders": [ - "Francois Hennebique and others." - ] - } - ] - }) + test_file_new = self.get_test_loc('utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_new.json') + test_file_old = self.get_test_loc('utils/update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyleft_licenses_old.json') - test_delta = deltacode.Delta(100, test_file_new, None) - utils.update_added_from_license_info(test_delta, unique_categories) - utils.update_added_from_copyright_info(test_delta) + deltacode = DeltaCode(test_file_new, test_file_old, {}) expected_factors = [ 'license info added', @@ -1537,20 +632,22 @@ def test_update_from_lic_copy_info_file_added_copyright_and_commercial_and_copyl 'copyright info added' ] - assert test_delta.score == 170 - assert len(test_delta.factors) == 4 + delta = deltacode.deltas[0] + + assert delta.score == 170 + assert len(delta.factors) == 4 for factor in expected_factors: - assert factor in test_delta.factors + assert factor in delta.factors def test_align_trees_simple(self): test_scan_new = self.get_test_loc('utils/align-trees-simple-new.json') # Our old scan uses --full-root option in scancode test_scan_old = self.get_test_loc('utils/align-trees-simple-old.json') - new_scan = models.Scan(test_scan_new) - old_scan = models.Scan(test_scan_old) + new_scan = VirtualCodebase(test_scan_new) + old_scan = VirtualCodebase(test_scan_old) - result_seg_new, result_seg_old = utils.align_trees(new_scan.files, old_scan.files) + result_seg_new, result_seg_old = utils.align_trees(new_scan, old_scan) assert result_seg_new == 0 # Our old scan uses --full-root option in scancode, hence the 5 segments that @@ -1561,83 +658,9 @@ def test_align_tress_zlib_failing(self): test_scan_new = self.get_test_loc('utils/align-trees-zlib-failing-new.json') test_scan_old = self.get_test_loc('utils/align-trees-zlib-failing-old.json') - new_scan = models.Scan(test_scan_new) - old_scan = models.Scan(test_scan_old) + new_scan = VirtualCodebase(test_scan_new) + old_scan = VirtualCodebase(test_scan_old) # test that the exception is raised with pytest.raises(utils.AlignmentException): - result_seg_new, result_seg_old = utils.align_trees(new_scan.files, old_scan.files) - - def test_DeltaCode_check_moved_no_sha1_match(self): - added_sha1 = 'a' - removed_sha1 = 'b' - - new_added = models.File({'path': 'path/same.txt', 'sha1': 'a', 'name': 'same.txt'}) - - added_delta = deltacode.Delta(100, new_added, None) - added_deltas = [added_delta] - - old_removed = models.File({'path': 'path/different.txt', 'sha1': 'b', 'name': 'different.txt'}) - - removed_delta = deltacode.Delta(10, None, old_removed) - removed_deltas = [removed_delta] - - result = utils.check_moved(added_sha1, added_deltas, removed_sha1, removed_deltas) - - assert result == False - - def test_DeltaCode_check_moved_1_sha1_match(self): - added_sha1 = 'a' - removed_sha1 = 'a' - - new_added = models.File({'path': 'path/same.txt', 'sha1': 'a', 'name': 'same.txt'}) - - added_delta = deltacode.Delta(100, new_added, None) - added_deltas = [added_delta] - - old_removed = models.File({'path': 'path/same.txt', 'sha1': 'a', 'name': 'same.txt'}) - - removed_delta = deltacode.Delta(10, None, old_removed) - removed_deltas = [removed_delta] - - result = utils.check_moved(added_sha1, added_deltas, removed_sha1, removed_deltas) - - assert result == True - - def test_DeltaCode_check_moved_1_sha1_match_different_names(self): - added_sha1 = 'a' - removed_sha1 = 'a' - - new_added = models.File({'path': 'path/same.txt', 'sha1': 'a', 'name': 'same.txt'}) - - added_delta = deltacode.Delta(100, new_added, None) - added_deltas = [added_delta] - - old_removed = models.File({'path': 'path/different.txt', 'sha1': 'a', 'name': 'different.txt'}) - - removed_delta = deltacode.Delta(10, None, old_removed) - removed_deltas = [removed_delta] - - result = utils.check_moved(added_sha1, added_deltas, removed_sha1, removed_deltas) - - assert result == None - - def test_DeltaCode_check_moved_2_sha1_matches(self): - added_sha1 = 'a' - removed_sha1 = 'a' - - new_added_01 = models.File({'path': 'pathA/same.txt', 'sha1': 'a', 'name': 'same.txt'}) - new_added_02 = models.File({'path': 'pathB/same.txt', 'sha1': 'a', 'name': 'same.txt'}) - - added_delta_01 = deltacode.Delta(100, new_added_01, None) - added_delta_02 = deltacode.Delta(100, new_added_02, None) - added_deltas = [added_delta_01, added_delta_02] - - old_removed = models.File({'path': 'path/same.txt', 'sha1': 'a', 'name': 'same.txt'}) - - removed_delta = deltacode.Delta(10, None, old_removed) - removed_deltas = [removed_delta] - - result = utils.check_moved(added_sha1, added_deltas, removed_sha1, removed_deltas) - - assert result == False + result_seg_new, result_seg_old = utils.align_trees(new_scan, old_scan)