Skip to content

Commit e288619

Browse files
committed
test modify
Signed-off-by: Pratik Dey <pratikrocks.dey11@gmail.com>
1 parent 7fd5e79 commit e288619

79 files changed

Lines changed: 2083 additions & 1369 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/deltacode/__init__.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ class DeltaCode(object):
5555
def __init__(self, new_path, old_path, options):
5656
self.codebase1 = None
5757
self.codebase2 = None
58-
self.new_files_fingerprint = (
59-
dict()
60-
) # map of { {new_file1:fingerprint},{new_file2:fingerprint},...} it will be needed when we need the fingerprints
61-
self.old_files_fingerprint = (
62-
dict()
63-
) # map of { {old_file1:fingerprint},{old_file2:fingerprint},...}
6458
self.options = options
6559
self.deltas = []
6660
self.errors = []
@@ -70,6 +64,7 @@ def __init__(self, new_path, old_path, options):
7064
self.codebase2 = VirtualCodebase(old_path)
7165

7266
except Exception as exception:
67+
print(str(exception))
7368
self.errors.append(str(exception))
7469

7570
if self.codebase1 is not None or self.codebase2 is not None:
@@ -82,7 +77,7 @@ def __init__(self, new_path, old_path, options):
8277
self.license_diff()
8378
self.copyright_diff()
8479
self.stats.calculate_stats()
85-
self.similarity()
80+
# self.similarity()
8681
# Sort deltas by score, descending, i.e., high > low, and then by
8782
# factors, alphabetically. Run the least significant sort first.
8883
self.deltas.sort(key=lambda Delta: Delta.factors, reverse=False)
@@ -119,13 +114,8 @@ def similarity(self):
119114
)
120115

121116
def create_deltas(
122-
self, new_resource, old_resource, new_path, old_path, score, count, status
117+
self, new_resource, old_resource, new_path, old_path, score, status
123118
):
124-
count = count + 1
125-
if new_resource:
126-
new_resource.path = new_path
127-
if old_resource:
128-
old_resource.path = old_path
129119
delta = Delta(score, new_resource, old_resource)
130120
delta.status = status
131121
self.deltas.append(delta)
@@ -138,10 +128,12 @@ def determine_delta(self):
138128
"""
139129

140130
old_files_sha1_considered_in_deltas = dict()
141-
142-
Delta.NEW_CODEBASE_OFFSET, Delta.OLD_CODEBASE_OFFSET = utils.align_trees(
143-
self.codebase1, self.codebase2
144-
)
131+
try:
132+
Delta.NEW_CODEBASE_OFFSET, Delta.OLD_CODEBASE_OFFSET = utils.align_trees(
133+
self.codebase1, self.codebase2
134+
)
135+
except utils.AlignmentException:
136+
Delta.NEW_CODEBASE_OFFSET, Delta.OLD_CODEBASE_OFFSET = 0, 0
145137

146138
for new_resource in self.codebase1.walk():
147139
if new_resource.is_file:
@@ -170,9 +162,9 @@ def determine_delta(self):
170162
path_new,
171163
path_old,
172164
0,
173-
self.stats.num_unmodified,
174165
"unmodified",
175166
)
167+
self.stats.num_unmodified += 1
176168
break
177169
else:
178170
old_files_sha1_considered_in_deltas[
@@ -184,9 +176,9 @@ def determine_delta(self):
184176
path_new,
185177
path_old,
186178
20,
187-
self.stats.num_modified,
188179
"modified",
189180
)
181+
self.stats.num_modified += 1
190182
break
191183
else:
192184
if new_resource.sha1 == old_resource.sha1:
@@ -200,9 +192,9 @@ def determine_delta(self):
200192
path_new,
201193
path_old,
202194
0,
203-
self.stats.num_moved,
204195
"moved",
205196
)
197+
self.stats.num_moved += 1
206198
break
207199

208200
if ADDED:
@@ -212,9 +204,9 @@ def determine_delta(self):
212204
path_new,
213205
None,
214206
100,
215-
self.stats.num_added,
216207
"added",
217208
)
209+
self.stats.num_added += 1
218210

219211
for old_resource_remaining in self.codebase2.walk():
220212
if (
@@ -233,9 +225,9 @@ def determine_delta(self):
233225
None,
234226
path_old,
235227
0,
236-
self.stats.num_removed,
237228
"removed",
238229
)
230+
self.stats.num_removed += 1
239231

240232
def license_diff(self):
241233
"""
@@ -376,19 +368,20 @@ def licenses_to_dict(self, file):
376368
return []
377369

