From 76b88dc685934978809ddf67a56fc30bc4290a71 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Wed, 28 Mar 2018 13:15:12 -0700 Subject: [PATCH 1/2] Add license/copyright score for 'added' files #84 Signed-off-by: John M. Horan --- src/deltacode/__init__.py | 7 + src/deltacode/utils.py | 31 +++- tests/data/cli/1_file_moved_and_1_copy.csv | 4 +- tests/data/cli/1_file_moved_and_added.csv | 4 +- tests/data/cli/added1.csv | 2 +- tests/data/cli/renamed1.csv | 2 +- tests/test_deltacode.py | 2 +- tests/test_utils.py | 185 +++++++++++++++++++++ 8 files changed, 223 insertions(+), 14 deletions(-) diff --git a/src/deltacode/__init__.py b/src/deltacode/__init__.py index ace13ac9..b7853914 100644 --- a/src/deltacode/__init__.py +++ b/src/deltacode/__init__.py @@ -282,6 +282,13 @@ def is_unmodified(self): self.old_file.path == self.new_file.path): return True + def is_added(self): + """ + Identify a Delta object reflecting the addition of a File. + """ + if not self.old_file and self.new_file: + return True + def to_dict(self): """ Return an OrderedDict comprising the 'factors', 'score' and new and old diff --git a/src/deltacode/utils.py b/src/deltacode/utils.py index 6a1ca9c9..46865df7 100644 --- a/src/deltacode/utils.py +++ b/src/deltacode/utils.py @@ -35,10 +35,22 @@ def determine_license_diff(delta, unique_categories): """ - Increase the Delta object's 'score' attribute and add one or more - appropriate categories to its 'factors' attribute if there has been a - license change and depending on the nature of that change. - """ + Increase an 'added' or 'modified' Delta object's 'score' attribute and add + one or more appropriate categories to its 'factors' attribute if there has + been a license change and depending on the nature of that change. + """ + if delta.is_added(): + 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') + # no license ==> 'Copyleft Limited'or higher + for category in new_categories: + if category in unique_categories: + delta.update(20, category.lower() + ' added') + return + if not delta.is_modified(): return @@ -73,10 +85,15 @@ def determine_license_diff(delta, unique_categories): def determine_copyright_diff(delta): """ - Increase the Delta object's 'score' attribute and add one or more - appropriate categories to its 'factors' attribute if there has been a - copyright change and depending on the nature of that change. + Increase an 'added' or 'modified' Delta object's 'score' attribute and add + one or more appropriate categories to its 'factors' attribute if there has + been a copyright change and depending on the nature of that change. """ + if delta.is_added(): + if delta.new_file.has_copyrights(): + delta.update(10, 'copyright info added') + return + if not delta.is_modified(): return diff --git a/tests/data/cli/1_file_moved_and_1_copy.csv b/tests/data/cli/1_file_moved_and_1_copy.csv index 8a1a0bc3..9ca41fb2 100644 --- a/tests/data/cli/1_file_moved_and_1_copy.csv +++ b/tests/data/cli/1_file_moved_and_1_copy.csv @@ -1,4 +1,4 @@ Factors,Score,Path,Name,Type,Size,Old Path -added,100,b/a4.py,a4.py,file,200, -added,100,b/a4_copy.py,a4_copy.py,file,200, +added license info added copyright info added,130,b/a4.py,a4.py,file,200, +added license info added copyright info added,130,b/a4_copy.py,a4_copy.py,file,200, removed,0,a/a4.py,a4.py,file,200, diff --git a/tests/data/cli/1_file_moved_and_added.csv b/tests/data/cli/1_file_moved_and_added.csv index fd41309b..2951022c 100644 --- a/tests/data/cli/1_file_moved_and_added.csv +++ b/tests/data/cli/1_file_moved_and_added.csv @@ -1,4 +1,4 @@ Factors,Score,Path,Name,Type,Size,Old Path -added,100,b/a4.py,a4.py,file,200, -added,100,c/a4.py,a4.py,file,200, +added license info added copyright info added,130,b/a4.py,a4.py,file,200, +added license info added copyright info added,130,c/a4.py,a4.py,file,200, removed,0,a/a4.py,a4.py,file,200, diff --git a/tests/data/cli/added1.csv b/tests/data/cli/added1.csv index 5c07a03e..2c52ee55 100644 --- a/tests/data/cli/added1.csv +++ b/tests/data/cli/added1.csv @@ -1,2 +1,2 @@ Factors,Score,Path,Name,Type,Size,Old Path -added,100,a/a5.py,a5.py,file,200, +added license info added copyright info added,130,a/a5.py,a5.py,file,200, diff --git a/tests/data/cli/renamed1.csv b/tests/data/cli/renamed1.csv index 568c858e..8446a115 100644 --- a/tests/data/cli/renamed1.csv +++ b/tests/data/cli/renamed1.csv @@ -1,3 +1,3 @@ Factors,Score,Path,Name,Type,Size,Old Path -added,100,a/a4_renamed_not_modified.py,a4_renamed_not_modified.py,file,200, +added license info added copyright info added,130,a/a4_renamed_not_modified.py,a4_renamed_not_modified.py,file,200, removed,0,a/a4.py,a4.py,file,200, diff --git a/tests/test_deltacode.py b/tests/test_deltacode.py index 70169aa4..1a7e5787 100644 --- a/tests/test_deltacode.py +++ b/tests/test_deltacode.py @@ -1463,7 +1463,7 @@ def test_DeltaCode_sort_order(self): deltas_object = deltacode_object.deltas expected = [ - ['added'], + ['added', 'license info added', 'copyright info added'], ['modified'], ['moved'], ['removed'], diff --git a/tests/test_utils.py b/tests/test_utils.py index 73e9b68a..e77d1fab 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -654,6 +654,73 @@ def test_determine_license_diff_copyleft_to_copyleft_limited(self): assert len(test_delta.factors) == 1 assert 'license change' in test_delta.factors + def test_determine_license_diff_file_added_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" + } + ] + }) + + test_delta = deltacode.Delta(100, test_file_new, None) + + utils.determine_license_diff(test_delta, unique_categories) + + assert test_delta.score == 120 + assert len(test_delta.factors) == 1 + + assert 'license info added' in test_delta.factors + + def test_determine_license_diff_file_added_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" + } + ] + }) + + test_delta = deltacode.Delta(100, test_file_new, None) + + utils.determine_license_diff(test_delta, unique_categories) + + assert test_delta.score == 160 + assert len(test_delta.factors) == 3 + + assert 'license info added' in test_delta.factors + + expected_factors = [ + 'license info added', + 'commercial added', + 'copyleft added' + ] + + for factor in expected_factors: + assert factor in test_delta.factors + def test_determine_copyright_diff_empty(self): test_delta = deltacode.Delta() @@ -1016,6 +1083,32 @@ def test_determine_copyright_diff_one_copyright_removed(self): assert len(test_delta.factors) == 1 assert 'copyright change' in test_delta.factors + def test_determine_copyright_diff_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_delta = deltacode.Delta(100, test_file_new, None) + + utils.determine_copyright_diff(test_delta) + + assert test_delta.score == 110 + assert len(test_delta.factors) == 1 + assert 'copyright info added' in test_delta.factors + def test_determine_lic_copy_diffs_copyright_and_license_info_added(self): test_file_new = models.File({ 'path':'/test/path.txt', @@ -1352,6 +1445,98 @@ def test_determine_lic_copy_diffs_license_change_no_copyright_change(self): for factor in expected_factors: assert factor in test_delta.factors + def test_determine_lic_copy_diffs_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_delta = deltacode.Delta(100, test_file_new, None) + + utils.determine_license_diff(test_delta, unique_categories) + utils.determine_copyright_diff(test_delta) + + expected_factors = [ + 'license info added', + 'copyright info added' + ] + + assert test_delta.score == 130 + assert len(test_delta.factors) == 2 + for factor in expected_factors: + assert factor in test_delta.factors + + def test_determine_lic_copy_diffs_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_delta = deltacode.Delta(100, test_file_new, None) + + utils.determine_license_diff(test_delta, unique_categories) + utils.determine_copyright_diff(test_delta) + + expected_factors = [ + 'license info added', + 'commercial added', + 'copyleft added', + 'copyright info added' + ] + + assert test_delta.score == 170 + assert len(test_delta.factors) == 4 + for factor in expected_factors: + assert factor in test_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 From b0dc286a49a30902daa9e6795b283519abe8eba0 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Wed, 28 Mar 2018 17:52:02 -0700 Subject: [PATCH 2/2] Modularize license and copyright diff methods #84 Signed-off-by: John M. Horan --- src/deltacode/__init__.py | 12 +-- src/deltacode/utils.py | 68 +++++++++++---- tests/test_utils.py | 168 +++++++++++++++++++------------------- 3 files changed, 140 insertions(+), 108 deletions(-) diff --git a/src/deltacode/__init__.py b/src/deltacode/__init__.py index b7853914..8a5e49eb 100644 --- a/src/deltacode/__init__.py +++ b/src/deltacode/__init__.py @@ -204,7 +204,7 @@ def license_diff(self): ]) for delta in self.deltas: - utils.determine_license_diff(delta, unique_categories) + utils.update_from_license_info(delta, unique_categories) def copyright_diff(self): """ @@ -215,7 +215,7 @@ def copyright_diff(self): attribute -- if there has been a copyright change. """ for delta in self.deltas: - utils.determine_copyright_diff(delta) + utils.update_from_copyright_info(delta) def index_deltas(self, index_key='path', delta_list=[]): """ @@ -277,16 +277,16 @@ def is_unmodified(self): other than 'unmodified' and return True if all but 'unmodified' are ruled out. """ - if (self.old_file and self.new_file and - self.old_file.sha1 == self.new_file.sha1 and - self.old_file.path == self.new_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): """ Identify a Delta object reflecting the addition of a File. """ - if not self.old_file and self.new_file: + if self.new_file and not self.old_file: return True def to_dict(self): diff --git a/src/deltacode/utils.py b/src/deltacode/utils.py index 46865df7..4774b1e5 100644 --- a/src/deltacode/utils.py +++ b/src/deltacode/utils.py @@ -33,27 +33,43 @@ from commoncode import paths -def determine_license_diff(delta, unique_categories): +def update_from_license_info(delta, unique_categories): """ Increase an 'added' or 'modified' Delta object's 'score' attribute and add one or more appropriate categories to its 'factors' attribute if there has been a license change and depending on the nature of that change. """ if delta.is_added(): - 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') - # no license ==> 'Copyleft Limited'or higher - for category in new_categories: - if category in unique_categories: - delta.update(20, category.lower() + ' added') - return - - if not delta.is_modified(): + update_added_from_license_info(delta, unique_categories) + + if delta.is_modified(): + update_modified_from_license_info(delta, unique_categories) + + +def update_added_from_license_info(delta, unique_categories): + """ + Increase an 'added' Delta object's 'score' attribute and add + 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') + # no license ==> 'Copyleft Limited'or higher + for category in new_categories: + if category in unique_categories: + delta.update(20, category.lower() + ' added') return + +def update_modified_from_license_info(delta, unique_categories): + """ + Increase a 'modified' Delta object's 'score' attribute and add + 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 @@ -83,20 +99,36 @@ def determine_license_diff(delta, unique_categories): delta.update(20, category.lower() + ' added') -def determine_copyright_diff(delta): +def update_from_copyright_info(delta): """ Increase an 'added' or 'modified' Delta object's 'score' attribute and add one or more appropriate categories to its 'factors' attribute if there has been a copyright change and depending on the nature of that change. """ if delta.is_added(): - if delta.new_file.has_copyrights(): - delta.update(10, 'copyright info added') - return + update_added_from_copyright_info(delta) + + if delta.is_modified(): + update_modified_from_copyright_info(delta) + - if not delta.is_modified(): +def update_added_from_copyright_info(delta): + """ + Increase an 'added' Delta object's 'score' attribute and add + 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') return + +def update_modified_from_copyright_info(delta): + """ + Increase a 'modified' Delta object's 'score' attribute and add + 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 [] diff --git a/tests/test_utils.py b/tests/test_utils.py index e77d1fab..dcf2c447 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -55,23 +55,23 @@ class TestUtils(FileBasedTesting): test_data_dir = os.path.join(os.path.dirname(__file__), 'data') - def test_determine_license_diff_empty(self): + def test_update_from_license_info_empty(self): test_delta = deltacode.Delta() - utils.determine_license_diff(test_delta, set()) + utils.update_from_license_info(test_delta, set()) assert test_delta.score == 0 - def test_determine_license_diff_non_modified(self): + def test_update_from_license_info_non_modified(self): test_file = models.File({'path':'/test/path.txt', 'name': 'path.txt'}) test_delta = deltacode.Delta(old_file=test_file) - utils.determine_license_diff(test_delta, set()) + utils.update_from_license_info(test_delta, set()) assert test_delta.score == 0 assert len(test_delta.factors) == 0 - def test_determine_license_diff_no_license_key_value(self): + def test_update_from_license_info_no_license_key_value(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -87,12 +87,12 @@ def test_determine_license_diff_no_license_key_value(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 20 assert len(test_delta.factors) == 0 - def test_determine_license_diff_no_license_changes(self): + def test_update_from_license_info_no_license_changes(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -124,12 +124,12 @@ def test_determine_license_diff_no_license_changes(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 20 assert len(test_delta.factors) == 0 - def test_determine_license_diff_single_license_change(self): + def test_update_from_license_info_single_license_change(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -161,7 +161,7 @@ def test_determine_license_diff_single_license_change(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) expected_factors = [ 'license change', @@ -173,7 +173,7 @@ def test_determine_license_diff_single_license_change(self): for factor in expected_factors: assert factor in test_delta.factors - def test_determine_license_diff_copyleft_license_info_added(self): + def test_update_from_license_info_copyleft_license_info_added(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -198,7 +198,7 @@ def test_determine_license_diff_copyleft_license_info_added(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) expected_factors = [ 'license info added', @@ -210,7 +210,7 @@ def test_determine_license_diff_copyleft_license_info_added(self): for factor in expected_factors: assert factor in test_delta.factors - def test_determine_license_diff_permissive_license_info_added(self): + def test_update_from_license_info_permissive_license_info_added(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -235,13 +235,13 @@ def test_determine_license_diff_permissive_license_info_added(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 40 assert len(test_delta.factors) == 1 assert 'license info added' in test_delta.factors - def test_determine_license_diff_permissive_license_info_removed(self): + def test_update_from_license_info_permissive_license_info_removed(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -266,13 +266,13 @@ def test_determine_license_diff_permissive_license_info_removed(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, set()) + utils.update_modified_from_license_info(test_delta, set()) assert test_delta.score == 35 assert len(test_delta.factors) == 1 assert 'license info removed' in test_delta.factors - def test_determine_license_diff_copyleft_license_info_removed(self): + def test_update_from_license_info_copyleft_license_info_removed(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -297,13 +297,13 @@ def test_determine_license_diff_copyleft_license_info_removed(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, set()) + utils.update_modified_from_license_info(test_delta, set()) assert test_delta.score == 35 assert len(test_delta.factors) == 1 assert 'license info removed' in test_delta.factors - def test_determine_license_diff_one_license_added(self): + def test_update_from_license_info_one_license_added(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -341,7 +341,7 @@ def test_determine_license_diff_one_license_added(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) expected_factors = [ 'license change', @@ -353,7 +353,7 @@ def test_determine_license_diff_one_license_added(self): for factor in expected_factors: assert factor in test_delta.factors - def test_determine_license_diff_one_license_removed(self): + def test_update_from_license_info_one_license_removed(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -391,13 +391,13 @@ def test_determine_license_diff_one_license_removed(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 30 assert len(test_delta.factors) == 1 assert 'license change' in test_delta.factors - def test_determine_license_diff_one_permissive_to_two_permissives(self): + def test_update_from_license_info_one_permissive_to_two_permissives(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -435,13 +435,13 @@ def test_determine_license_diff_one_permissive_to_two_permissives(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 30 assert len(test_delta.factors) == 1 assert 'license change' in test_delta.factors - def test_determine_license_diff_two_permissives_to_one_permissive(self): + def test_update_from_license_info_two_permissives_to_one_permissive(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -479,13 +479,13 @@ def test_determine_license_diff_two_permissives_to_one_permissive(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 30 assert len(test_delta.factors) == 1 assert 'license change' in test_delta.factors - def test_determine_license_diff_one_permissive_to_six_copyleft_or_higher(self): + 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', @@ -559,7 +559,7 @@ def test_determine_license_diff_one_permissive_to_six_copyleft_or_higher(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 150 assert len(test_delta.factors) == 7 @@ -577,7 +577,7 @@ def test_determine_license_diff_one_permissive_to_six_copyleft_or_higher(self): for factor in expected_factors: assert factor in test_delta.factors - def test_determine_license_diff_copyleft_to_different_copyleft(self): + def test_update_from_license_info_copyleft_to_different_copyleft(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -610,13 +610,13 @@ def test_determine_license_diff_copyleft_to_different_copyleft(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 30 assert len(test_delta.factors) == 1 assert 'license change' in test_delta.factors - def test_determine_license_diff_copyleft_to_copyleft_limited(self): + def test_update_from_license_info_copyleft_to_copyleft_limited(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -648,13 +648,13 @@ def test_determine_license_diff_copyleft_to_copyleft_limited(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_modified_from_license_info(test_delta, unique_categories) assert test_delta.score == 30 assert len(test_delta.factors) == 1 assert 'license change' in test_delta.factors - def test_determine_license_diff_file_added_permissive_license(self): + def test_update_from_license_info_file_added_permissive_license(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -672,14 +672,14 @@ def test_determine_license_diff_file_added_permissive_license(self): test_delta = deltacode.Delta(100, test_file_new, None) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_added_from_license_info(test_delta, unique_categories) assert test_delta.score == 120 assert len(test_delta.factors) == 1 assert 'license info added' in test_delta.factors - def test_determine_license_diff_file_added_commercial_and_copyleft_licenses(self): + def test_update_from_license_info_file_added_commercial_and_copyleft_licenses(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -705,7 +705,7 @@ def test_determine_license_diff_file_added_commercial_and_copyleft_licenses(self test_delta = deltacode.Delta(100, test_file_new, None) - utils.determine_license_diff(test_delta, unique_categories) + utils.update_added_from_license_info(test_delta, unique_categories) assert test_delta.score == 160 assert len(test_delta.factors) == 3 @@ -721,23 +721,23 @@ def test_determine_license_diff_file_added_commercial_and_copyleft_licenses(self for factor in expected_factors: assert factor in test_delta.factors - def test_determine_copyright_diff_empty(self): + def test_update_from_copyright_info_empty(self): test_delta = deltacode.Delta() - utils.determine_copyright_diff(test_delta) + utils.update_from_copyright_info(test_delta) assert test_delta.score == 0 - def test_determine_copyright_diff_non_modified(self): + 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) - utils.determine_copyright_diff(test_delta) + utils.update_from_copyright_info(test_delta) assert test_delta.score == 0 assert len(test_delta.factors) == 0 - def test_determine_copyright_diff_no_copyright_key_value(self): + def test_update_from_copyright_info_no_copyright_key_value(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -753,12 +753,12 @@ def test_determine_copyright_diff_no_copyright_key_value(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 20 assert len(test_delta.factors) == 0 - def test_determine_copyright_diff_no_copyright_changes(self): + def test_update_from_copyright_info_no_copyright_changes(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -794,12 +794,12 @@ def test_determine_copyright_diff_no_copyright_changes(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 20 assert len(test_delta.factors) == 0 - def test_determine_copyright_diff_single_copyright_change(self): + def test_update_from_copyright_info_single_copyright_change(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -835,13 +835,13 @@ def test_determine_copyright_diff_single_copyright_change(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 25 assert len(test_delta.factors) == 1 assert 'copyright change' in test_delta.factors - def test_determine_copyright_diff_single_copyright_change_holders_only(self): + def test_update_from_copyright_info_single_copyright_change_holders_only(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -873,13 +873,13 @@ def test_determine_copyright_diff_single_copyright_change_holders_only(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 25 assert len(test_delta.factors) == 1 assert 'copyright change' in test_delta.factors - def test_determine_copyright_diff_single_copyright_change_statements_only(self): + def test_update_from_copyright_info_single_copyright_change_statements_only(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -911,13 +911,13 @@ def test_determine_copyright_diff_single_copyright_change_statements_only(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + 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_determine_copyright_diff_copyright_info_added(self): + def test_update_from_copyright_info_copyright_info_added(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -944,13 +944,13 @@ def test_determine_copyright_diff_copyright_info_added(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 30 assert len(test_delta.factors) == 1 assert 'copyright info added' in test_delta.factors - def test_determine_copyright_diff_copyright_info_removed(self): + def test_update_from_copyright_info_copyright_info_removed(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -977,13 +977,13 @@ def test_determine_copyright_diff_copyright_info_removed(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + 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_determine_copyright_diff_one_copyright_added(self): + def test_update_from_copyright_info_one_copyright_added(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -1027,13 +1027,13 @@ def test_determine_copyright_diff_one_copyright_added(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 25 assert len(test_delta.factors) == 1 assert 'copyright change' in test_delta.factors - def test_determine_copyright_diff_one_copyright_removed(self): + def test_update_from_copyright_info_one_copyright_removed(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -1077,13 +1077,13 @@ def test_determine_copyright_diff_one_copyright_removed(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 25 assert len(test_delta.factors) == 1 assert 'copyright change' in test_delta.factors - def test_determine_copyright_diff_file_added_one_copyright(self): + def test_update_from_copyright_info_file_added_one_copyright(self): test_file_new = models.File({ 'path':'/test/path.txt', 'name': 'path.txt', @@ -1103,13 +1103,13 @@ def test_determine_copyright_diff_file_added_one_copyright(self): test_delta = deltacode.Delta(100, test_file_new, None) - utils.determine_copyright_diff(test_delta) + utils.update_added_from_copyright_info(test_delta) assert test_delta.score == 110 assert len(test_delta.factors) == 1 assert 'copyright info added' in test_delta.factors - def test_determine_lic_copy_diffs_copyright_and_license_info_added(self): + 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', @@ -1145,8 +1145,8 @@ def test_determine_lic_copy_diffs_copyright_and_license_info_added(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_license_info(test_delta, unique_categories) + utils.update_modified_from_copyright_info(test_delta) expected_factors = [ 'license info added', @@ -1159,7 +1159,7 @@ def test_determine_lic_copy_diffs_copyright_and_license_info_added(self): for factor in expected_factors: assert factor in test_delta.factors - def test_determine_lic_copy_diffs_copyright_and_license_info_removed(self): + 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', @@ -1195,8 +1195,8 @@ def test_determine_lic_copy_diffs_copyright_and_license_info_removed(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_license_info(test_delta, unique_categories) + utils.update_modified_from_copyright_info(test_delta) expected_factors = [ 'license info removed', @@ -1208,7 +1208,7 @@ def test_determine_lic_copy_diffs_copyright_and_license_info_removed(self): for factor in expected_factors: assert factor in test_delta.factors - def test_determine_lic_copy_diffs_copyright_info_added_license_info_removed(self): + 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', @@ -1244,8 +1244,8 @@ def test_determine_lic_copy_diffs_copyright_info_added_license_info_removed(self test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_license_info(test_delta, unique_categories) + utils.update_modified_from_copyright_info(test_delta) expected_factors = [ 'license info removed', @@ -1257,7 +1257,7 @@ def test_determine_lic_copy_diffs_copyright_info_added_license_info_removed(self for factor in expected_factors: assert factor in test_delta.factors - def test_determine_lic_copy_diffs_license_info_added_copyright_info_removed(self): + 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', @@ -1293,8 +1293,8 @@ def test_determine_lic_copy_diffs_license_info_added_copyright_info_removed(self test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_license_info(test_delta, unique_categories) + utils.update_modified_from_copyright_info(test_delta) expected_factors = [ 'license info added', @@ -1307,7 +1307,7 @@ def test_determine_lic_copy_diffs_license_info_added_copyright_info_removed(self for factor in expected_factors: assert factor in test_delta.factors - def test_determine_lic_copy_diffs_copyright_change_no_license_change(self): + 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', @@ -1367,14 +1367,14 @@ def test_determine_lic_copy_diffs_copyright_change_no_license_change(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_license_info(test_delta, unique_categories) + utils.update_modified_from_copyright_info(test_delta) assert test_delta.score == 25 assert len(test_delta.factors) == 1 assert 'copyright change' in test_delta.factors - def test_determine_lic_copy_diffs_license_change_no_copyright_change(self): + 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', @@ -1432,8 +1432,8 @@ def test_determine_lic_copy_diffs_license_change_no_copyright_change(self): test_delta = deltacode.Delta(20, test_file_new, test_file_old) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_modified_from_license_info(test_delta, unique_categories) + utils.update_modified_from_copyright_info(test_delta) expected_factors = [ 'license change', @@ -1445,7 +1445,7 @@ def test_determine_lic_copy_diffs_license_change_no_copyright_change(self): for factor in expected_factors: assert factor in test_delta.factors - def test_determine_lic_copy_diffs_file_added_copyright_and_permissive_license(self): + 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', @@ -1473,8 +1473,8 @@ def test_determine_lic_copy_diffs_file_added_copyright_and_permissive_license(se test_delta = deltacode.Delta(100, test_file_new, None) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_added_from_license_info(test_delta, unique_categories) + utils.update_added_from_copyright_info(test_delta) expected_factors = [ 'license info added', @@ -1486,7 +1486,7 @@ def test_determine_lic_copy_diffs_file_added_copyright_and_permissive_license(se for factor in expected_factors: assert factor in test_delta.factors - def test_determine_lic_copy_diffs_file_added_copyright_and_commercial_and_copyleft_licenses(self): + 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', @@ -1522,8 +1522,8 @@ def test_determine_lic_copy_diffs_file_added_copyright_and_commercial_and_copyle test_delta = deltacode.Delta(100, test_file_new, None) - utils.determine_license_diff(test_delta, unique_categories) - utils.determine_copyright_diff(test_delta) + utils.update_added_from_license_info(test_delta, unique_categories) + utils.update_added_from_copyright_info(test_delta) expected_factors = [ 'license info added',