Skip to content

Commit 25d29f1

Browse files
committed
Add test for build_spdx_licensing #56
Signed-off-by: Jono Yang <[email protected]>
1 parent 4521921 commit 25d29f1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"license_key": "389-exception", "spdx_license_key": "389-exception", "other_spdx_license_keys": [], "is_exception": true, "json": "389-exception.json", "yml": "389-exception.yml", "html": "389-exception.html", "text": "389-exception.LICENSE"}, {"license_key": "3com-microcode", "spdx_license_key": "LicenseRef-scancode-3com-microcode", "other_spdx_license_keys": [], "is_exception": false, "json": "3com-microcode.json", "yml": "3com-microcode.yml", "html": "3com-microcode.html", "text": "3com-microcode.LICENSE"}, {"license_key": "3dslicer-1.0", "spdx_license_key": "LicenseRef-scancode-3dslicer-1.0", "other_spdx_license_keys": [], "is_exception": false, "json": "3dslicer-1.0.json", "yml": "3dslicer-1.0.yml", "html": "3dslicer-1.0.html", "text": "3dslicer-1.0.LICENSE"}]

tests/test_license_expression.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919

2020
from collections import namedtuple
2121
from collections import OrderedDict
22+
from os.path import abspath
23+
from os.path import dirname
24+
from os.path import join
2225
from unittest import TestCase
2326
from unittest.case import expectedFailure
27+
import json
2428
import sys
2529

2630
from boolean.boolean import PARSE_UNBALANCED_CLOSING_PARENS
@@ -42,6 +46,7 @@
4246
from license_expression import ParseError
4347
from license_expression import Token
4448

49+
from license_expression import build_spdx_licensing
4550
from license_expression import build_token_groups_for_with_subexpression
4651
from license_expression import validate_symbols
4752

@@ -2224,3 +2229,27 @@ def test_validation_invalid_license_exception(self):
22242229
assert [] == result.valid_symbols
22252230
assert ['MIT'] == result.invalid_symbols
22262231
assert [] == result.exception_symbols
2232+
2233+
2234+
class UtilTest(TestCase):
2235+
def test_build_spdx_licensing(self):
2236+
curr_dir = dirname(abspath(__file__))
2237+
data_dir = join(curr_dir, 'data')
2238+
test_license_key_index_location = join(data_dir, 'test_license_key_index.json')
2239+
2240+
with open(test_license_key_index_location, 'r') as f:
2241+
license_info = json.load(f)
2242+
lics = [
2243+
{
2244+
'key': l.get('spdx_license_key', ''),
2245+
'aliases': l.get('other_spdx_license_keys', ''),
2246+
'is_exception': l.get('is_exception', ''),
2247+
} for l in license_info if l.get('spdx_license_key')
2248+
]
2249+
syms = [LicenseSymbol(**l) for l in lics]
2250+
expected = Licensing(syms)
2251+
2252+
result = build_spdx_licensing(test_license_key_index_location)
2253+
2254+
assert expected.known_symbols == result.known_symbols
2255+
assert expected.known_symbols_lowercase == result.known_symbols_lowercase

0 commit comments

Comments
 (0)