378370
def file_to_dict(self, deltacode, file, new_file=True):
371+
379372
path_offset = (
380373
Delta.NEW_CODEBASE_OFFSET if new_file else Delta.OLD_CODEBASE_OFFSET
381374
)
382375
if file:
383376
return OrderedDict(
384377
[
385-
("path", file.path),
378+
("path", "/".join(paths.split(file.path)[path_offset:])),
386379
("type", file.type),
387380
("name", file.name),
388381
("size", file.size),
389382
("sha1", file.sha1),
390-
("fingerprint", deltacode.old_files_fingerprint.get(file.path, "")),
391-
("original_path", "/".join(paths.split(file.path)[path_offset:])),
383+
("fingerprint", ""),
384+
("original_path", file.path),
392385
("licenses", self.licenses_to_dict(file)),
393386
("copyrights", self.copyrights_to_dict(file)),
394387
]
@@ -399,6 +392,8 @@ def to_dict(self, deltacode):
399392
Return an OrderedDict comprising the 'factors', 'score' and new and old
400393
'path' attributes of the object.
401394
"""
395+
if not deltacode.options.get("--all-delta-types", "") == True and self.status == "unmodified":
396+
return
402397
if self.new_file:
403398
new_file = self.new_file.to_dict()
404399
else:

src/deltacode/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import json
3535

3636
from commoncode.system import on_windows
37+
from commoncode import paths
3738
from commoncode.resource import VirtualCodebase
3839

3940
def run_scan_click(options, monkeypatch=None, test_mode=True, expected_rc=0, env=None):
@@ -149,6 +150,10 @@ def streamline_errors(errors):
149150
errors[i] = cleaned_error
150151

151152

153+
def get_aligned_path(delta, path, new_file):
154+
OFFSET = delta.NEW_CODEBASE_OFFSET if new_file else delta.OLD_CODEBASE_OFFSET
155+
return "/".join(paths.split(path)[OFFSET:])
156+
152157
def streamline_headers(headers):
153158
"""
154159
Modify the `headers` list of mappings in place to make it easier to test.

src/deltacode/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def update_added_from_license_info(delta, unique_categories):
5555
one or more categories to its 'factors' attribute if there has
5656
been a license change.
5757
"""
58-
new_licenses = delta.new_file.licenses or []
58+
new_licenses = (
59+
delta.new_file.licenses if hasattr(delta.new_file, "licenses") else []
60+
)
5961

6062
new_categories = set(license["category"] for license in new_licenses)
61-
if delta.new_file.licenses:
63+
if hasattr(delta.new_file, "licenses"):
6264
delta.update(20, "license info added")
6365
for category in new_categories:
6466
# no license ==> 'Copyleft Limited'or higher
@@ -200,7 +202,7 @@ def deltas(deltacode, all_delta_types=False):
200202
for delta in deltacode.deltas:
201203
if all_delta_types is True:
202204
yield delta.to_dict(deltacode)
203-
elif not delta.is_unmodified():
205+
elif not delta.status == "unmodified":
204206
yield delta.to_dict(deltacode)
205207

206208

tests/data/cli/scan_1_file_moved_new.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"size": 200,
7272
"sha1": "84b647771481d39dd3a53f6dc210c26abac37748",
7373
"md5": "3cb56efa7140478458dbaa2b30239845",
74-
"fingerprint": "83ee5b9e652faad754b8e20bead792f8",
7574
"files_count": null,
7675
"mime_type": "text/plain",
7776
"file_type": "ASCII text, with CRLF line terminators",
@@ -131,7 +130,6 @@
131130
"size": 200,
132131
"sha1": "310797523e47db8481aeb06f1634317285115091",
133132
"md5": "19efdad483f68bc9997a5c1f7ba41b26",
134-
"fingerprint": "e30cf09443e7878dfcd3288886e97533",
135133
"files_count": null,
136134
"mime_type": "text/plain",
137135
"file_type": "ASCII text, with CRLF line terminators",
@@ -191,7 +189,6 @@
191189
"size": 200,
192190
"sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9",
193191
"md5": "795ff2cae8ece792a9bfebe18ad3c8e6",
194-
"fingerprint": "e30cf09443e7878dfed3288886e97533",
195192
"files_count": null,
196193
"mime_type": "text/plain",
197194
"file_type": "ASCII text, with CRLF line terminators",
@@ -251,7 +248,6 @@
251248
"size": 200,
252249
"sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b",
253250
"md5": "fc403815d6605df989414ff40a64ea17",
254-
"fingerprint": "e30cf09443e7878dfed3288886e97542",
255251
"files_count": null,
256252
"mime_type": "text/plain",
257253
"file_type": "ASCII text, with CRLF line terminators",
@@ -311,7 +307,6 @@
311307
"size": 200,
312308
"sha1": "70f6ce80985578b5104db0abc578cf5a05e78f4b",
313309
"md5": "af9e9420c6c5b2b0ca74e96bf7c1a2f4",
314-
"fingerprint": "e30cf09443e7878dfed1088886e97542",
315310
"files_count": null,
316311
"mime_type": "text/plain",
317312
"file_type": "ASCII text, with CRLF line terminators",
@@ -371,7 +366,6 @@
371366
"size": 200,
372367
"sha1": "3340d86b1da9323067db8022f86dc97cfccee1d0",
373368
"md5": "74ce2b26cebb32670634270dde1fdf33",
374-
"fingerprint": "e30cf09443e7878dfed1088886e97232",
375369
"files_count": null,
376370
"mime_type": "text/plain",
377371
"file_type": "ASCII text, with CRLF line terminators",
@@ -431,7 +425,6 @@
431425
"size": 200,
432426
"sha1": "e49d4463662414bee5ad2d2e5c1fbd704f33b84e",
433427
"md5": "8d458f54d32959b03dff37ef485b29c6",
434-
"fingerprint": "e30cf83443e7878dfed1088886e97232",
435428
"files_count": null,
436429
"mime_type": "text/plain",
437430
"file_type": "ASCII text, with CRLF line terminators",
@@ -491,7 +484,6 @@
491484
"size": 200,
492485
"sha1": "98c9e6bed78b1513c28e666016cb35a50708c36e",
493486
"md5": "c3559aef44883a46e007ab01213091cb",
494-
"fingerprint": "e30cf83443e7878dfed1032386e97232",
495487
"files_count": null,
496488
"mime_type": "text/plain",
497489
"file_type": "ASCII text, with CRLF line terminators",

tests/data/cli/scan_1_file_moved_old.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"size": 200,
7272
"sha1": "84b647771481d39dd3a53f6dc210c26abac37748",
7373
"md5": "3cb56efa7140478458dbaa2b30239845",
74-
"fingerprint": "83ee5b9e652faad754b8e20bead792f8",
7574
"files_count": null,
7675
"mime_type": "text/plain",
7776
"file_type": "ASCII text, with CRLF line terminators",
@@ -131,7 +130,6 @@
131130
"size": 200,
132131
"sha1": "310797523e47db8481aeb06f1634317285115091",
133132
"md5": "19efdad483f68bc9997a5c1f7ba41b26",
134-
"fingerprint": "e30cf09443e7878dfcd3288886e97533",
135133
"files_count": null,
136134
"mime_type": "text/plain",
137135
"file_type": "ASCII text, with CRLF line terminators",
@@ -191,7 +189,6 @@
191189
"size": 200,
192190
"sha1": "fd5d3589c825f448546d7dcec36da3e567d35fe9",
193191
"md5": "795ff2cae8ece792a9bfebe18ad3c8e6",
194-
"fingerprint": "e30cf09443e7878dfed3288886e97533",
195192
"files_count": null,
196193
"mime_type": "text/plain",
197194
"file_type": "ASCII text, with CRLF line terminators",
@@ -251,7 +248,6 @@
251248
"size": 200,
252249
"sha1": "6f71666c46446c29d3f45feef5419ae76fb86a5b",
253250
"md5": "fc403815d6605df989414ff40a64ea17",
254-
"fingerprint": "e30cf09443e7878dfed3288886e97542",
255251
"files_count": null,
256252
"mime_type": "text/plain",
257253
"file_type": "ASCII text, with CRLF line terminators",
@@ -311,7 +307,6 @@
311307
"size": 200,
312308
"sha1": "70f6ce80985578b5104db0abc578cf5a05e78f4b",
313309
"md5": "af9e9420c6c5b2b0ca74e96bf7c1a2f4",
314-
"fingerprint": "e30cf09443e7878dfed1088886e97542",
315310
"files_count": null,
316311
"mime_type": "text/plain",
317312
"file_type": "ASCII text, with CRLF line terminators",
@@ -371,7 +366,6 @@
371366
"size": 200,
372367
"sha1": "3340d86b1da9323067db8022f86dc97cfccee1d0",
373368
"md5": "74ce2b26cebb32670634270dde1fdf33",
374-
"fingerprint": "e30cf09443e7878dfed1088886e97232",
375369
"files_count": null,
376370
"mime_type": "text/plain",
377371
"file_type": "ASCII text, with CRLF line terminators",
@@ -431,7 +425,6 @@
431425
"size": 200,
432426
"sha1": "e49d4463662414bee5ad2d2e5c1fbd704f33b84e",
433427
"md5": "8d458f54d32959b03dff37ef485b29c6",
434-
"fingerprint": "e30cf83443e7878dfed1088886e97232",
435428
"files_count": null,
436429
"mime_type": "text/plain",
437430
"file_type": "ASCII text, with CRLF line terminators",
@@ -491,7 +484,6 @@
491484
"size": 200,
492485
"sha1": "98c9e6bed78b1513c28e666016cb35a50708c36e",
493486
"md5": "c3559aef44883a46e007ab01213091cb",
494-
"fingerprint": "e30cf83443e7878dfed1032386e97232",
495487
"files_count": null,
496488
"mime_type": "text/plain",
497489
"file_type": "ASCII text, with CRLF line terminators",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"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.",
3+
"scancode_version": "2.1.0",
4+
"scancode_options": {
5+
"--license": true,
6+
"--info": true
7+
},
8+
"files_count": 1,
9+
"files": [
10+
{
11+
"path": "path/modified.txt",
12+
"type": "file",
13+
"name": "modified.txt",
14+
"size": 20,
15+
"sha1": "a",
16+
"original_path": ""
17+
}
18+
]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"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.",
3+
"scancode_version": "2.1.0",
4+
"scancode_options": {
5+
"--license": true,
6+
"--info": true
7+
},
8+
"files_count": 1,
9+
"files": [
10+
{
11+
"path": "path/modified.txt",
12+
"type": "file",
13+
"name": "modified.txt",
14+
"size": 21,
15+
"sha1": "b",
16+
"original_path": ""
17+
}
18+
]
19+
}

tests/data/deltacode/no_lic_to_all_notable_lic_new.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"date": "2018-03-16",
4949
"sha1": "535b9966048ad50a9d5eb2f167c0a3013ee5cc6f",
5050
"md5": "e5658fe520bbebaf6f3d4be2e2525ab6",
51-
"fingerprint": "e30cf09443e7878dfed3288886e97542",
5251
"mime_type": "text/plain",
5352
"file_type": "UTF-8 Unicode text, with very long lines, with CRLF line terminators",
5453
"programming_language": "Python",
@@ -407,7 +406,6 @@
407406
"date": "2017-09-26",
408407
"sha1": "310797523e47db8481aeb06f1634317285115091",
409408
"md5": "19efdad483f68bc9997a5c1f7ba41b26",
410-
"fingerprint": "e30cf09443e7878dfed3288886d17542",
411409
"mime_type": "text/plain",
412410
"file_type": "ASCII text, with CRLF line terminators",
413411
"programming_language": "Python",

tests/data/deltacode/no_lic_to_all_notable_lic_old.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"date": "2018-03-16",
4949
"sha1": "0d17f1c2b6b82e8c7eec1fdad94c028b679518ff",
5050
"md5": "a2272cfafc4dff14c008db5c5ddde6a9",
51-
"fingerprint": "e30cf09443e7878dfed3288886e97542",
5251
"mime_type": "text/plain",
5352
"file_type": "ASCII text, with CRLF line terminators",
5453
"programming_language": "Python",
@@ -76,7 +75,6 @@
7675
"date": "2017-09-26",
7776
"sha1": "310797523e47db8481aeb06f1634317285115091",
7877
"md5": "19efdad483f68bc9997a5c1f7ba41b26",
79-
"fingerprint": "e30cf09443e7878dfed3288886d17542",
8078
"mime_type": "text/plain",
8179
"file_type": "ASCII text, with CRLF line terminators",
8280
"programming_language": "Python",

0 commit comments

Comments
 (0)