Skip to content

Commit 35366f0

Browse files
committed
Enable generation of copyright test data files
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 87d5559 commit 35366f0

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

src/licensedcode/data/licenses/mtll.LICENSE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ notes: |
1010
derived from the Apache Software License v1.1, but it is modified in
1111
several ways. It is Free, but GPL-incompatible.
1212
spdx_license_key: MTLL
13+
ignorable_authors:
14+
- at the University of Notre Dame, the Pervasive Technology Labs at Indiana University, and
15+
Dresden University of Technology
1316
---
1417

1518
Software License for MTL

src/licensedcode/data/licenses/nero-eula.LICENSE

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ ignorable_copyrights:
1515
- Copyright (c) 1991-2, RSA Data Security, Inc.
1616
- Copyright (c) 1992-1999 Dolby Laboratories, Inc.
1717
- Copyright (c) 1996-2012 Nero AG and its licensors
18+
- Copyright (c) 1999-2002. Microsoft Corporation
1819
- Copyright (c) 2008 Microsoft Corporation
1920
- Copyright 2011 Dolby Laboratories
20-
- Media Technologies. Copyright (c) 1999-2002. Microsoft Corporation
2121
- copyright (c) 1998-2005 The OpenSSL Project
2222
- copyright (c) 2000-2008 Gracenote
2323
- copyright (c) 2000-2008 Gracenote. Gracenote Software
@@ -33,7 +33,6 @@ ignorable_holders:
3333
- Dr Brian Gladman, Worcester, UK.
3434
- Gracenote
3535
- Gracenote. Gracenote Software
36-
- Media Technologies. Microsoft Corporation
3736
- Microsoft Corporation
3837
- Nero AG and its licensors
3938
- Nero AG.
@@ -402,4 +401,4 @@ Other product and brand names may be trademarks of their respective owners and d
402401
www.nero.com
403402

404403
If you have any questions concerning this Agreement contact us via legal@nero.com.
405-
© 2012 Nero AG. All rights reserved.
404+
© 2012 Nero AG. All rights reserved.

tests/cluecode/cluecode_test_utils.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#
99

1010
import io
11+
import os
1112
from itertools import chain
1213
from os import path
1314

@@ -23,7 +24,6 @@
2324
from cluecode.copyrights import Detection
2425
from scancode_config import REGEN_TEST_FIXTURES
2526

26-
2727
"""
2828
Data-driven Copyright test utilities.
2929
"""
@@ -129,19 +129,56 @@ def dump(self, check_exists=False):
129129
def load_copyright_tests(test_dir=test_env.test_data_dir, generate_missing=False):
130130
"""
131131
Yield an iterable of CopyrightTest loaded from test data files in `test_dir`.
132+
If `generate_missing` is True, generate missing YAML data files with a default test template.
132133
"""
133-
test_dirs = (path.join(test_dir, td) for td in
134-
('copyrights', 'ics', 'holders', 'authors', 'years', 'generated'))
134+
test_dirs = [
135+
path.join(test_dir, td)
136+
for td in
137+
('copyrights', 'ics', 'holders', 'authors', 'years', 'generated')
138+
]
139+
140+
if generate_missing:
141+
for td in test_dirs:
142+
create_missing_test_data_files(test_dir=td)
135143

136-
all_test_files = chain.from_iterable(
137-
get_test_file_pairs(td, generate_missing=generate_missing)
138-
for td in test_dirs
139-
)
144+
all_test_files = chain.from_iterable(get_test_file_pairs(td) for td in test_dirs)
140145

141146
for data_file, test_file in all_test_files:
142147
yield CopyrightTest(data_file, test_file)
143148

144149

150+
empty_data_file = """what:
151+
- copyrights
152+
- holders
153+
- holders_summary
154+
- authors
155+
"""
156+
157+
158+
def create_missing_test_data_files(test_dir):
159+
"""
160+
Create missing copyright test data files in a `test_dir` directory.
161+
162+
Each test consist of a pair of files:
163+
- a test file.
164+
- a data file with the same name as a test file and a '.yml' extension added.
165+
"""
166+
for top, _, files in os.walk(test_dir):
167+
for tfile in files:
168+
if tfile.endswith('~'):
169+
continue
170+
file_path = path.abspath(path.join(top, tfile))
171+
172+
if tfile.endswith('.yml'):
173+
data_file_path = file_path
174+
else:
175+
data_file_path = file_path + '.yml'
176+
177+
if not path.exists(data_file_path):
178+
with open(data_file_path, "w") as tfo:
179+
tfo.write(empty_data_file)
180+
181+
145182
def as_sorted_mapping(counter):
146183
"""
147184
Return a list of ordered mapping of {value:val, count:cnt} built from a

tests/cluecode/test_copyrights.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class TestCopyrightDataDriven(FileBasedTesting):
3131
pass
3232

3333

34-
build_tests(copyright_tests=load_copyright_tests(
35-
generate_missing=REGEN_TEST_FIXTURES),
34+
build_tests(
35+
copyright_tests=load_copyright_tests(generate_missing=REGEN_TEST_FIXTURES),
3636
clazz=TestCopyrightDataDriven,
3737
regen=REGEN_TEST_FIXTURES,
3838
)

0 commit comments

Comments
 (0)