|
21 | 21 | from testing_utils import get_test_loc |
22 | 22 | from testing_utils import get_temp_file |
23 | 23 |
|
| 24 | +from attributecode import INFO |
24 | 25 | from attributecode import attrib |
| 26 | +from attributecode import gen |
25 | 27 | from attributecode import model |
26 | 28 |
|
27 | 29 |
|
@@ -135,6 +137,76 @@ def test_lic_key_name_sync(self): |
135 | 137 |
|
136 | 138 | assert f1 == f2 |
137 | 139 |
|
| 140 | + """ |
| 141 | + def test_custom_template(self): |
| 142 | + test_file = get_test_loc('test_attrib/scancode_custom_template/clean-text-0.3.0-mod-lceupi.json') |
| 143 | + custom_template = get_test_loc('test_attrib/scancode_custom_template/scancode.template') |
| 144 | + errors, abouts = gen.load_inventory(test_file, scancode=True) |
| 145 | + expected_errors = [(40, 'Field about_resource: Unable to verify path: isc_lic.py: No base directory provided'), (30, "Field license_key: ignored duplicated list value: 'isc'"), (30, "Field license_name: ignored duplicated list value: 'ISC License'")] |
| 146 | + result = [(level, e) for level, e in errors if level > INFO] |
| 147 | + assert expected_errors == result |
| 148 | + #assert not errors |
| 149 | +
|
| 150 | + lic_dict = {'isc': {'key': 'isc', 'short_name': 'ISC License', 'name': 'ISC License', |
| 151 | + 'category': 'Permissive', 'owner': 'ISC - Internet Systems Consortium', |
| 152 | + 'homepage_url': 'https://www.isc.org/software/license', 'notes': 'Per SPDX.org, this license is OSI certified.', |
| 153 | + 'spdx_license_key': 'ISC', 'text_urls': ['http://fedoraproject.org/wiki/Licensing:MIT#Old_Style_with_legal_disclaimer_2', 'http://openbsd.wikia.com/wiki/OpenBSD%27s_BSD_license', 'http://opensource.org/licenses/isc-license.txt', 'https://www.isc.org/software/license'], |
| 154 | + 'osi_url': 'http://opensource.org/licenses/isc-license.txt', 'other_urls': ['http://openbsd.wikia.com/wiki/OpenBSD%27s_BSD_license', 'http://www.isc.org/software/license', 'http://www.opensource.org/licenses/ISC', 'https://opensource.org/licenses/ISC', 'https://www.isc.org/downloads/software-support-policy/isc-license/', 'https://www.isc.org/isc-license-1.0.html'], |
| 155 | + 'license_text': 'Permission to use, copy, modify, and/or distribute this software for any purpose\nwith or without fee is hereby granted, provided that the above copyright notice\nand this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\nFITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\nOF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\nTORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\nTHIS SOFTWARE.\n'}} |
| 156 | + is_about_input = False |
| 157 | + errors, result = attrib.generate_from_file(abouts, is_about_input, lic_dict, min_license_score=0, template_loc=custom_template) |
| 158 | + expected_errors = [] |
| 159 | + #result = [(level, e) for level, e in errors if level > INFO] |
| 160 | + #assert expected_errors == result |
| 161 | + assert not errors |
| 162 | +
|
| 163 | + expected_file = get_test_loc( |
| 164 | + 'test_attrib/scancode_custom_template/expect.html') |
| 165 | + with open(expected_file) as exp: |
| 166 | + expected = exp.read() |
| 167 | +
|
| 168 | + # strip the timestamp: the timestamp is wrapped in italic block |
| 169 | + result = remove_timestamp(result) |
| 170 | + expected = remove_timestamp(expected) |
| 171 | + assert expected == result |
| 172 | +
|
| 173 | + def test_generate_with_default_template(self): |
| 174 | + test_file = get_test_loc('test_attrib/default_template/simple_sample.csv') |
| 175 | + errors, abouts = util.load_inventory(test_file) |
| 176 | + assert not errors |
| 177 | +
|
| 178 | + lic_dict = {'bsd-new': |
| 179 | + {'key': 'bsd-new', 'short_name': 'BSD-3-Clause', 'name': 'BSD-3-Clause', |
| 180 | + 'category': 'Permissive', 'owner': 'Regents of the University of California', |
| 181 | + 'homepage_url': 'http://www.opensource.org/licenses/BSD-3-Clause', |
| 182 | + 'notes': 'Per SPDX.org, this license is OSI certified.', |
| 183 | + 'spdx_license_key': 'BSD-3-Clause', 'osi_license_key': 'BSD-3', |
| 184 | + 'text_urls': ['http://www.opensource.org/licenses/BSD-3-Clause'], |
| 185 | + 'osi_url': 'http://www.opensource.org/licenses/BSD-3-Clause', |
| 186 | + 'other_urls': ['http://framework.zend.com/license/new-bsd', 'https://opensource.org/licenses/BSD-3-Clause'], |
| 187 | + 'license_text': 'Redistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\nRedistributions of source code must retain the above copyright notice, this list\nof conditions and the following disclaimer.\n\nRedistributions in binary form must reproduce the above copyright notice, this\nlist of conditions and the following disclaimer in the documentation and/or\nother materials provided with the distribution.\n\nNeither the name of the ORGANIZATION nor the names of its contributors may be\nused to endorse or promote products derived from this software without specific\nprior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS\nBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\nCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\nGOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\nHOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\nLIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\nTHE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.'}, |
| 188 | + 'mit': {'key': 'mit', 'short_name': 'MIT License', 'name': 'MIT License', |
| 189 | + 'category': 'Permissive', 'owner': 'MIT', |
| 190 | + 'homepage_url': 'http://opensource.org/licenses/mit-license.php', |
| 191 | + 'notes': 'Per SPDX.org, this license is OSI certified.', 'spdx_license_key': 'MIT', |
| 192 | + 'text_urls': ['http://opensource.org/licenses/mit-license.php'], |
| 193 | + 'osi_url': 'http://www.opensource.org/licenses/MIT', |
| 194 | + 'other_urls': ['https://opensource.com/article/18/3/patent-grant-mit-license', 'https://opensource.com/article/19/4/history-mit-license', 'https://opensource.org/licenses/MIT'], |
| 195 | + 'license_text': 'Permission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n"Software"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'} |
| 196 | + } |
| 197 | + error, result = attrib.generate_from_file(abouts, lic_dict, min_license_score=0) |
| 198 | + assert not error |
| 199 | +
|
| 200 | + expected_file = get_test_loc( |
| 201 | + 'test_attrib/default_template/expect.html') |
| 202 | + with open(expected_file) as exp: |
| 203 | + expected = exp.read() |
| 204 | +
|
| 205 | + # strip the timestamp: the timestamp is wrapped in italic block |
| 206 | + result = remove_timestamp(result) |
| 207 | + expected = remove_timestamp(expected) |
| 208 | + assert expected == result |
| 209 | + """ |
138 | 210 |
|
139 | 211 | def remove_timestamp(html_text): |
140 | 212 | """ |
|
0 commit comments