Skip to content

Commit c2741df

Browse files
committed
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2 parents 53866eb + 5257bca commit c2741df

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
@@ -1542,7 +1542,7 @@ def _get_or_create_parent(self, path, parent_by_path):
15421542
Note: the root path and root Resource must already be in
15431543
`parent_by_path` or else this function does not work.
15441544
"""
1545-
parent_path = parent_directory(path).rstrip('/').rstrip('\\')
1545+
parent_path = parent_directory(path).rstrip('/').rstrip('\\').lstrip("/")
15461546
existing_parent = parent_by_path.get(parent_path)
15471547
if existing_parent:
15481548
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
@@ -1330,6 +1330,13 @@ def test_VirtualCodebase_create_from_multiple_scans(self):
13301330
]
13311331
assert expected == results
13321332

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

13341341
class TestResource(FileBasedTesting):
13351342
test_data_dir = join(dirname(__file__), 'data')

0 commit comments

Comments
 (0)