Skip to content

Commit

Permalink
Include directories in codebase.walk, ignore file date in JSON tests
Browse files Browse the repository at this point in the history
Reference: #2945

Signed-off-by: John M. Horan <[email protected]>
  • Loading branch information
johnmhoran committed May 23, 2022
1 parent f29255f commit 1f7d78f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/summarycode/file_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ def process_codebase(self, codebase, file_cat, **kwargs):
return

for resource in codebase.walk(topdown=True):
if resource.is_file:
category = categorize_resource(resource)
if not category:
continue
resource.analysis_priority = category.analysis_priority
resource.file_category = category.file_category
resource.file_subcategory = category.file_subcategory
resource.save(codebase)
category = categorize_resource(resource)
if not category:
continue
resource.analysis_priority = category.analysis_priority
resource.file_category = category.file_category
resource.file_subcategory = category.file_subcategory
resource.save(codebase)


class Categorizer:
Expand Down
93 changes: 93 additions & 0 deletions tests/summarycode/data/file_cat/archive/media01-info-scan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"headers": [
{
"tool_name": "scancode-toolkit",
"tool_version": "31.0.0b5",
"options": {
"input": [
"tests/summarycode/data/file_cat/code/media01"
],
"--file-cat": true,
"--info": true,
"--json-pp": "tests/summarycode/data/file_cat/scans/media01/media01-info-scan.json"
},
"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.",
"start_timestamp": "2022-05-21T010012.311818",
"end_timestamp": "2022-05-21T010012.367067",
"output_format_version": "2.0.0",
"duration": 0.0552670955657959,
"message": null,
"errors": [],
"warnings": [],
"extra_data": {
"system_environment": {
"operating_system": "linux",
"cpu_architecture": "64",
"platform": "Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.29",
"platform_version": "#1 SMP Wed Mar 2 00:30:59 UTC 2022",
"python_version": "3.8.10 (default, Mar 15 2022, 12:22:08) \n[GCC 9.4.0]"
},
"spdx_license_list_version": "3.16",
"files_count": 1
}
}
],
"files": [
{
"path": "media01",
"type": "directory",
"name": "media01",
"base_name": "media01",
"extension": "",
"size": 0,
"date": null,
"sha1": null,
"md5": null,
"sha256": null,
"mime_type": null,
"file_type": null,
"programming_language": null,
"is_binary": false,
"is_text": false,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"analysis_priority": null,
"file_category": null,
"file_subcategory": null,
"files_count": 1,
"dirs_count": 0,
"size_count": 105451,
"scan_errors": []
},
{
"path": "media01/jarDependImg.png",
"type": "file",
"name": "jarDependImg.png",
"base_name": "jarDependImg",
"extension": ".png",
"size": 105451,
"date": "2008-01-06",
"sha1": "d8b1b95b564b776e24b8de15699471c8e871fd34",
"md5": "cbaa0aefb8e2505c2670db5832c2316f",
"sha256": "9bf513e9a63aad6d99c3a76759ba2b5f4bb795568a35ddd41d8d9460c8fb9673",
"mime_type": "image/png",
"file_type": "PNG image data, 600 x 400, 8-bit/color RGBA, non-interlaced",
"programming_language": null,
"is_binary": true,
"is_text": false,
"is_archive": false,
"is_media": true,
"is_source": false,
"is_script": false,
"analysis_priority": "3",
"file_category": "media",
"file_subcategory": "image",
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"--json-pp": "tests/summarycode/data/file_cat/scans/media01/media01-info-scan.json"
},
"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.",
"start_timestamp": "2022-05-21T010012.311818",
"end_timestamp": "2022-05-21T010012.367067",
"start_timestamp": "2022-05-23T194805.069626",
"end_timestamp": "2022-05-23T194805.131938",
"output_format_version": "2.0.0",
"duration": 0.0552670955657959,
"duration": 0.06232571601867676,
"message": null,
"errors": [],
"warnings": [],
Expand Down Expand Up @@ -53,9 +53,9 @@
"is_media": false,
"is_source": false,
"is_script": false,
"analysis_priority": null,
"file_category": null,
"file_subcategory": null,
"analysis_priority": "4",
"file_category": "directory",
"file_subcategory": "",
"files_count": 1,
"dirs_count": 0,
"size_count": 105451,
Expand Down
4 changes: 3 additions & 1 deletion tests/summarycode/test_file_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2370,4 +2370,6 @@ def test_media01_info():
result_file = test_env.get_temp_file("json")
run_scan_click(["--info", "--file-cat", test_dir, "--json", result_file])
expected = test_env.get_test_loc("file_cat/scans/media01/media01-info-scan.json")
check_json_scan(expected, result_file, regen=REGEN_TEST_FIXTURES)
check_json_scan(
expected, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES
)

0 comments on commit 1f7d78f

Please sign in to comment.