Skip to content

Commit 1b639c6

Browse files
committed
test_deltacode_to_dict_modified
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
1 parent 7e78c28 commit 1b639c6

3 files changed

Lines changed: 36 additions & 27 deletions

File tree

src/deltacode/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, new_path, old_path, options):
5252
try:
5353
self.codebase1 = VirtualCodebase(new_path)
5454
self.codebase2 = VirtualCodebase(old_path)
55-
except :
55+
except Exception as exception:
5656
pass
5757
self.new_files_count = 0 #keeps the count of the new file
5858
self.old_files_count = 0 #keeps the count of old files
@@ -549,4 +549,3 @@ def to_dict(self):
549549
('percent_modified', self.percent_modified),
550550
('percent_unmodified', self.percent_unmodified),
551551
])
552-
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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/unmodified.txt",
12+
"type": "file",
13+
"name": "unmodified.txt",
14+
"size": 20,
15+
"sha1": "a",
16+
"fingerprint": "e30cf09443e7878dfed3288886e97542",
17+
"original_path": ""
18+
}
19+
20+
]
21+
}

tests/test_deltacode.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -409,24 +409,14 @@ def test_Delta_to_dict_modified(self):
409409
assert delta.to_dict() == expected
410410

411411
def test_Delta_to_dict_unmodified(self):
412-
new = models.File({
413-
'path': 'path/unmodified.txt',
414-
'type': 'file',
415-
'name': 'unmodified.txt',
416-
'size': 20,
417-
'sha1': 'a',
418-
'fingerprint': 'e30cf09443e7878dfed3288886e97542',
419-
'original_path': ''
420-
})
421-
old = models.File({
422-
'path': 'path/unmodified.txt',
423-
'type': 'file',
424-
'name': 'unmodified.txt',
425-
'size': 20,
426-
'sha1': 'a',
427-
'fingerprint': 'e30cf09443e7878dfed3288886e97542',
428-
'original_path': ''
429-
})
412+
new_scan = self.get_test_loc('deltacode/test_Delta_to_dict_unmodified.json')
413+
old_scan = self.get_test_loc('deltacode/test_Delta_to_dict_unmodified.json')
414+
415+
options = OrderedDict([
416+
('--all-delta-types', True)
417+
])
418+
deltacode_object = DeltaCode(new_scan,old_scan,options)
419+
delta_objects = deltacode_object.deltas
430420

431421
expected = OrderedDict([
432422
('status', 'unmodified'),
@@ -439,7 +429,7 @@ def test_Delta_to_dict_unmodified(self):
439429
('size', 20),
440430
('sha1', 'a'),
441431
('fingerprint', 'e30cf09443e7878dfed3288886e97542'),
442-
('original_path', ''),
432+
('original_path', 'path/unmodified.txt'),
443433
('licenses', []),
444434
('copyrights', [])
445435
])),
@@ -450,16 +440,15 @@ def test_Delta_to_dict_unmodified(self):
450440
('size', 20),
451441
('sha1', 'a'),
452442
('fingerprint', 'e30cf09443e7878dfed3288886e97542'),
453-
('original_path', ''),
443+
('original_path', 'path/unmodified.txt'),
454444
('licenses', []),
455445
('copyrights', [])
456446
]))
457447
])
458-
459-
delta = deltacode.Delta(0, new, old)
460-
delta.status = 'unmodified'
461-
462-
assert delta.to_dict() == expected
448+
for delta in delta_objects:
449+
delta.status = 'unmodified'
450+
for delta in delta_objects:
451+
assert delta.to_dict(deltacode_object) == expected
463452

464453
def test_Delta_to_dict_moved(self):
465454
new = models.File({

0 commit comments

Comments
 (0)