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
2 changes: 1 addition & 1 deletion src/commoncode/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ def _get_or_create_parent(self, path, parent_by_path):
Note: the root path and root Resource must already be in `parent_by_path` or else this
function does not work.
"""
parent_path = parent_directory(path).rstrip('/').rstrip('\\')
parent_path = parent_directory(path).rstrip('/').rstrip('\\').lstrip("/")
existing_parent = parent_by_path.get(parent_path)
if existing_parent:
return existing_parent
Expand Down
36 changes: 36 additions & 0 deletions tests/data/resource/virtual_codebase/path_full_root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"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.",
"scancode_version": "2.2.1.post12.6d07756e",
"scancode_options": {
"--info": true,
"--license-score": 0,
"--full-root": true,
"--format": "json-pp"
},
"files_count": 1,
"files": [
{
"path": "/Users/sesser/code/nexb/scancode-toolkit/samples/README",
"type": "file",
"name": "README",
"base_name": "README",
"extension": "",
"date": "2017-09-22",
"size": 236,
"sha1": "2e07e32c52d607204fad196052d70e3d18fb8636",
"md5": "effc6856ef85a9250fb1a470792b3f38",
"files_count": null,
"mime_type": "text/plain",
"file_type": "ASCII text",
"programming_language": null,
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"scan_errors": []
}
]
}

7 changes: 7 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,13 @@ def test_VirtualCodebase_create_from_multiple_scans(self):
]
assert expected == results

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


class TestResource(FileBasedTesting):
test_data_dir = join(dirname(__file__), 'data')
Expand Down