|
15 | 15 | # SPDX-License-Identifier: Apache-2.0 |
16 | 16 | # Copyright (c) OWASP Foundation. All Rights Reserved. |
17 | 17 |
|
| 18 | +from os import mkdir |
18 | 19 | from os.path import join |
19 | 20 | from tempfile import TemporaryDirectory |
20 | 21 | from unittest import TestCase |
@@ -53,7 +54,25 @@ def test_project2licenses_license_dict_file(self) -> None: |
53 | 54 | } |
54 | 55 | lfac = LicenseFactory() |
55 | 56 | with TemporaryDirectory() as tmpdir: |
56 | | - with open(join(tmpdir, project['license']['file']), 'w') as tf: |
| 57 | + with open(join(tmpdir, 'license.txt'), 'w') as tf: |
| 58 | + tf.write('File license text') |
| 59 | + licenses = list(project2licenses(project, lfac, fpath=join(tmpdir, 'pyproject.toml'))) |
| 60 | + self.assertEqual(len(licenses), 1) |
| 61 | + lic = licenses[0] |
| 62 | + self.assertIsInstance(lic, DisjunctiveLicense) |
| 63 | + self.assertIs(lic.text.encoding, Encoding.BASE_64) |
| 64 | + self.assertEqual(lic.text.content, 'RmlsZSBsaWNlbnNlIHRleHQ=') |
| 65 | + self.assertEqual(lic.acknowledgement, LicenseAcknowledgement.DECLARED) |
| 66 | + |
| 67 | + def test_project2licenses_license_dict_file_in_subfolder(self) -> None: |
| 68 | + project = { |
| 69 | + 'name': 'testpkg', |
| 70 | + 'license': {'file': 'foo/license.txt'}, |
| 71 | + } |
| 72 | + lfac = LicenseFactory() |
| 73 | + with TemporaryDirectory() as tmpdir: |
| 74 | + mkdir(join(tmpdir, 'foo')) |
| 75 | + with open(join(tmpdir, 'foo', 'license.txt'), 'w') as tf: |
57 | 76 | tf.write('File license text') |
58 | 77 | licenses = list(project2licenses(project, lfac, fpath=join(tmpdir, 'pyproject.toml'))) |
59 | 78 | self.assertEqual(len(licenses), 1) |
|
0 commit comments