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 10:23:22 +0000 |
commit | d535aba974d47802c80ea1f9c678c0e8351523bb (patch) | |
tree | 962fc0721d8d9495e0450dceca26318ba3567190 /meta/lib/oe | |
parent | 94c29c100873fd8606ad60f194c9b9e7c7a71e85 (diff) | |
download | poky-d535aba974d47802c80ea1f9c678c0e8351523bb.tar.gz |
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 ]
(From OE-Core rev: 2001979ad41e6fdd5a37b0f90a96708f39c9df07)
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r-- | meta/lib/oe/tests/__init__.py | 0 | ||||
-rw-r--r-- | meta/lib/oe/tests/test_elf.py | 21 | ||||
-rw-r--r-- | meta/lib/oe/tests/test_license.py | 68 | ||||
-rw-r--r-- | meta/lib/oe/tests/test_path.py | 89 | ||||
-rw-r--r-- | meta/lib/oe/tests/test_types.py | 62 | ||||
-rw-r--r-- | meta/lib/oe/tests/test_utils.py | 51 |
6 files changed, 0 insertions, 291 deletions
diff --git a/meta/lib/oe/tests/__init__.py b/meta/lib/oe/tests/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 --- a/meta/lib/oe/tests/__init__.py +++ /dev/null | |||
diff --git a/meta/lib/oe/tests/test_elf.py b/meta/lib/oe/tests/test_elf.py deleted file mode 100644 index 1f59037ed9..0000000000 --- a/meta/lib/oe/tests/test_elf.py +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | import unittest | ||
2 | import oe.qa | ||
3 | |||
4 | class TestElf(unittest.TestCase): | ||
5 | def test_machine_name(self): | ||
6 | """ | ||
7 | Test elf_machine_to_string() | ||
8 | """ | ||
9 | self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC") | ||
10 | self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86") | ||
11 | self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS") | ||
12 | self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC") | ||
13 | self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM") | ||
14 | self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH") | ||
15 | self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64") | ||
16 | self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64") | ||
17 | self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64") | ||
18 | |||
19 | self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown (0)") | ||
20 | self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF), "Unknown (3735928559)") | ||
21 | self.assertEqual(oe.qa.elf_machine_to_string("foobar"), "Unknown ('foobar')") | ||
diff --git a/meta/lib/oe/tests/test_license.py b/meta/lib/oe/tests/test_license.py deleted file mode 100644 index c388886184..0000000000 --- a/meta/lib/oe/tests/test_license.py +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | import unittest | ||
2 | import oe.license | ||
3 | |||
4 | class SeenVisitor(oe.license.LicenseVisitor): | ||
5 | def __init__(self): | ||
6 | self.seen = [] | ||
7 | oe.license.LicenseVisitor.__init__(self) | ||
8 | |||
9 | def visit_Str(self, node): | ||
10 | self.seen.append(node.s) | ||
11 | |||
12 | class TestSingleLicense(unittest.TestCase): | ||
13 | licenses = [ | ||
14 | "GPLv2", | ||
15 | "LGPL-2.0", | ||
16 | "Artistic", | ||
17 | "MIT", | ||
18 | "GPLv3+", | ||
19 | "FOO_BAR", | ||
20 | ] | ||
21 | invalid_licenses = ["GPL/BSD"] | ||
22 | |||
23 | @staticmethod | ||
24 | def parse(licensestr): | ||
25 | visitor = SeenVisitor() | ||
26 | visitor.visit_string(licensestr) | ||
27 | return visitor.seen | ||
28 | |||
29 | def test_single_licenses(self): | ||
30 | for license in self.licenses: | ||
31 | licenses = self.parse(license) | ||
32 | self.assertListEqual(licenses, [license]) | ||
33 | |||
34 | def test_invalid_licenses(self): | ||
35 | for license in self.invalid_licenses: | ||
36 | with self.assertRaises(oe.license.InvalidLicense) as cm: | ||
37 | self.parse(license) | ||
38 | self.assertEqual(cm.exception.license, license) | ||
39 | |||
40 | class TestSimpleCombinations(unittest.TestCase): | ||
41 | tests = { | ||
42 | "FOO&BAR": ["FOO", "BAR"], | ||
43 | "BAZ & MOO": ["BAZ", "MOO"], | ||
44 | "ALPHA|BETA": ["ALPHA"], | ||
45 | "BAZ&MOO|FOO": ["FOO"], | ||
46 | "FOO&BAR|BAZ": ["FOO", "BAR"], | ||
47 | } | ||
48 | preferred = ["ALPHA", "FOO", "BAR"] | ||
49 | |||
50 | def test_tests(self): | ||
51 | def choose(a, b): | ||
52 | if all(lic in self.preferred for lic in b): | ||
53 | return b | ||
54 | else: | ||
55 | return a | ||
56 | |||
57 | for license, expected in self.tests.items(): | ||
58 | licenses = oe.license.flattened_licenses(license, choose) | ||
59 | self.assertListEqual(licenses, expected) | ||
60 | |||
61 | class TestComplexCombinations(TestSimpleCombinations): | ||
62 | tests = { | ||
63 | "FOO & (BAR | BAZ)&MOO": ["FOO", "BAR", "MOO"], | ||
64 | "(ALPHA|(BETA&THETA)|OMEGA)&DELTA": ["OMEGA", "DELTA"], | ||
65 | "((ALPHA|BETA)&FOO)|BAZ": ["BETA", "FOO"], | ||
66 | "(GPL-2.0|Proprietary)&BSD-4-clause&MIT": ["GPL-2.0", "BSD-4-clause", "MIT"], | ||
67 | } | ||
68 | preferred = ["BAR", "OMEGA", "BETA", "GPL-2.0"] | ||
diff --git a/meta/lib/oe/tests/test_path.py b/meta/lib/oe/tests/test_path.py deleted file mode 100644 index 44d068143e..0000000000 --- a/meta/lib/oe/tests/test_path.py +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | import unittest | ||
2 | import oe, oe.path | ||
3 | import tempfile | ||
4 | import os | ||
5 | import errno | ||
6 | import shutil | ||
7 | |||
8 | class TestRealPath(unittest.TestCase): | ||
9 | DIRS = [ "a", "b", "etc", "sbin", "usr", "usr/bin", "usr/binX", "usr/sbin", "usr/include", "usr/include/gdbm" ] | ||
10 | FILES = [ "etc/passwd", "b/file" ] | ||
11 | LINKS = [ | ||
12 | ( "bin", "/usr/bin", "/usr/bin" ), | ||
13 | ( "binX", "usr/binX", "/usr/binX" ), | ||
14 | ( "c", "broken", "/broken" ), | ||
15 | ( "etc/passwd-1", "passwd", "/etc/passwd" ), | ||
16 | ( "etc/passwd-2", "passwd-1", "/etc/passwd" ), | ||
17 | ( "etc/passwd-3", "/etc/passwd-1", "/etc/passwd" ), | ||
18 | ( "etc/shadow-1", "/etc/shadow", "/etc/shadow" ), | ||
19 | ( "etc/shadow-2", "/etc/shadow-1", "/etc/shadow" ), | ||
20 | ( "prog-A", "bin/prog-A", "/usr/bin/prog-A" ), | ||
21 | ( "prog-B", "/bin/prog-B", "/usr/bin/prog-B" ), | ||
22 | ( "usr/bin/prog-C", "../../sbin/prog-C", "/sbin/prog-C" ), | ||
23 | ( "usr/bin/prog-D", "/sbin/prog-D", "/sbin/prog-D" ), | ||
24 | ( "usr/binX/prog-E", "../sbin/prog-E", None ), | ||
25 | ( "usr/bin/prog-F", "../../../sbin/prog-F", "/sbin/prog-F" ), | ||
26 | ( "loop", "a/loop", None ), | ||
27 | ( "a/loop", "../loop", None ), | ||
28 | ( "b/test", "file/foo", "/b/file/foo" ), | ||
29 | ] | ||
30 | |||
31 | LINKS_PHYS = [ | ||
32 | ( "./", "/", "" ), | ||
33 | ( "binX/prog-E", "/usr/sbin/prog-E", "/sbin/prog-E" ), | ||
34 | ] | ||
35 | |||
36 | EXCEPTIONS = [ | ||
37 | ( "loop", errno.ELOOP ), | ||
38 | ( "b/test", errno.ENOENT ), | ||
39 | ] | ||
40 | |||
41 | def __del__(self): | ||
42 | try: | ||
43 | #os.system("tree -F %s" % self.tmpdir) | ||
44 | shutil.rmtree(self.tmpdir) | ||
45 | except: | ||
46 | pass | ||
47 | |||
48 | def setUp(self): | ||
49 | self.tmpdir = tempfile.mkdtemp(prefix = "oe-test_path") | ||
50 | self.root = os.path.join(self.tmpdir, "R") | ||
51 | |||
52 | os.mkdir(os.path.join(self.tmpdir, "_real")) | ||
53 | os.symlink("_real", self.root) | ||
54 | |||
55 | for d in self.DIRS: | ||
56 | os.mkdir(os.path.join(self.root, d)) | ||
57 | for f in self.FILES: | ||
58 | open(os.path.join(self.root, f), "w") | ||
59 | for l in self.LINKS: | ||
60 | os.symlink(l[1], os.path.join(self.root, l[0])) | ||
61 | |||
62 | def __realpath(self, file, use_physdir, assume_dir = True): | ||
63 | return oe.path.realpath(os.path.join(self.root, file), self.root, | ||
64 | use_physdir, assume_dir = assume_dir) | ||
65 | |||
66 | def test_norm(self): | ||
67 | for l in self.LINKS: | ||
68 | if l[2] == None: | ||
69 | continue | ||
70 | |||
71 | target_p = self.__realpath(l[0], True) | ||
72 | target_l = self.__realpath(l[0], False) | ||
73 | |||
74 | if l[2] != False: | ||
75 | self.assertEqual(target_p, target_l) | ||
76 | self.assertEqual(l[2], target_p[len(self.root):]) | ||
77 | |||
78 | def test_phys(self): | ||
79 | for l in self.LINKS_PHYS: | ||
80 | target_p = self.__realpath(l[0], True) | ||
81 | target_l = self.__realpath(l[0], False) | ||
82 | |||
83 | self.assertEqual(l[1], target_p[len(self.root):]) | ||
84 | self.assertEqual(l[2], target_l[len(self.root):]) | ||
85 | |||
86 | def test_loop(self): | ||
87 | for e in self.EXCEPTIONS: | ||
88 | self.assertRaisesRegex(OSError, r'\[Errno %u\]' % e[1], | ||
89 | self.__realpath, e[0], False, False) | ||
diff --git a/meta/lib/oe/tests/test_types.py b/meta/lib/oe/tests/test_types.py deleted file mode 100644 index 367cc30e45..0000000000 --- a/meta/lib/oe/tests/test_types.py +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | import unittest | ||
2 | from oe.maketype import create, factory | ||
3 | |||
4 | class TestTypes(unittest.TestCase): | ||
5 | def assertIsInstance(self, obj, cls): | ||
6 | return self.assertTrue(isinstance(obj, cls)) | ||
7 | |||
8 | def assertIsNot(self, obj, other): | ||
9 | return self.assertFalse(obj is other) | ||
10 | |||
11 | def assertFactoryCreated(self, value, type, **flags): | ||
12 | cls = factory(type) | ||
13 | self.assertIsNot(cls, None) | ||
14 | self.assertIsInstance(create(value, type, **flags), cls) | ||
15 | |||
16 | class TestBooleanType(TestTypes): | ||
17 | def test_invalid(self): | ||
18 | self.assertRaises(ValueError, create, '', 'boolean') | ||
19 | self.assertRaises(ValueError, create, 'foo', 'boolean') | ||
20 | self.assertRaises(TypeError, create, object(), 'boolean') | ||
21 | |||
22 | def test_true(self): | ||
23 | self.assertTrue(create('y', 'boolean')) | ||
24 | self.assertTrue(create('yes', 'boolean')) | ||
25 | self.assertTrue(create('1', 'boolean')) | ||
26 | self.assertTrue(create('t', 'boolean')) | ||
27 | self.assertTrue(create('true', 'boolean')) | ||
28 | self.assertTrue(create('TRUE', 'boolean')) | ||
29 | self.assertTrue(create('truE', 'boolean')) | ||
30 | |||
31 | def test_false(self): | ||
32 | self.assertFalse(create('n', 'boolean')) | ||
33 | self.assertFalse(create('no', 'boolean')) | ||
34 | self.assertFalse(create('0', 'boolean')) | ||
35 | self.assertFalse(create('f', 'boolean')) | ||
36 | self.assertFalse(create('false', 'boolean')) | ||
37 | self.assertFalse(create('FALSE', 'boolean')) | ||
38 | self.assertFalse(create('faLse', 'boolean')) | ||
39 | |||
40 | def test_bool_equality(self): | ||
41 | self.assertEqual(create('n', 'boolean'), False) | ||
42 | self.assertNotEqual(create('n', 'boolean'), True) | ||
43 | self.assertEqual(create('y', 'boolean'), True) | ||
44 | self.assertNotEqual(create('y', 'boolean'), False) | ||
45 | |||
46 | class TestList(TestTypes): | ||
47 | def assertListEqual(self, value, valid, sep=None): | ||
48 | obj = create(value, 'list', separator=sep) | ||
49 | self.assertEqual(obj, valid) | ||
50 | if sep is not None: | ||
51 | self.assertEqual(obj.separator, sep) | ||
52 | self.assertEqual(str(obj), obj.separator.join(obj)) | ||
53 | |||
54 | def test_list_nosep(self): | ||
55 | testlist = ['alpha', 'beta', 'theta'] | ||
56 | self.assertListEqual('alpha beta theta', testlist) | ||
57 | self.assertListEqual('alpha beta\ttheta', testlist) | ||
58 | self.assertListEqual('alpha', ['alpha']) | ||
59 | |||
60 | def test_list_usersep(self): | ||
61 | self.assertListEqual('foo:bar', ['foo', 'bar'], ':') | ||
62 | self.assertListEqual('foo:bar:baz', ['foo', 'bar', 'baz'], ':') | ||
diff --git a/meta/lib/oe/tests/test_utils.py b/meta/lib/oe/tests/test_utils.py deleted file mode 100644 index 5d9ac52e7d..0000000000 --- a/meta/lib/oe/tests/test_utils.py +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | import unittest | ||
2 | from oe.utils import packages_filter_out_system | ||
3 | |||
4 | class TestPackagesFilterOutSystem(unittest.TestCase): | ||
5 | def test_filter(self): | ||
6 | """ | ||
7 | Test that oe.utils.packages_filter_out_system works. | ||
8 | """ | ||
9 | try: | ||
10 | import bb | ||
11 | except ImportError: | ||
12 | self.skipTest("Cannot import bb") | ||
13 | |||
14 | d = bb.data_smart.DataSmart() | ||
15 | d.setVar("PN", "foo") | ||
16 | |||
17 | d.setVar("PACKAGES", "foo foo-doc foo-dev") | ||
18 | pkgs = packages_filter_out_system(d) | ||
19 | self.assertEqual(pkgs, []) | ||
20 | |||
21 | d.setVar("PACKAGES", "foo foo-doc foo-data foo-dev") | ||
22 | pkgs = packages_filter_out_system(d) | ||
23 | self.assertEqual(pkgs, ["foo-data"]) | ||
24 | |||
25 | d.setVar("PACKAGES", "foo foo-locale-en-gb") | ||
26 | pkgs = packages_filter_out_system(d) | ||
27 | self.assertEqual(pkgs, []) | ||
28 | |||
29 | d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb") | ||
30 | pkgs = packages_filter_out_system(d) | ||
31 | self.assertEqual(pkgs, ["foo-data"]) | ||
32 | |||
33 | |||
34 | class TestTrimVersion(unittest.TestCase): | ||
35 | def test_version_exception(self): | ||
36 | with self.assertRaises(TypeError): | ||
37 | trim_version(None, 2) | ||
38 | with self.assertRaises(TypeError): | ||
39 | trim_version((1, 2, 3), 2) | ||
40 | |||
41 | def test_num_exception(self): | ||
42 | with self.assertRaises(ValueError): | ||
43 | trim_version("1.2.3", 0) | ||
44 | with self.assertRaises(ValueError): | ||
45 | trim_version("1.2.3", -1) | ||
46 | |||
47 | def test_valid(self): | ||
48 | self.assertEqual(trim_version("1.2.3", 1), "1") | ||
49 | self.assertEqual(trim_version("1.2.3", 2), "1.2") | ||
50 | self.assertEqual(trim_version("1.2.3", 3), "1.2.3") | ||
51 | self.assertEqual(trim_version("1.2.3", 4), "1.2.3") | ||