Skip to content

Commit 5257bca

Browse files
committed
Fixed Full Root scans for Virtual Codebase
Signed-off-by: Pratik Dey <pratikrocks.dey11@gmail.com>
1 parent 76a03d9 commit 5257bca

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/commoncode/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ def _get_or_create_parent(self, path, parent_by_path):
15111511
Note: the root path and root Resource must already be in `parent_by_path` or else this
15121512
function does not work.
15131513
"""
1514-
parent_path = parent_directory(path).rstrip('/').rstrip('\\')
1514+
parent_path = parent_directory(path).rstrip('/').rstrip('\\').lstrip("/")
15151515
existing_parent = parent_by_path.get(parent_path)
15161516
if existing_parent:
15171517
return existing_parent
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.2.1.post12.6d07756e",
4+
"scancode_options": {
5+
"--info": true,
6+
"--license-score": 0,
7+
"--full-root": true,
8+
"--format": "json-pp"
9+
},
10+
"files_count": 1,
11+
"files": [
12+
{
13+
"path": "/Users/sesser/code/nexb/scancode-toolkit/samples/README",
14+
"type": "file",
15+
"name": "README",
16+
"base_name": "README",
17+
"extension": "",
18+
"date": "2017-09-22",
19+
"size": 236,
20+
"sha1": "2e07e32c52d607204fad196052d70e3d18fb8636",
21+
"md5": "effc6856ef85a9250fb1a470792b3f38",
22+
"files_count": null,
23+
"mime_type": "text/plain",
24+
"file_type": "ASCII text",
25+
"programming_language": null,
26+
"is_binary": false,
27+
"is_text": true,
28+
"is_archive": false,
29+
"is_media": false,
30+
"is_source": false,
31+
"is_script": false,
32+
"scan_errors": []
33+
}
34+
]
35+
}
36+

tests/test_resource.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,13 @@ def test_VirtualCodebase_create_from_multiple_scans(self):
13231323
]
13241324
assert expected == results
13251325

1326+
def test_VirtualCodebase_scanning_full_root(self):
1327+
test_file = self.get_test_loc("resource/virtual_codebase/path_full_root.json")
1328+
codebase = VirtualCodebase(test_file)
1329+
resource = sorted(r for r in codebase.walk())[0]
1330+
assert resource.path == "/Users/sesser/code/nexb/scancode-toolkit/samples/README"
1331+
assert codebase.compute_counts()[0] == 1
1332+
13261333

13271334
class TestResource(FileBasedTesting):
13281335
test_data_dir = join(dirname(__file__), 'data')

0 commit comments

Comments
 (0)