Skip to content

Commit 1b11fec

Browse files
committed
Remove cutoff_score from license_diff #62
* Also fixed failing tests, deleted one duplicative test. Signed-off-by: John M. Horan <johnmhoran@gmail.com>
1 parent b9c0db1 commit 1b11fec

3 files changed

Lines changed: 18 additions & 33 deletions

File tree

src/deltacode/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def __init__(self, new_path, old_path, options):
5656
if self.new.path != '' and self.old.path != '':
5757
self.determine_delta()
5858
self.determine_moved()
59-
# TODO: Need to account for possibly passing in a 'cutoff_score'.
6059
self.license_diff()
6160
# Sort deltas by score, descending, i.e., high > low.
6261
self.deltas.sort(key=lambda Delta: Delta.score, reverse=True)
@@ -180,7 +179,7 @@ def update_deltas(self, added, removed):
180179
self.deltas.remove(added)
181180
self.deltas.remove(removed)
182181

183-
def license_diff(self, cutoff_score=50):
182+
def license_diff(self):
184183
"""
185184
Compare the license details for a pair of 'new' and 'old' File objects
186185
in a Delta object and change the Delta object's 'score' attribute --
@@ -205,8 +204,8 @@ def license_diff(self, cutoff_score=50):
205204
i.score += 15
206205
return
207206

208-
new_keys = set(l.key for l in new_licenses if l.score >= cutoff_score)
209-
old_keys = set(l.key for l in old_licenses if l.score >= cutoff_score)
207+
new_keys = set(l.key for l in new_licenses)
208+
old_keys = set(l.key for l in old_licenses)
210209

211210
if new_keys != old_keys:
212211
i.factors.append('license change')
@@ -225,6 +224,7 @@ def index_deltas(self, index_key='path', delta_list=[]):
225224
index = {}
226225

227226
for delta in delta_list:
227+
# FIXME: This is an ugly way to do this.
228228
if delta.score == 10:
229229
key = getattr(delta.old_file, index_key)
230230
else:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Factors,Score,Path,Name,Type,Size,Old Path
2-
modified,20,some/path/a/a1.py,a1.py,file,350,
3-
modified,20,some/path/b/b1.py,b1.py,file,290,
2+
modified license change,30,some/path/a/a1.py,a1.py,file,350,
3+
modified license change,30,some/path/b/b1.py,b1.py,file,290,

tests/test_deltacode.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ def test_DeltaCode_license_modified_low_score(self):
250250

251251
deltas = result.deltas
252252

253-
assert len([i for i in deltas if i.score == 30]) == 0
254-
assert len([i for i in deltas if i.score == 20]) == 2
253+
assert len([i for i in deltas if i.score == 30]) == 2
254+
assert len([i for i in deltas if i.score == 20]) == 0
255255

256-
assert [d.score for d in deltas if d.new_file.path == 'some/path/a/a1.py'] == [20]
257-
assert [d.score for d in deltas if d.new_file.path == 'some/path/b/b1.py'] == [20]
256+
assert [d.score for d in deltas if d.new_file.path == 'some/path/a/a1.py'] == [30]
257+
assert [d.score for d in deltas if d.new_file.path == 'some/path/b/b1.py'] == [30]
258258

259259
def test_DeltaCode_license_modified(self):
260260
new_scan = self.get_test_loc('deltacode/scan_modified_new_license_added.json')
@@ -329,21 +329,6 @@ def test_Delta_modified_license_added(self):
329329
assert [d.score for d in deltas if d.new_file.path == 'some/path/b/b1.py'] == [30]
330330
assert [d.score for d in deltas if d.new_file.path == 'some/path/c/c1.py'] == [20]
331331

332-
def test_Delta_modified_license_added_low_score(self):
333-
new_scan = self.get_test_loc('deltacode/scan_modified_new_license_added_low_score.json')
334-
old_scan = self.get_test_loc('deltacode/scan_modified_old_license_added_low_score.json')
335-
336-
options = OrderedDict([
337-
('--all-delta-types', False)
338-
])
339-
340-
result = DeltaCode(new_scan, old_scan, options)
341-
342-
deltas = result.deltas
343-
344-
assert [d.score for d in deltas if d.new_file.path == 'some/path/a/a1.py'] == [20]
345-
assert [d.score for d in deltas if d.new_file.path == 'some/path/b/b1.py'] == [20]
346-
347332
def test_Delta_modified_no_license_changes(self):
348333
new_scan = self.get_test_loc('deltacode/scan_modified_new_no_license_changes.json')
349334
old_scan = self.get_test_loc('deltacode/scan_modified_old_no_license_changes.json')
@@ -847,8 +832,8 @@ def test_score_new_lic_below_cutoff_score(self):
847832
assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b']
848833
assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified']
849834

850-
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30]
851-
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified', 'license change']
835+
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20]
836+
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified']
852837
assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [
853838
OrderedDict([
854839
('key', 'mit'),
@@ -888,8 +873,8 @@ def test_score_old_lic_below_cutoff_score(self):
888873
assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b']
889874
assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified']
890875

891-
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30]
892-
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified', 'license change']
876+
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20]
877+
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified']
893878
assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [
894879
OrderedDict([
895880
('key', 'mit'),
@@ -1018,8 +1003,8 @@ def test_score_multiple_lic_keys_new_below_cutoff_score(self):
10181003
assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b']
10191004
assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified']
10201005

1021-
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20]
1022-
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified']
1006+
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30]
1007+
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified', 'license change']
10231008
assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [
10241009
OrderedDict([
10251010
('key', 'mit'),
@@ -1073,8 +1058,8 @@ def test_score_multiple_lic_keys_old_below_cutoff_score(self):
10731058
assert [d.old_file.sha1 for d in deltas_object if d.old_file.path == 'path.txt'] == ['b']
10741059
assert [d.new_file.sha1 for d in deltas_object if d.new_file.path == 'path.txt'] == ['b_modified']
10751060

1076-
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [20]
1077-
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified']
1061+
assert [d.score for d in deltas_object if d.new_file.path == 'path.txt'] == [30]
1062+
assert [d.factors for d in deltas_object if d.new_file.path == 'path.txt'].pop() == ['modified', 'license change']
10781063
assert [d.to_dict().get('old').get('licenses') for d in deltas_object if d.new_file.path == 'path.txt'].pop() == [
10791064
OrderedDict([
10801065
('key', 'gpl-2.0'),

0 commit comments

Comments
 (0)