Skip to content

Commit e0c1245

Browse files
authored
Merge pull request #1030 from nexB/990-load-from-json
Add test for minimal virtualcodebase #990
2 parents a8c5544 + b6df628 commit e0c1245

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

src/scancode/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ def res_data(file_data):
11301130
file_data.pop('base_name', None)
11311131
file_data.pop('extension', None)
11321132

1133-
file_type = file_data.pop('type', False)
1133+
file_type = file_data.pop('type', 'file')
11341134
is_file = file_type == 'file'
11351135

11361136
return name, path, is_file, file_data
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.1.post71.a1f6ea002",
4+
"scancode_options": {
5+
"input": "NOTICE",
6+
"--copyright": true,
7+
"--json-pp": "noinfo.json"
8+
},
9+
"files_count": 1,
10+
"files": [
11+
{
12+
"path": "NOTICE",
13+
"type": "file",
14+
"copyrights": [
15+
{
16+
"statements": [
17+
"Copyright (c) 2017 nexB Inc. and others."
18+
],
19+
"holders": [
20+
"nexB Inc. and others."
21+
],
22+
"authors": [],
23+
"start_line": 4,
24+
"end_line": 4
25+
}
26+
],
27+
"scan_errors": []
28+
}
29+
]
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"files_count": 1,
3+
"files": [
4+
{
5+
"path": "NOTICE"
6+
}
7+
]
8+
}

tests/scancode/test_resource.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
from __future__ import print_function
2828
from __future__ import unicode_literals
2929

30+
from collections import OrderedDict
3031
from os.path import dirname
3132
from os.path import exists
3233
from os.path import join
3334

3435
from commoncode.testcase import FileBasedTesting
36+
from commoncode.fileutils import parent_directory
3537

3638
from scancode.resource import Codebase
37-
from scancode.resource import VirtualCodebase
38-
from commoncode.fileutils import parent_directory
3939
from scancode.resource import get_path
40+
from scancode.resource import VirtualCodebase
4041

4142

4243
class TestCodebase(FileBasedTesting):
@@ -411,7 +412,6 @@ def test_get_path(self):
411412
assert full == full_skipped
412413

413414
def test_compute_counts_when_using_disk_cache(self):
414-
from functools import partial
415415

416416
test_codebase = self.get_test_loc('resource/samples')
417417
codebase = Codebase(test_codebase, strip_root=True, max_in_memory=-1)
@@ -421,6 +421,7 @@ def test_compute_counts_when_using_disk_cache(self):
421421
assert size_count == 0
422422

423423
def test_low_max_in_memory_does_not_raise_exception_when_ignoring_files(self):
424+
424425
def is_ignored(location, ignores):
425426
"""
426427
Return a tuple of (pattern , message) if a file at location is ignored or
@@ -848,6 +849,37 @@ def test_virtual_codebase_get_resource(self):
848849
plugin_attributes=attributes)
849850
assert virtual_codebase.root is virtual_codebase.get_resource(0)
850851

852+
def test_virtual_codebase_can_process_minimal_resources_without_info(self):
853+
scan_data = self.get_test_loc('resource/virtual_codebase/noinfo.json')
854+
codebase = VirtualCodebase(json_scan_location=scan_data, plugin_attributes={})
855+
expected = [
856+
OrderedDict([
857+
(u'path', u'NOTICE'),
858+
(u'type', u'file'),
859+
(u'copyrights', [
860+
OrderedDict([
861+
(u'statements', [u'Copyright (c) 2017 nexB Inc. and others.']),
862+
(u'holders', [u'nexB Inc. and others.']),
863+
(u'authors', []),
864+
(u'start_line', 4),
865+
(u'end_line', 4)
866+
])
867+
]),
868+
(u'scan_errors', [])
869+
])
870+
]
871+
assert expected == [r.to_dict() for r in codebase.walk()]
872+
873+
def test_virtual_codebase_can_process_minimal_resources_with_only_path(self):
874+
scan_data = self.get_test_loc('resource/virtual_codebase/only-path.json')
875+
codebase = VirtualCodebase(json_scan_location=scan_data, plugin_attributes={})
876+
expected = [OrderedDict([
877+
(u'path', u'NOTICE'),
878+
(u'type', u'file'),
879+
(u'scan_errors', [])
880+
])]
881+
assert expected == [r.to_dict() for r in codebase.walk()]
882+
851883

852884
class TestVirtualCodebaseCache(FileBasedTesting):
853885
test_data_dir = join(dirname(__file__), 'data')

0 commit comments

Comments
 (0)