Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/commoncode/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,10 +1591,13 @@ def _populate(self, scan_data):
if not resources_data:
raise Exception('Input has no file-level scan results.')

# We collect the first Resource so we can see what attributes it has and determine
# the root path from its path
sample_resource_data = resources_data[0]

# We iterate through all the Resource(s) so that we can build attributes each resource contains

sample_resource_data = dict()

for resource in resources_data:
sample_resource_data.update(resource)

# Collect the existing attributes of the standard Resource class
standard_res_attributes = set(f.name for f in attr.fields(Resource))
# add these properties since they are fields but are serialized
Expand Down
26 changes: 26 additions & 0 deletions tests/data/resource/virtual_codebase/fingerprint_attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"files": [
{
"path": "apache_to_all_notable_lic_new",
"type": "directory",
"sha1": null,
"md5": null,
"scan_errors": []
},
{
"path": "apache_to_all_notable_lic_new/a1.py",
"type": "file",
"sha1": "535b9966048ad50a9d5eb2f167c0a3013ee5cc6f",
"md5": "e5658fe520bbebaf6f3d4be2e2525ab6",
"fingerprint": "e30cf09443e7878dfed3288886e97542",
"scan_errors": []
},
{
"path": "apache_to_all_notable_lic_new/a2.py",
"type": "file",
"sha1": "310797523e47db8481aeb06f1634317285115091",
"md5": "19efdad483f68bc9997a5c1f7ba41b26",
"scan_errors": []
}
]
}
9 changes: 9 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,15 @@ def test_virtual_codebase_can_process_minimal_resources_with_only_path(self):
])
]
assert [r.to_dict() for r in codebase.walk()] == expected

def test_VirtualCodebase_account_fingerprint_attribute(self):
test_file = self.get_test_loc("resource/virtual_codebase/fingerprint_attribute.json")
codebase = VirtualCodebase(test_file)
resources_fingerprint = [resource.fingerprint for resource in codebase.walk()]
assert "e30cf09443e7878dfed3288886e97542" in resources_fingerprint
assert None in resources_fingerprint
assert codebase.get_resource(0) == codebase.root
assert resources_fingerprint.count(None) == 2


class TestCodebaseLowestCommonParent(FileBasedTesting):
Expand Down