Skip to content

Commit 5f61749

Browse files
committed
fixed TypeError due to different attributes over directories and files
Signed-off-by: Pratik Dey <pratikrocks.dey11@gmail.com>
1 parent 02fb544 commit 5f61749

3 files changed

Lines changed: 111 additions & 2 deletions

File tree

src/commoncode/resource.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,12 @@ def _populate(self, scan_data):
15931593

15941594
# We collect the first Resource so we can see what attributes it has and determine
15951595
# the root path from its path
1596-
sample_resource_data = resources_data[0]
1597-
1596+
1597+
sample_resource_data = dict()
1598+
1599+
for resource in resources_data:
1600+
sample_resource_data.update(resource)
1601+
15981602
# Collect the existing attributes of the standard Resource class
15991603
standard_res_attributes = set(f.name for f in attr.fields(Resource))
16001604
# add these properties since they are fields but are serialized
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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.9.0b1.post32.fea65d35a",
4+
"scancode_options": {
5+
"input": "C:\\code\\nexb\\dev\\codebase01\\licenses\\apache_to_all_notable_lic\\apache_to_all_notable_lic_new",
6+
"--copyright": true,
7+
"--info": true,
8+
"--json-pp": "C:\\code\\nexb\\dev\\deltacode\\tests\\data\\deltacode\\apache_to_all_notable_lic_new.json",
9+
"--license": true,
10+
"--package": true
11+
},
12+
"files_count": 2,
13+
"files": [
14+
{
15+
"path": "apache_to_all_notable_lic_new",
16+
"type": "directory",
17+
"name": "apache_to_all_notable_lic_new",
18+
"base_name": "apache_to_all_notable_lic_new",
19+
"extension": "",
20+
"size": 0,
21+
"date": null,
22+
"sha1": null,
23+
"md5": null,
24+
"mime_type": null,
25+
"file_type": null,
26+
"programming_language": null,
27+
"is_binary": false,
28+
"is_text": false,
29+
"is_archive": false,
30+
"is_media": false,
31+
"is_source": false,
32+
"is_script": false,
33+
"licenses": [],
34+
"copyrights": [],
35+
"packages": [],
36+
"files_count": 2,
37+
"dirs_count": 0,
38+
"size_count": 16471,
39+
"scan_errors": []
40+
},
41+
{
42+
"path": "apache_to_all_notable_lic_new/a1.py",
43+
"type": "file",
44+
"name": "a1.py",
45+
"base_name": "a1",
46+
"extension": ".py",
47+
"size": 16271,
48+
"date": "2018-03-16",
49+
"sha1": "535b9966048ad50a9d5eb2f167c0a3013ee5cc6f",
50+
"md5": "e5658fe520bbebaf6f3d4be2e2525ab6",
51+
"fingerprint": "e30cf09443e7878dfed3288886e97542",
52+
"mime_type": "text/plain",
53+
"file_type": "UTF-8 Unicode text, with very long lines, with CRLF line terminators",
54+
"programming_language": "Python",
55+
"is_binary": false,
56+
"is_text": true,
57+
"is_archive": false,
58+
"is_media": false,
59+
"is_source": true,
60+
"is_script": false,
61+
"licenses": [],
62+
"copyrights": [],
63+
"packages": [],
64+
"files_count": 0,
65+
"dirs_count": 0,
66+
"size_count": 0,
67+
"scan_errors": []
68+
},
69+
{
70+
"path": "apache_to_all_notable_lic_new/a2.py",
71+
"type": "file",
72+
"name": "a2.py",
73+
"base_name": "a2",
74+
"extension": ".py",
75+
"size": 200,
76+
"date": "2017-09-26",
77+
"sha1": "310797523e47db8481aeb06f1634317285115091",
78+
"md5": "19efdad483f68bc9997a5c1f7ba41b26",
79+
"mime_type": "text/plain",
80+
"file_type": "ASCII text, with CRLF line terminators",
81+
"programming_language": "Python",
82+
"is_binary": false,
83+
"is_text": true,
84+
"is_archive": false,
85+
"is_media": false,
86+
"is_source": true,
87+
"is_script": false,
88+
"licenses": [],
89+
"copyrights": [],
90+
"packages": [],
91+
"files_count": 0,
92+
"dirs_count": 0,
93+
"size_count": 0,
94+
"scan_errors": []
95+
}
96+
]
97+
}

tests/test_resource.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,14 @@ def test_virtual_codebase_can_process_minimal_resources_with_only_path(self):
10551055
])
10561056
]
10571057
assert [r.to_dict() for r in codebase.walk()] == expected
1058+
1059+
def test_VirtualCodebase_account_fingerprint_attribute(self):
1060+
test_file = self.get_test_loc("resource/virtual_codebase/fingerprint_attribute.json")
1061+
codebase = VirtualCodebase(test_file)
1062+
resources_fingerprint = [resource.fingerprint for resource in codebase.walk()]
1063+
assert "e30cf09443e7878dfed3288886e97542" in resources_fingerprint
1064+
assert None in resources_fingerprint
1065+
assert resources_fingerprint.count(None) == 2
10581066

10591067

10601068
class TestCodebaseLowestCommonParent(FileBasedTesting):

0 commit comments

Comments
 (0)