diff options
author | Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> | 2021-12-15 17:08:13 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-12-20 15:29:01 +0000 |
commit | c39e6712939948365b49c2c61fa8e72eff198479 (patch) | |
tree | 6c4d44e92c5f94b3a3d432472f53ff749a330018 /meta/lib | |
parent | 24a800ff7069848974380d28eab75fd8d9e3f5b4 (diff) | |
download | poky-c39e6712939948365b49c2c61fa8e72eff198479.tar.gz |
selftest: recipetool: Add test for handle_license_vars function
(From OE-Core rev: cfe72844713c79484fb432915672d9f5f1ff0c25)
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/recipetool.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py index 1c73b2c5e0..9db1ddb532 100644 --- a/meta/lib/oeqa/selftest/cases/recipetool.py +++ b/meta/lib/oeqa/selftest/cases/recipetool.py | |||
@@ -592,6 +592,68 @@ class RecipetoolTests(RecipetoolBase): | |||
592 | with open(srcfile, 'w') as fh: | 592 | with open(srcfile, 'w') as fh: |
593 | fh.writelines(plugincontent) | 593 | fh.writelines(plugincontent) |
594 | 594 | ||
595 | def test_recipetool_handle_license_vars(self): | ||
596 | from create import handle_license_vars | ||
597 | from unittest.mock import Mock | ||
598 | |||
599 | commonlicdir = get_bb_var('COMMON_LICENSE_DIR') | ||
600 | |||
601 | d = bb.tinfoil.TinfoilDataStoreConnector | ||
602 | d.getVar = Mock(return_value=commonlicdir) | ||
603 | |||
604 | srctree = tempfile.mkdtemp(prefix='recipetoolqa') | ||
605 | self.track_for_cleanup(srctree) | ||
606 | |||
607 | # Multiple licenses | ||
608 | licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0'] | ||
609 | for licence in licenses: | ||
610 | shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence)) | ||
611 | # Duplicate license | ||
612 | shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE')) | ||
613 | |||
614 | extravalues = { | ||
615 | # Duplicate and missing licenses | ||
616 | 'LICENSE': 'Zlib & BSD-2-Clause & Zlib', | ||
617 | 'LIC_FILES_CHKSUM': [ | ||
618 | 'file://README.md;md5=0123456789abcdef0123456789abcd' | ||
619 | ] | ||
620 | } | ||
621 | lines_before = [] | ||
622 | handled = [] | ||
623 | licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d) | ||
624 | expected_lines_before = [ | ||
625 | '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is', | ||
626 | '# your responsibility to verify that the values are complete and correct.', | ||
627 | '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib', | ||
628 | '#', | ||
629 | '# NOTE: multiple licenses have been detected; they have been separated with &', | ||
630 | '# in the LICENSE value for now since it is a reasonable assumption that all', | ||
631 | '# of the licenses apply. If instead there is a choice between the multiple', | ||
632 | '# licenses then you should change the value to separate the licenses with |', | ||
633 | '# instead of &. If there is any doubt, check the accompanying documentation', | ||
634 | '# to determine which situation is applicable.', | ||
635 | 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"', | ||
636 | 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n' | ||
637 | ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n' | ||
638 | ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n' | ||
639 | ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n' | ||
640 | ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n' | ||
641 | ' file://README.md;md5=0123456789abcdef0123456789abcd"', | ||
642 | '' | ||
643 | ] | ||
644 | self.assertEqual(lines_before, expected_lines_before) | ||
645 | expected_licvalues = [ | ||
646 | ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'), | ||
647 | ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'), | ||
648 | ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9'), | ||
649 | ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'), | ||
650 | ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302') | ||
651 | ] | ||
652 | self.assertEqual(handled, [('license', expected_licvalues)]) | ||
653 | self.assertEqual(extravalues, {}) | ||
654 | self.assertEqual(licvalues, expected_licvalues) | ||
655 | |||
656 | |||
595 | def test_recipetool_split_pkg_licenses(self): | 657 | def test_recipetool_split_pkg_licenses(self): |
596 | from create import split_pkg_licenses | 658 | from create import split_pkg_licenses |
597 | licvalues = [ | 659 | licvalues = [ |