Skip to content

Commit 5366e68

Browse files
Add license dump tests
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 12355c5 commit 5366e68

File tree

84 files changed

+8082
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+8082
-12
lines changed

src/licensedcode/license_db.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import saneyaml
3636
from jinja2 import Environment, FileSystemLoader
3737
from licensedcode.models import load_licenses
38+
from licensedcode.models import licenses_data_dir
3839
from scancode_config import __version__ as scancode_version
3940

4041

@@ -129,7 +130,11 @@ def generate_help(output_path, environment):
129130
write_file(output_path, "help.html", html)
130131

131132

132-
def generate(build_location, template_dir=TEMPLATES_DIR):
133+
def generate(
134+
build_location,
135+
template_dir=TEMPLATES_DIR,
136+
licenses_data_dir=licenses_data_dir
137+
):
133138

134139
if not os.path.exists(build_location):
135140
os.makedirs(build_location)
@@ -138,7 +143,9 @@ def generate(build_location, template_dir=TEMPLATES_DIR):
138143
loader=FileSystemLoader(template_dir),
139144
autoescape=True,
140145
)
141-
licenses = dict(sorted(load_licenses(with_deprecated=True).items()))
146+
licenses = dict(sorted(
147+
load_licenses(licenses_data_dir=licenses_data_dir, with_deprecated=True).items()
148+
))
142149

143150
root_path = pathlib.Path(build_location)
144151
root_path.mkdir(parents=False, exist_ok=True)

src/scancode/cli_test_utils.py

+30
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from packageurl import PackageURL
1818

1919
from scancode_config import scancode_root_dir
20+
from scancode_config import REGEN_TEST_FIXTURES
2021

2122

