diff options
| author | Ross Burton <ross.burton@intel.com> | 2016-12-13 16:31:02 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-12-16 08:30:00 +0000 |
| commit | 2001979ad41e6fdd5a37b0f90a96708f39c9df07 (patch) | |
| tree | 62a425dfba8a12c5086d11622802aa72eeea421f /meta/lib/oeqa/selftest/oelib/license.py | |
| parent | a8e7c5b415b99973c39a7ddd57cae45695fb0119 (diff) | |
| download | openembedded-core-2001979ad41e6fdd5a37b0f90a96708f39c9df07.tar.gz openembedded-core-2001979ad41e6fdd5a37b0f90a96708f39c9df07.tar.bz2 openembedded-core-2001979ad41e6fdd5a37b0f90a96708f39c9df07.zip | |
oeqa: move lib/oe tests to oe-selftest
These tests don't get ran often (as demonstrated by the fact that some were not
ported to Python 3), so move them to oeqa/selftest so they get executed
frequently and can be extended easily.
[ YOCTO #7376 ]
Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'meta/lib/oeqa/selftest/oelib/license.py')
| -rw-r--r-- | meta/lib/oeqa/selftest/oelib/license.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/oelib/license.py b/meta/lib/oeqa/selftest/oelib/license.py new file mode 100644 index 0000000000..c388886184 --- /dev/null +++ b/meta/lib/oeqa/selftest/oelib/license.py @@ -0,0 +1,68 @@ +import unittest +import oe.license + +class SeenVisitor(oe.license.LicenseVisitor): + def __init__(self): + self.seen = [] + oe.license.LicenseVisitor.__init__(self) + + def visit_Str(self, node): + self.seen.append(node.s) + +class TestSingleLicense(unittest.TestCase): + licenses = [ + "GPLv2", + "LGPL-2.0", + "Artistic", + "MIT", + "GPLv3+", + "FOO_BAR", + ] + invalid_licenses = ["GPL/BSD"] + + @staticmethod + def parse(licensestr): + visitor = SeenVisitor() + visitor.visit_string(licensestr) + return visitor.seen + + def test_single_licenses(self): + for license in self.licenses: + licenses = self.parse(license) + self.assertListEqual(licenses, [license]) + + def test_invalid_licenses(self): + for license in self.invalid_licenses: + with self.assertRaises(oe.license.InvalidLicense) as cm: + self.parse(license) + self.assertEqual(cm.exception.license, license) + +class TestSimpleCombinations(unittest.TestCase): + tests = { + "FOO&BAR": ["FOO", "BAR"], + "BAZ & MOO": ["BAZ", "MOO"], + "ALPHA|BETA": ["ALPHA"], + "BAZ&MOO|FOO": ["FOO"], + "FOO&BAR|BAZ": ["FOO", "BAR"], + } + preferred = ["ALPHA", "FOO", "BAR"] + + def test_tests(self): + def choose(a, b): + if all(lic in self.preferred for lic in b): + return b + else: + return a + + for license, expected in self.tests.items(): + licenses = oe.license.flattened_licenses(license, choose) + self.assertListEqual(licenses, expected) + +class TestComplexCombinations(TestSimpleCombinations): + tests = { + "FOO & (BAR | BAZ)&MOO": ["FOO", "BAR", "MOO"], + "(ALPHA|(BETA&THETA)|OMEGA)&DELTA": ["OMEGA", "DELTA"], + "((ALPHA|BETA)&FOO)|BAZ": ["BETA", "FOO"], + "(GPL-2.0|Proprietary)&BSD-4-clause&MIT": ["GPL-2.0", "BSD-4-clause", "MIT"], + } + preferred = ["BAR", "OMEGA", "BETA", "GPL-2.0"] |
