Repository navigation
Expand file tree
/
Copy pathtest_match_hash.py
More file actions
52 lines (43 loc) · 1.81 KB
/
Copy pathtest_match_hash.py
File metadata and controls
52 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# ScanCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/scancode-toolkit for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import os
from commoncode.testcase import FileBasedTesting
from licensedcode import index
from licensedcode import models
from licensedcode import match_hash
from licensedcode.spans import Span
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
class TestHashMatch(FileBasedTesting):
test_data_dir = TEST_DATA_DIR
def test_match_hash_can_match_exactly(self):
rule_dir = self.get_test_loc('hash/rules')
rules = list(models.load_rules(rule_dir))
idx = index.LicenseIndex(rules)
query_doc = self.get_test_loc('hash/old_rules/lgpl-2.0-plus_23.RULE')
matches = idx.match(query_doc)
assert len(matches) == 1
match = matches[0]
assert match.coverage() == 100
assert match.matcher == match_hash.MATCH_HASH
assert match.rule == rules[0]
assert match.qspan == Span(0, 119)
assert match.ispan == Span(0, 119)
def test_match_hash_returns_correct_offset(self):
rule_dir = self.get_test_loc('hash/rules')
rules = list(models.load_rules(rule_dir))
idx = index.LicenseIndex(rules)
query_doc = self.get_test_loc('hash/query.txt')
matches = idx.match(query_doc)
assert len(matches) == 1
match = matches[0]
assert match.matcher == match_hash.MATCH_HASH
assert match.coverage() == 100
assert match.rule == rules[0]
assert match.qspan == Span(0, 119)
assert match.ispan == Span(0, 119)