2223
def run_scan_plain(
@@ -391,3 +392,32 @@ def streamline_jsonlines_scan(scan_result, remove_file_date=False):
391392

392393
for scanned_file in result_line.get('files', []):
393394
streamline_scanned_file(scanned_file, remove_file_date)
395+
396+
397+
def check_json(expected, results, regen=REGEN_TEST_FIXTURES):
398+
"""
399+
Assert if the results JSON file is the same as the expected JSON file.
400+
"""
401+
if regen:
402+
mode = 'w'
403+
with open(expected, mode) as ex:
404+
json.dump(results, ex, indent=2, separators=(',', ': '))
405+
with open(expected) as ex:
406+
expected = json.load(ex)
407+
assert results == expected
408+
409+
410+
def load_both_and_check_json(expected, results, regen=REGEN_TEST_FIXTURES):
411+
"""
412+
Assert if the results JSON file is the same as the expected JSON file.
413+
"""
414+
with open(results) as res:
415+
results = json.load(res)
416+
417+
if regen:
418+
mode = 'w'
419+
with open(expected, mode) as ex:
420+
json.dump(results, ex, indent=2, separators=(',', ': '))
421+
with open(expected) as ex:
422+
expected = json.load(ex)
423+
assert results == expected

tests/licensedcode/data/license_db/index.json-expected.json

+158
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
key: bash-exception-gpl
3+
short_name: Bash exception to GPL
4+
name: Bash exception to GPL
5+
category: Copyleft
6+
owner: Free Software Foundation (FSF)
7+
notes: this used with GPL 1.0 and 2.0. It was removed from the V3 text https://git.savannah.gnu.org/cgit/bash.git/commit/COPYING?id=3185942a5234e26ab13fa02f9c51d340cec514f8
8+
is_exception: yes
9+
spdx_license_key: LicenseRef-scancode-bash-exception-gpl-2.0
10+
text_urls:
11+
- https://git.savannah.gnu.org/cgit/bash.git/plain/COPYING?h=bash-3.0-rc1&id=dd9e6dfa23d0dae4888f11fb8c6a27bc36d1b283
12+
---
13+
14+
b'\nThe Free Software Foundation has exempted Bash from the requirement of\nParagraph 2c of the General Public License. This is to say, there is\nno requirement for Bash to print a notice when it is started\ninteractively in the usual way. We made this exception because users\nand standards expect shells not to print such messages. This\nexception applies to any program that serves as a shell and that is\nbased primarily on Bash as opposed to other GNU software.'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>LicenseDB: bash-exception-gpl</title>
7+
<style>
8+
table.dataTable {visibility: visible!important;}
9+
.dataTables_filter {display: none;}
10+
table.dataTable thead th, table.dataTable thead td {padding: 8px!important; border-top: 1px solid #111;}
11+
.dataTables_wrapper .dataTables_info {padding: 0 0 2px!important; font-size: .75rem!important; color: #3b4351!important;}
12+
header {padding-top: .4rem; padding-bottom: .4rem;}
13+
footer {background-color: #f7f8f9; color: #bcc3ce; padding: 1.5rem .75rem 1rem; margin-top: 1em;}
14+
a:visited {color: #5755d9!important;}
15+
.navbar .nav-item {color:#66758c;padding: .25rem .4rem;}
16+
.navbar .nav-item a, .navbar .nav-item a:visited {color:#66758c !important;}
17+
.anchor {color: #6362dc; display: none; margin-left: .2rem; padding: 0 .2rem;}
18+
h4:focus .anchor, h4:hover .anchor {display: inline; text-decoration: none;}
19+
.help_text, .help_text:hover, .help_text:visited {color: #3b4351!important; border-bottom: dotted 0.0625rem #cccccc; text-decoration: inherit;}
20+
</style>
21+
<link rel="stylesheet" href="static/spectre-0.5.9.min.css">
22+
<script src="static/jquery-3.5.1.slim.min.js"></script>
23+
24+
<script src="static/jquery.mark-8.11.1.min.js"></script>
25+
<style>
26+
table.dataTable {visibility: visible!important;}
27+
#search-section {display: none;}
28+
ul.list-style-none {list-style: none; margin: 0;}
29+
ul li:first-child {margin-top: 0;}
30+
dl {display: flex; flex-flow: row wrap;}
31+
dl dt, dl dd {margin: 0; padding: 6px 10px;}
32+
dt {flex-basis: 20%; background: #555; text-align: right; color: #fff;}
33+
dd {flex-basis: 70%; flex-grow: 1;}
34+
</style>
35+
36+
</head>
37+
<body style="padding: 0 7rem;">
38+
<div class="container">
39+
<header class="navbar">
40+
<section class="navbar-section">
41+
<a class="navbar-brand text-bold mr-2" style="font-size: 1rem;" href="index.html">ScanCode LicenseDB</a>
42+
<a href="help.html" class="btn btn-link">Help</a>
43+
<a href="https://gitter.im/aboutcode-org/discuss" target="_blank" class="btn btn-link">Chat</a>
44+
<a href="https://github.com/nexB/scancode-licensedb" target="_blank" class="btn btn-link">GitHub</a>
45+
<span class="nav-item">Licensed under <a href="cc-by-4.0.html" class="text-bold">CC-BY-4.0</a></span>
46+
</section>
47+
<section id="search-section">
48+
<div class="input-group input-inline">
49+
<button class="btn btn-primary input-group-btn disabled" tabindex="-1" style="opacity: 0.9">Search</button>
50+
<input id="searchbox" class="form-input" type="search">
51+
</div>
52+
</section>
53+
</header>
54+
</div>
55+
56+
<div class="container">
57+
<hr>
58+
<a href="index.html">back to list</a> -
59+
<a href="bash-exception-gpl.yml">yml</a> -
60+
<a href="bash-exception-gpl.json">json</a> -
61+
<a href="bash-exception-gpl.LICENSE">text</a> -
62+
<a href="https://github.com/nexB/scancode-toolkit/edit/develop/src/licensedcode/data/licenses/bash-exception-gpl.LICENSE" target="_blank">edit text</a> -
63+
<a href="https://github.com/nexB/scancode-toolkit/edit/develop/src/licensedcode/data/licenses/bash-exception-gpl.yml" target="_blank">edit data</a>
64+
<hr>
65+
<dl>
66+
67+
<dt style="">key</dt>
68+
<dd>
69+
70+
bash-exception-gpl
71+
72+
</dd>
73+
74+
<dt style="">short_name</dt>
75+
<dd>
76+
77+
Bash exception to GPL
78+
79+
</dd>
80+
81+
<dt style="">name</dt>
82+
<dd>
83+
84+
Bash exception to GPL
85+
86+
</dd>
87+
88+
<dt style="">category</dt>
89+
<dd>
90+
91+
Copyleft
92+
93+
</dd>
94+
95+
<dt style="">owner</dt>
96+
<dd>
97+
98+
Free Software Foundation (FSF)
99+
100+
</dd>
101+
102+
<dt style="">notes</dt>
103+
<dd>
104+
105+
this used with GPL 1.0 and 2.0. It was removed from the V3 text <a href="https://git.savannah.gnu.org/cgit/bash.git/commit/COPYING?id=3185942a5234e26ab13fa02f9c51d340cec514f8" rel="noopener" target="_blank">https://git.savannah.gnu.org/cgit/bash.git/commit/COPYING?id=3185942a5234e26ab13fa02f9c51d340cec514f8</a>
106+
107+
</dd>
108+
109+
<dt style="">is_exception</dt>
110+
<dd>
111+
112+
True
113+
114+
</dd>
115+
116+
<dt style="">spdx_license_key</dt>
117+
<dd>
118+
119+
LicenseRef-scancode-bash-exception-gpl-2.0
120+
121+
</dd>
122+
123+
<dt style="">text_urls</dt>
124+
<dd>
125+
126+
<ul class="list-style-none">
127+
<li><a href="https://git.savannah.gnu.org/cgit/bash.git/plain/COPYING?h=bash-3.0-rc1&amp;id=dd9e6dfa23d0dae4888f11fb8c6a27bc36d1b283" rel="noopener" target="_blank">https://git.savannah.gnu.org/cgit/bash.git/plain/COPYING?h=bash-3.0-rc1&amp;id=dd9e6dfa23d0dae4888f11fb8c6a27bc36d1b283</a></li>
128+
</ul>
129+
130+
</dd>
131+
132+
<dt style="">text</dt>
133+
<dd>
134+
135+
136+
The Free Software Foundation has exempted Bash from the requirement of
137+
Paragraph 2c of the General Public License. This is to say, there is
138+
no requirement for Bash to print a notice when it is started
139+
interactively in the usual way. We made this exception because users
140+
and standards expect shells not to print such messages. This
141+
exception applies to any program that serves as a shell and that is
142+
based primarily on Bash as opposed to other GNU software.
143+
144+
</dd>
145+
146+
</dl>
147+
<div class="text-bold">license_text</div>
148+
<pre id="license-text" class="code mt-1" style="white-space: pre-wrap;"><code>
149+
The Free Software Foundation has exempted Bash from the requirement of
150+
Paragraph 2c of the General Public License. This is to say, there is
151+
no requirement for Bash to print a notice when it is started
152+
interactively in the usual way. We made this exception because users
153+
and standards expect shells not to print such messages. This
154+
exception applies to any program that serves as a shell and that is
155+
based primarily on Bash as opposed to other GNU software.</code></pre>
156+
</div>
157+
158+
<div class="container">
159+
<footer class="section text-dark">
160+
<p>
161+
<a href="help.html">Help</a> ·
162+
<a href="https://gitter.im/aboutcode-org/discuss" target="_blank">Chat</a> ·
163+
<a href="https://github.com/nexB/scancode-licensedb" target="_blank">GitHub</a> ·
164+
<a href="https://www.aboutcode.org/" target="_blank">AboutCode</a>
165+
</p>
166+
<p>Designed and built by <a href="https://www.nexb.com/" target="_blank">nexB</a>. Licensed under the <a href="cc-by-4.0.html">Creative Commons Attribution License 4.0 (CC-BY-4.0)</a>.</p>
167+
<p>Generated with <a href="https://github.com/nexB/scancode-toolkit" target="_blank">ScanCode toolkit</a> 31.1.0 on Sep 28, 2022.</p>
168+
</footer>
169+
</div>
170+
171+
<script>
172+
$(document).ready(function() {
173+
let url_params = new URLSearchParams(window.location.search);
174+
let marks = url_params.getAll('mark'); // ?mark=0-10&mark=30-40
175+
$.each(marks, function(index, value) {
176+
let [start, end] = value.split("-");
177+
$("#license-text").markRanges([{
178+
start: start,
179+
length: end - start,
180+
}]);
181+
});
182+
});
183+
</script>
184+
185+
</body>
186+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"key": "bash-exception-gpl",
3+
"short_name": "Bash exception to GPL",
4+
"name": "Bash exception to GPL",
5+
"category": "Copyleft",
6+
"owner": "Free Software Foundation (FSF)",
7+
"notes": "this used with GPL 1.0 and 2.0. It was removed from the V3 text https://git.savannah.gnu.org/cgit/bash.git/commit/COPYING?id=3185942a5234e26ab13fa02f9c51d340cec514f8",
8+
"is_exception": true,
9+
"spdx_license_key": "LicenseRef-scancode-bash-exception-gpl-2.0",
10+
"text_urls": [
11+
"https://git.savannah.gnu.org/cgit/bash.git/plain/COPYING?h=bash-3.0-rc1&id=dd9e6dfa23d0dae4888f11fb8c6a27bc36d1b283"
12+
],
13+
"text": "\nThe Free Software Foundation has exempted Bash from the requirement of\nParagraph 2c of the General Public License. This is to say, there is\nno requirement for Bash to print a notice when it is started\ninteractively in the usual way. We made this exception because users\nand standards expect shells not to print such messages. This\nexception applies to any program that serves as a shell and that is\nbased primarily on Bash as opposed to other GNU software."
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
key: bash-exception-gpl
2+
short_name: Bash exception to GPL
3+
name: Bash exception to GPL
4+
category: Copyleft
5+
owner: Free Software Foundation (FSF)
6+
notes: this used with GPL 1.0 and 2.0. It was removed from the V3 text https://git.savannah.gnu.org/cgit/bash.git/commit/COPYING?id=3185942a5234e26ab13fa02f9c51d340cec514f8
7+
is_exception: yes
8+
spdx_license_key: LicenseRef-scancode-bash-exception-gpl-2.0
9+
text_urls:
10+
- https://git.savannah.gnu.org/cgit/bash.git/plain/COPYING?h=bash-3.0-rc1&id=dd9e6dfa23d0dae4888f11fb8c6a27bc36d1b283
11+
text: |
12+
13+
The Free Software Foundation has exempted Bash from the requirement of
14+
Paragraph 2c of the General Public License. This is to say, there is
15+
no requirement for Bash to print a notice when it is started
16+
interactively in the usual way. We made this exception because users
17+
and standards expect shells not to print such messages. This
18+
exception applies to any program that serves as a shell and that is
19+
based primarily on Bash as opposed to other GNU software.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
key: binary-linux-firmware
3+
short_name: Binary-Only Linux Firmware License
4+
name: Binary-Only Linux Firmware License
5+
category: Proprietary Free
6+
owner: Unspecified
7+
homepage_url: https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/
8+
spdx_license_key: LicenseRef-scancode-binary-linux-firmware
9+
---
10+
11+
b'\nRedistribution. Redistribution and use in binary form, without\nmodification, are permitted provided that the following conditions are\nmet:\n\n* Redistributions must reproduce the above copyright notice and the\nfollowing disclaimer in the documentation and/or other materials\nprovided with the distribution.\n\n* Neither the name of the Copyright Holder nor the names of its\nsuppliers may be used to endorse or promote products derived from this\nsoftware without specific prior written permission.\n\n* No reverse engineering, decompilation, or disassembly of this software\nis permitted.\n\nDISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\nCONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\nBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\nCOPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\nINCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\nNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\nUSE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\nANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\nTHIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE'

0 commit comments

Comments
 (0)