aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/tests
diff options
context:
space:
mode:
authorChristopher Larson <kergoth@gmail.com>2011-12-04 20:03:37 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-12-08 15:23:00 +0000
commit20d4068045c76e9dc2aff0c152dd02d6a109c9dd (patch)
tree81733d8d174cc5d2951a874d599bfcdaaedc6b99 /meta/lib/oe/tests
parent36cc35b4cbb91049a63daa7c915f538047db0f76 (diff)
downloadopenembedded-core-20d4068045c76e9dc2aff0c152dd02d6a109c9dd.tar.gz
license: split license parsing into oe.license
In addition to moving this functionality to oe.license, makes the string preparation more picky before passing it off to the ast compilation. This ensures that LICENSE entries like 'GPL/BSD' are seen as invalid (due to the presence of the unsupported '/'). Signed-off-by: Christopher Larson <kergoth@gmail.com>
Diffstat (limited to 'meta/lib/oe/tests')
-rw-r--r--meta/lib/oe/tests/test_license.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/meta/lib/oe/tests/test_license.py b/meta/lib/oe/tests/test_license.py
new file mode 100644
index 0000000000..cb949fc76f
--- /dev/null
+++ b/meta/lib/oe/tests/test_license.py
@@ -0,0 +1,38 @@
+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)