Skip to contentSkip to conversation

oe-tests: Migrate tests from /oe/test to /oeqa/selftest/oe-tests

PATCH In review [email protected] 3 participants 11 messages Nov 15, 2016 – Dec 13, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): B6EBB6A4080

#1 lore raw

PATCH v2 1/1 oe-tests: Migrate tests from /oe/test to /oeqa/selftest/oe-tests

From: Jose Perez Carranza <[email protected]>

Currently the unittests for scripts on meta/lib/oe/tests are not being executed by any suite hence the best option is migrate them to meta/lib/oeqa/selftest/oelib-tests to be executed along with the selftest suite.

[YOCTO #7376]

---
 meta/lib/oe/tests/__init__.py                  |  0
 meta/lib/oe/tests/test_elf.py                  | 21 ------
 meta/lib/oe/tests/test_license.py              | 68 -------------------
 meta/lib/oe/tests/test_path.py                 | 89 -------------------------
 meta/lib/oe/tests/test_types.py                | 62 ------------------
 meta/lib/oe/tests/test_utils.py                | 51 ---------------
 meta/lib/oeqa/selftest/oelib-tests/__init__.py |  0
 meta/lib/oeqa/selftest/oelib-tests/elf.py      | 22 +++++++
 meta/lib/oeqa/selftest/oelib-tests/license.py  | 69 ++++++++++++++++++++
 meta/lib/oeqa/selftest/oelib-tests/path.py     | 90 ++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/oelib-tests/types.py    | 61 +++++++++++++++++
 meta/lib/oeqa/selftest/oelib-tests/utils.py    | 52 +++++++++++++++
 12 files changed, 294 insertions(+), 291 deletions(-)
 delete mode 100644 meta/lib/oe/tests/__init__.py
 delete mode 100644 meta/lib/oe/tests/test_elf.py
 delete mode 100644 meta/lib/oe/tests/test_license.py
 delete mode 100644 meta/lib/oe/tests/test_path.py
 delete mode 100644 meta/lib/oe/tests/test_types.py
 delete mode 100644 meta/lib/oe/tests/test_utils.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/__init__.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/elf.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/license.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/path.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/types.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/utils.py
meta/lib/oe/tests/__init__.py deleted +0 -0
deleted file mode 100644
index e69de29..0000000
meta/lib/oe/tests/test_elf.py deleted +0 -21
deleted file mode 100644
index 1f59037..0000000
@@ -1,21 +0,0 @@
-import unittest
-import oe.qa
-
-class TestElf(unittest.TestCase):
-    def test_machine_name(self):
-        """
-        Test elf_machine_to_string()
-        """
-        self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64")
-        self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64")
-
-        self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown (0)")
-        self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF), "Unknown (3735928559)")
-        self.assertEqual(oe.qa.elf_machine_to_string("foobar"), "Unknown ('foobar')")
meta/lib/oe/tests/test_license.py deleted +0 -68

68 lines not on this page · raw message

meta/lib/oe/tests/test_path.py deleted +0 -89

89 lines not on this page · raw message

meta/lib/oe/tests/test_types.py deleted +0 -62

62 lines not on this page · raw message

meta/lib/oe/tests/test_utils.py deleted +0 -51

51 lines not on this page · raw message

meta/lib/oeqa/selftest/oelib-tests/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
meta/lib/oeqa/selftest/oelib-tests/elf.py new file +22 -0
new file mode 100644
index 0000000..582d772
@@ -0,0 +1,22 @@
+from oeqa.selftest.base import oeSelfTest
+from oeqa.utils.decorators import testcase
+import oe.qa
+
+class TestElf(oeSelfTest):
+    def test_machine_name(self):
+        """
+        Test elf_machine_to_string()
+        """
+        self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64")
+        self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64")
+
+        self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown (0)")
+        self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF), "Unknown (3735928559)")
+        self.assertEqual(oe.qa.elf_machine_to_string("foobar"), "Unknown ('foobar')")
meta/lib/oeqa/selftest/oelib-tests/license.py new file +69 -0

69 lines not on this page · raw message

meta/lib/oeqa/selftest/oelib-tests/path.py new file +90 -0

90 lines not on this page · raw message

meta/lib/oeqa/selftest/oelib-tests/types.py new file +61 -0

61 lines not on this page · raw message

meta/lib/oeqa/selftest/oelib-tests/utils.py new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw
Quoted 2 lines · On 15 November 2016 at 16:24, <[email protected]> wrote:

+class TestPackagesFilterOutSystem(oeSelfTest):

As the tests don't need anything special that oeSelfTest provides, can they remain as testcase.TestCase instances? There's a lot of complication from oeSelfTest that isn't required.

Ross

#3 lore raw
Quoted 8 lines · Ross

On 15 November 2016 at 16:24, <[email protected] <mailto:[email protected]>> wrote:

+class TestPackagesFilterOutSystem(oeSelfTest):

As the tests don't need anything special that oeSelfTest provides, can they remain as testcase.TestCase instances? There's a lot of complication from oeSelfTest that isn't required.

In order to the test cases be recognized and executed as part of the suite they need to be in the same context of selftest hence be an instance of oeSelftest.

Quoted 1 line

Ross

#4 lore raw

PATCH v2 1/1 oe-tests: Migrate tests from /oe/test to /oeqa/selftest/oe-tests

Re-sending from the correct account (of mine).

From: Esquivel, Benjamin
Sent: Tuesday, November 15, 2016 12:38 PM
To: 'Jose Perez Carranza' <[email protected]>; 'Burton, Ross' <[email protected]>
Cc: 'OE-core' <[email protected]>
Subject: RE: [OE-core] [PATCH v2] oe-tests: Migrate tests from /oe/test to /oeqa/selftest/oe-tests

Apologies for the top posting.

The reason for the migration of the tests is for them to be included in the selftest execution. And for that execution, it needs to base off of the oeSelfTest class.

Benjamin

From: [email protected] <mailto:[email protected]> [mailto:[email protected]] On Behalf Of Jose Perez Carranza
Sent: Tuesday, November 15, 2016 12:09 PM
To: Burton, Ross <[email protected] <mailto:[email protected]> >
Cc: OE-core <[email protected] <mailto:[email protected]> >
Subject: Re: [OE-core] [PATCH v2] oe-tests: Migrate tests from /oe/test to /oeqa/selftest/oe-tests

On 11/15/2016 11:16 AM, Burton, Ross wrote:

On 15 November 2016 at 16:24, <[email protected] <mailto:[email protected]> > wrote:

+class TestPackagesFilterOutSystem(oeSelfTest):

As the tests don't need anything special that oeSelfTest provides, can they remain as testcase.TestCase instances? There's a lot of complication from oeSelfTest that isn't required.

In order to the test cases be recognized and executed as part of the suite they need to be in the same context of selftest hence be an instance of oeSelftest.

Ross

#5 lore raw
Quoted 5 lines · Benjamin Esquivel

The reason for the migration of the tests is for them to be included in the selftest execution. And for that execution, it needs to base off of the oeSelfTest class.

Sounds like a problem with the discovery if it mandates oeselftest. Is there a reason why it can't also execute bare unittests?

Ross

#6 lore raw
Quoted 10 lines · Ross

On 15 November 2016 at 19:10, Benjamin Esquivel <[email protected] <mailto:[email protected]>> wrote:

The reason for the migration of the tests is for them to be included in the selftest execution. And for that execution, it needs to base off of the oeSelfTest class.

Sounds like a problem with the discovery if it mandates oeselftest. Is there a reason why it can't also execute bare unittests?

You are right this is a problem on the suite right now AFAIK there
will pbe a fix for this on oeqa2 framework adding Marian and Anibal to the loop to give an in put on this.

Quoted 1 line

Ross

#7 lore raw
In reply to [email protected]

Looks good to me, thanks for sending the v2.

Quoted 16 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Tuesday, November 15, 2016 10:25 AM
To: [email protected]
Subject: [OE-core] [PATCH v2] oe-tests: Migrate tests from /oe/test to /oeqa/selftest/oe-tests

From: Jose Perez Carranza <[email protected]>

Currently the unittests for scripts on meta/lib/oe/tests are not being executed by any suite hence the best option is migrate them to meta/lib/oeqa/selftest/oelib-tests to be executed along with the selftest suite.

Quoted 8 lines

[YOCTO #7376]

---
 meta/lib/oe/tests/__init__.py                  |  0
 meta/lib/oe/tests/test_elf.py                  | 21 ------
 meta/lib/oe/tests/test_license.py              | 68 -------------------
 meta/lib/oe/tests/test_path.py                 | 89

-------------------------

Quoted 26 lines
 meta/lib/oe/tests/test_types.py                | 62 ------------------
 meta/lib/oe/tests/test_utils.py                | 51 ---------------
 meta/lib/oeqa/selftest/oelib-tests/__init__.py |  0
 meta/lib/oeqa/selftest/oelib-tests/elf.py      | 22 +++++++
 meta/lib/oeqa/selftest/oelib-tests/license.py  | 69
++++++++++++++++++++
 meta/lib/oeqa/selftest/oelib-tests/path.py     | 90
++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/oelib-tests/types.py    | 61 +++++++++++++++++
 meta/lib/oeqa/selftest/oelib-tests/utils.py    | 52 +++++++++++++++
 12 files changed, 294 insertions(+), 291 deletions(-)  delete mode 100644

meta/lib/oe/tests/__init__.py delete mode 100644 meta/lib/oe/tests/test_elf.py delete mode 100644 meta/lib/oe/tests/test_license.py delete mode 100644 meta/lib/oe/tests/test_path.py delete mode 100644 meta/lib/oe/tests/test_types.py delete mode 100644 meta/lib/oe/tests/test_utils.py create mode 100644 meta/lib/oeqa/selftest/oelib-tests/__init__.py

 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/elf.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/license.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/path.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/types.py
 create mode 100644 meta/lib/oeqa/selftest/oelib-tests/utils.py
meta/lib/oe/tests/__init__.py deleted +0 -0
deleted file mode 100644 index e69de29..0000000 diff --git
Quoted 1 line

a/meta/lib/oe/tests/test_elf.py b/meta/lib/oe/tests/test_elf.py deleted

file

Quoted 13 lines

mode 100644 index 1f59037..0000000

meta/lib/oe/tests/test_elf.py deleted +0 -9
@@ -1,21 +0,0 @@
-import unittest
-import oe.qa
-
-class TestElf(unittest.TestCase):
-    def test_machine_name(self):
-        """
-        Test elf_machine_to_string()
-        """
-        self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC")

meta/lib/oe/tests/test_elf.py line 19

Quoted 10 lines
meta/lib/oe/tests/test_elf.py deleted +0 -10
-        self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64")
-        self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64")
-        self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64")
-
-        self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown

(0)")

meta/lib/oe/tests/test_elf.py line 20

Quoted 1 line
meta/lib/oe/tests/test_elf.py deleted +0 -1
-        self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF),

"Unknown

Quoted 66 lines

(3735928559)")
- self.assertEqual(oe.qa.elf_machine_to_string("foobar"), "Unknown
('foobar')")

meta/lib/oe/tests/test_license.py deleted +0 -56
deleted file mode 100644
index c388886..0000000
@@ -1,68 +0,0 @@
-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
-

meta/lib/oe/tests/test_license.py line 66

Quoted 10 lines
meta/lib/oe/tests/test_license.py deleted +0 -10
-        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",

Quoted 9 lines

"MIT"],

meta/lib/oe/tests/test_license.py deleted +0 -2
-    }
-    preferred = ["BAR", "OMEGA", "BETA", "GPL-2.0"]
(quoted diff) +0 -0

b/meta/lib/oe/tests/test_path.py deleted file mode 100644 index 44d0681..0000000

meta/lib/oe/tests/test_path.py line 9

Quoted 9 lines
meta/lib/oe/tests/test_path.py deleted +0 -9
@@ -1,89 +0,0 @@
-import unittest
-import oe, oe.path
-import tempfile
-import os
-import errno
-import shutil
-
-class TestRealPath(unittest.TestCase):
-    DIRS = [ "a", "b", "etc", "sbin", "usr", "usr/bin", "usr/binX",

"usr/sbin",

Review

Quoted 150 lines

"usr/include", "usr/include/gdbm" ]

meta/lib/oe/tests/test_path.py deleted +0 -80
-    FILES = [ "etc/passwd", "b/file" ]
-    LINKS = [
-        ( "bin",             "/usr/bin",             "/usr/bin" ),
-        ( "binX",            "usr/binX",             "/usr/binX" ),
-        ( "c",               "broken",               "/broken" ),
-        ( "etc/passwd-1",    "passwd",               "/etc/passwd" ),
-        ( "etc/passwd-2",    "passwd-1",             "/etc/passwd" ),
-        ( "etc/passwd-3",    "/etc/passwd-1",        "/etc/passwd" ),
-        ( "etc/shadow-1",    "/etc/shadow",          "/etc/shadow" ),
-        ( "etc/shadow-2",    "/etc/shadow-1",        "/etc/shadow" ),
-        ( "prog-A",          "bin/prog-A",           "/usr/bin/prog-A" ),
-        ( "prog-B",          "/bin/prog-B",          "/usr/bin/prog-B" ),
-        ( "usr/bin/prog-C",  "../../sbin/prog-C",    "/sbin/prog-C" ),
-        ( "usr/bin/prog-D",  "/sbin/prog-D",         "/sbin/prog-D" ),
-        ( "usr/binX/prog-E", "../sbin/prog-E",       None ),
-        ( "usr/bin/prog-F",  "../../../sbin/prog-F", "/sbin/prog-F" ),
-        ( "loop",            "a/loop",               None ),
-        ( "a/loop",          "../loop",              None ),
-        ( "b/test",          "file/foo",             "/b/file/foo" ),
-    ]
-
-    LINKS_PHYS = [
-        ( "./",          "/",                "" ),
-        ( "binX/prog-E", "/usr/sbin/prog-E", "/sbin/prog-E" ),
-    ]
-
-    EXCEPTIONS = [
-        ( "loop",   errno.ELOOP ),
-        ( "b/test", errno.ENOENT ),
-    ]
-
-    def __del__(self):
-        try:
-            #os.system("tree -F %s" % self.tmpdir)
-            shutil.rmtree(self.tmpdir)
-        except:
-            pass
-
-    def setUp(self):
-        self.tmpdir = tempfile.mkdtemp(prefix = "oe-test_path")
-        self.root = os.path.join(self.tmpdir, "R")
-
-        os.mkdir(os.path.join(self.tmpdir, "_real"))
-        os.symlink("_real", self.root)
-
-        for d in self.DIRS:
-            os.mkdir(os.path.join(self.root, d))
-        for f in self.FILES:
-            open(os.path.join(self.root, f), "w")
-        for l in self.LINKS:
-            os.symlink(l[1], os.path.join(self.root, l[0]))
-
-    def __realpath(self, file, use_physdir, assume_dir = True):
-        return oe.path.realpath(os.path.join(self.root, file), self.root,
-                                use_physdir, assume_dir = assume_dir)
-
-    def test_norm(self):
-        for l in self.LINKS:
-            if l[2] == None:
-                continue
-
-            target_p = self.__realpath(l[0], True)
-            target_l = self.__realpath(l[0], False)
-
-            if l[2] != False:
-                self.assertEqual(target_p, target_l)
-                self.assertEqual(l[2], target_p[len(self.root):])
-
-    def test_phys(self):
-        for l in self.LINKS_PHYS:
-            target_p = self.__realpath(l[0], True)
-            target_l = self.__realpath(l[0], False)
-
-            self.assertEqual(l[1], target_p[len(self.root):])
-            self.assertEqual(l[2], target_l[len(self.root):])
-
-    def test_loop(self):
-        for e in self.EXCEPTIONS:
-            self.assertRaisesRegex(OSError, r'\[Errno %u\]' % e[1],
-                                    self.__realpath, e[0], False, False)
(quoted diff) +0 -0

b/meta/lib/oe/tests/test_types.py deleted file mode 100644 index 367cc30..0000000

meta/lib/oe/tests/test_types.py deleted +0 -62
@@ -1,62 +0,0 @@
-import unittest
-from oe.maketype import create, factory
-
-class TestTypes(unittest.TestCase):
-    def assertIsInstance(self, obj, cls):
-        return self.assertTrue(isinstance(obj, cls))
-
-    def assertIsNot(self, obj, other):
-        return self.assertFalse(obj is other)
-
-    def assertFactoryCreated(self, value, type, **flags):
-        cls = factory(type)
-        self.assertIsNot(cls, None)
-        self.assertIsInstance(create(value, type, **flags), cls)
-
-class TestBooleanType(TestTypes):
-    def test_invalid(self):
-        self.assertRaises(ValueError, create, '', 'boolean')
-        self.assertRaises(ValueError, create, 'foo', 'boolean')
-        self.assertRaises(TypeError, create, object(), 'boolean')
-
-    def test_true(self):
-        self.assertTrue(create('y', 'boolean'))
-        self.assertTrue(create('yes', 'boolean'))
-        self.assertTrue(create('1', 'boolean'))
-        self.assertTrue(create('t', 'boolean'))
-        self.assertTrue(create('true', 'boolean'))
-        self.assertTrue(create('TRUE', 'boolean'))
-        self.assertTrue(create('truE', 'boolean'))
-
-    def test_false(self):
-        self.assertFalse(create('n', 'boolean'))
-        self.assertFalse(create('no', 'boolean'))
-        self.assertFalse(create('0', 'boolean'))
-        self.assertFalse(create('f', 'boolean'))
-        self.assertFalse(create('false', 'boolean'))
-        self.assertFalse(create('FALSE', 'boolean'))
-        self.assertFalse(create('faLse', 'boolean'))
-
-    def test_bool_equality(self):
-        self.assertEqual(create('n', 'boolean'), False)
-        self.assertNotEqual(create('n', 'boolean'), True)
-        self.assertEqual(create('y', 'boolean'), True)
-        self.assertNotEqual(create('y', 'boolean'), False)
-
-class TestList(TestTypes):
-    def assertListEqual(self, value, valid, sep=None):
-        obj = create(value, 'list', separator=sep)
-        self.assertEqual(obj, valid)
-        if sep is not None:
-            self.assertEqual(obj.separator, sep)
-        self.assertEqual(str(obj), obj.separator.join(obj))
-
-    def test_list_nosep(self):
-        testlist = ['alpha', 'beta', 'theta']
-        self.assertListEqual('alpha beta theta', testlist)
-        self.assertListEqual('alpha  beta\ttheta', testlist)
-        self.assertListEqual('alpha', ['alpha'])
-
-    def test_list_usersep(self):
-        self.assertListEqual('foo:bar', ['foo', 'bar'], ':')
-        self.assertListEqual('foo:bar:baz', ['foo', 'bar', 'baz'], ':')
(quoted diff) +0 -0

b/meta/lib/oe/tests/test_utils.py

Quoted 75 lines

deleted file mode 100644 index 5d9ac52..0000000

meta/lib/oe/tests/test_utils.py deleted +0 -51
@@ -1,51 +0,0 @@
-import unittest
-from oe.utils import packages_filter_out_system
-
-class TestPackagesFilterOutSystem(unittest.TestCase):
-    def test_filter(self):
-        """
-        Test that oe.utils.packages_filter_out_system works.
-        """
-        try:
-            import bb
-        except ImportError:
-            self.skipTest("Cannot import bb")
-
-        d = bb.data_smart.DataSmart()
-        d.setVar("PN", "foo")
-
-        d.setVar("PACKAGES", "foo foo-doc foo-dev")
-        pkgs = packages_filter_out_system(d)
-        self.assertEqual(pkgs, [])
-
-        d.setVar("PACKAGES", "foo foo-doc foo-data foo-dev")
-        pkgs = packages_filter_out_system(d)
-        self.assertEqual(pkgs, ["foo-data"])
-
-        d.setVar("PACKAGES", "foo foo-locale-en-gb")
-        pkgs = packages_filter_out_system(d)
-        self.assertEqual(pkgs, [])
-
-        d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb")
-        pkgs = packages_filter_out_system(d)
-        self.assertEqual(pkgs, ["foo-data"])
-
-
-class TestTrimVersion(unittest.TestCase):
-    def test_version_exception(self):
-        with self.assertRaises(TypeError):
-            trim_version(None, 2)
-        with self.assertRaises(TypeError):
-            trim_version((1, 2, 3), 2)
-
-    def test_num_exception(self):
-        with self.assertRaises(ValueError):
-            trim_version("1.2.3", 0)
-        with self.assertRaises(ValueError):
-            trim_version("1.2.3", -1)
-
-    def test_valid(self):
-        self.assertEqual(trim_version("1.2.3", 1), "1")
-        self.assertEqual(trim_version("1.2.3", 2), "1.2")
-        self.assertEqual(trim_version("1.2.3", 3), "1.2.3")
-        self.assertEqual(trim_version("1.2.3", 4), "1.2.3")
meta/lib/oeqa/selftest/oelib-tests/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
meta/lib/oeqa/selftest/oelib-tests/elf.py new file +9 -0
new file mode 100644
index 0000000..582d772
@@ -0,0 +1,22 @@
+from oeqa.selftest.base import oeSelfTest from oeqa.utils.decorators
+import testcase import oe.qa
+
+class TestElf(oeSelfTest):
+    def test_machine_name(self):
+        """
+        Test elf_machine_to_string()
+        """
+        self.assertEqual(oe.qa.elf_machine_to_string(0x02), "SPARC")

meta/lib/oeqa/selftest/oelib-tests/elf.py line 19

Quoted 10 lines
meta/lib/oeqa/selftest/oelib-tests/elf.py new file +10 -0
+        self.assertEqual(oe.qa.elf_machine_to_string(0x03), "x86")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x08), "MIPS")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x14), "PowerPC")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x28), "ARM")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x2A), "SuperH")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x32), "IA-64")
+        self.assertEqual(oe.qa.elf_machine_to_string(0x3E), "x86-64")
+        self.assertEqual(oe.qa.elf_machine_to_string(0xB7), "AArch64")
+
+        self.assertEqual(oe.qa.elf_machine_to_string(0x00), "Unknown

(0)")

Quoted 88 lines
meta/lib/oeqa/selftest/oelib-tests/elf.py new file +1 -0
+        self.assertEqual(oe.qa.elf_machine_to_string(0xDEADBEEF),

"Unknown (3735928559)")

meta/lib/oeqa/selftest/oelib-tests/elf.py new file +2 -0
+        self.assertEqual(oe.qa.elf_machine_to_string("foobar"),
+ "Unknown ('foobar')")
meta/lib/oeqa/selftest/oelib-tests/license.py new file +67 -0
new file mode 100644
index 0000000..90bdf51
@@ -0,0 +1,69 @@
+import oe.license
+from oeqa.selftest.base import oeSelfTest from oeqa.utils.decorators
+import testcase
+
+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(oeSelfTest):
+    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(oeSelfTest):
+    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"],

meta/lib/oeqa/selftest/oelib-tests/license.py new file +2 -0
+    }
+    preferred = ["BAR", "OMEGA", "BETA", "GPL-2.0"]
meta/lib/oeqa/selftest/oelib-tests/path.py new file +0 -0
new file mode 100644
index 0000000..09b56cb

meta/lib/oeqa/selftest/oelib-tests/path.py line 6

Quoted 6 lines
meta/lib/oeqa/selftest/oelib-tests/path.py new file +6 -0
@@ -0,0 +1,90 @@
+from oeqa.selftest.base import oeSelfTest from oeqa.utils.decorators
+import testcase import oe, oe.path import tempfile import os import
+errno import shutil
+
+class TestRealPath(oeSelfTest):
+    DIRS = [ "a", "b", "etc", "sbin", "usr", "usr/bin", "usr/binX",

"usr/sbin",

Quoted 217 lines

"usr/include", "usr/include/gdbm" ]

meta/lib/oeqa/selftest/oelib-tests/path.py new file +81 -0
+    FILES = [ "etc/passwd", "b/file" ]
+    LINKS = [
+        ( "bin",             "/usr/bin",             "/usr/bin" ),
+        ( "binX",            "usr/binX",             "/usr/binX" ),
+        ( "c",               "broken",               "/broken" ),
+        ( "etc/passwd-1",    "passwd",               "/etc/passwd" ),
+        ( "etc/passwd-2",    "passwd-1",             "/etc/passwd" ),
+        ( "etc/passwd-3",    "/etc/passwd-1",        "/etc/passwd" ),
+        ( "etc/shadow-1",    "/etc/shadow",          "/etc/shadow" ),
+        ( "etc/shadow-2",    "/etc/shadow-1",        "/etc/shadow" ),
+        ( "prog-A",          "bin/prog-A",           "/usr/bin/prog-A" ),
+        ( "prog-B",          "/bin/prog-B",          "/usr/bin/prog-B" ),
+        ( "usr/bin/prog-C",  "../../sbin/prog-C",    "/sbin/prog-C" ),
+        ( "usr/bin/prog-D",  "/sbin/prog-D",         "/sbin/prog-D" ),
+        ( "usr/binX/prog-E", "../sbin/prog-E",       None ),
+        ( "usr/bin/prog-F",  "../../../sbin/prog-F", "/sbin/prog-F" ),
+        ( "loop",            "a/loop",               None ),
+        ( "a/loop",          "../loop",              None ),
+        ( "b/test",          "file/foo",             "/b/file/foo" ),
+    ]
+
+    LINKS_PHYS = [
+        ( "./",          "/",                "" ),
+        ( "binX/prog-E", "/usr/sbin/prog-E", "/sbin/prog-E" ),
+    ]
+
+    EXCEPTIONS = [
+        ( "loop",   errno.ELOOP ),
+        ( "b/test", errno.ENOENT ),
+    ]
+
+    def __del__(self):
+        try:
+            #os.system("tree -F %s" % self.tmpdir)
+            shutil.rmtree(self.tmpdir)
+        except:
+            pass
+
+    def setUp(self):
+        self.tmpdir = tempfile.mkdtemp(prefix = "oe-test_path")
+        self.root = os.path.join(self.tmpdir, "R")
+
+        os.mkdir(os.path.join(self.tmpdir, "_real"))
+        os.symlink("_real", self.root)
+
+        for d in self.DIRS:
+            os.mkdir(os.path.join(self.root, d))
+        for f in self.FILES:
+            open(os.path.join(self.root, f), "w")
+        for l in self.LINKS:
+            os.symlink(l[1], os.path.join(self.root, l[0]))
+
+    def __realpath(self, file, use_physdir, assume_dir = True):
+        return oe.path.realpath(os.path.join(self.root, file), self.root,
+                                use_physdir, assume_dir = assume_dir)
+
+    def test_norm(self):
+        for l in self.LINKS:
+            if l[2] == None:
+                continue
+
+            target_p = self.__realpath(l[0], True)
+            target_l = self.__realpath(l[0], False)
+
+            if l[2] != False:
+                self.assertEqual(target_p, target_l)
+                self.assertEqual(l[2], target_p[len(self.root):])
+
+    def test_phys(self):
+        for l in self.LINKS_PHYS:
+            target_p = self.__realpath(l[0], True)
+            target_l = self.__realpath(l[0], False)
+
+            self.assertEqual(l[1], target_p[len(self.root):])
+            self.assertEqual(l[2], target_l[len(self.root):])
+
+    def test_loop(self):
+        for e in self.EXCEPTIONS:
+            self.assertRaisesRegex(OSError, r'\[Errno %u\]' % e[1],
+                                    self.__realpath, e[0], False,
+ False)
meta/lib/oeqa/selftest/oelib-tests/types.py new file +61 -0
new file mode 100644
index 0000000..2613da9
@@ -0,0 +1,61 @@
+from oeqa.selftest.base import oeSelfTest from oeqa.utils.decorators
+import testcase from oe.maketype import create, factory
+
+class TestTypes(oeSelfTest):
+    def assertIsInstance(self, obj, cls):
+        return self.assertTrue(isinstance(obj, cls))
+
+    def assertIsNot(self, obj, other):
+        return self.assertFalse(obj is other)
+
+    def assertFactoryCreated(self, value, type, **flags):
+        cls = factory(type)
+        self.assertIsNot(cls, None)
+        self.assertIsInstance(create(value, type, **flags), cls)
+
+    def assertListIsEqual(self, value, valid, sep=None):
+        obj = create(value, 'list', separator=sep)
+        self.assertListEqual(obj, valid)
+
+class TestBooleanType(TestTypes):
+    def test_invalid(self):
+        self.assertRaises(ValueError, create, '', 'boolean')
+        self.assertRaises(ValueError, create, 'foo', 'boolean')
+        self.assertRaises(TypeError, create, object(), 'boolean')
+
+    def test_true(self):
+        self.assertTrue(create('y', 'boolean'))
+        self.assertTrue(create('yes', 'boolean'))
+        self.assertTrue(create('1', 'boolean'))
+        self.assertTrue(create('t', 'boolean'))
+        self.assertTrue(create('true', 'boolean'))
+        self.assertTrue(create('TRUE', 'boolean'))
+        self.assertTrue(create('truE', 'boolean'))
+
+    def test_false(self):
+        self.assertFalse(create('n', 'boolean'))
+        self.assertFalse(create('no', 'boolean'))
+        self.assertFalse(create('0', 'boolean'))
+        self.assertFalse(create('f', 'boolean'))
+        self.assertFalse(create('false', 'boolean'))
+        self.assertFalse(create('FALSE', 'boolean'))
+        self.assertFalse(create('faLse', 'boolean'))
+
+    def test_bool_equality(self):
+        self.assertEqual(create('n', 'boolean'), False)
+        self.assertNotEqual(create('n', 'boolean'), True)
+        self.assertEqual(create('y', 'boolean'), True)
+        self.assertNotEqual(create('y', 'boolean'), False)
+
+class TestList(TestTypes):
+
+    def test_list_nosep(self):
+        testlist = ['alpha', 'beta', 'theta']
+        self.assertListIsEqual('alpha beta theta', testlist)
+        self.assertListIsEqual('alpha  beta\ttheta', testlist)
+        self.assertListIsEqual('alpha', ['alpha'])
+
+    def test_list_usersep(self):
+        self.assertListIsEqual('foo:bar', ['foo', 'bar'], ':')
+        self.assertListIsEqual('foo:bar:baz', ['foo', 'bar', 'baz'],
+ ':')
meta/lib/oeqa/selftest/oelib-tests/utils.py new file +52 -1
new file mode 100644
index 0000000..25c60e1
@@ -0,0 +1,52 @@
+from oeqa.selftest.base import oeSelfTest from oeqa.utils.decorators
+import testcase from oe.utils import packages_filter_out_system,
+trim_version
+
+class TestPackagesFilterOutSystem(oeSelfTest):
+    def test_filter(self):
+        """
+        Test that oe.utils.packages_filter_out_system works.
+        """
+        try:
+            import bb
+        except ImportError:
+            self.skipTest("Cannot import bb")
+
+        d = bb.data_smart.DataSmart()
+        d.setVar("PN", "foo")
+
+        d.setVar("PACKAGES", "foo foo-doc foo-dev")
+        pkgs = packages_filter_out_system(d)
+        self.assertEqual(pkgs, [])
+
+        d.setVar("PACKAGES", "foo foo-doc foo-data foo-dev")
+        pkgs = packages_filter_out_system(d)
+        self.assertEqual(pkgs, ["foo-data"])
+
+        d.setVar("PACKAGES", "foo foo-locale-en-gb")
+        pkgs = packages_filter_out_system(d)
+        self.assertEqual(pkgs, [])
+
+        d.setVar("PACKAGES", "foo foo-data foo-locale-en-gb")
+        pkgs = packages_filter_out_system(d)
+        self.assertEqual(pkgs, ["foo-data"])
+
+
+class TestTrimVersion(oeSelfTest):
+    def test_version_exception(self):
+        with self.assertRaises(TypeError):
+            trim_version(None, 2)
+        with self.assertRaises(TypeError):
+            trim_version((1, 2, 3), 2)
+
+    def test_num_exception(self):
+        with self.assertRaises(ValueError):
+            trim_version("1.2.3", 0)
+        with self.assertRaises(ValueError):
+            trim_version("1.2.3", -1)
+
+    def test_valid(self):
+        self.assertEqual(trim_version("1.2.3", 1), "1")
+        self.assertEqual(trim_version("1.2.3", 2), "1.2")
+        self.assertEqual(trim_version("1.2.3", 3), "1.2.3")
+        self.assertEqual(trim_version("1.2.3", 4), "1.2.3")
--

2.1.4

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

#8 lore raw
In reply to [email protected]
Quoted 5 lines · On 15 November 2016 at 16:24, <[email protected]> wrote:

Currently the unittests for scripts on meta/lib/oe/tests are not being executed by any suite hence the best option is migrate them to meta/lib/oeqa/selftest/oelib-tests to be executed along with the selftest suite.

For some reason the discovery is very slow:

$ oe-selftest  -r oelib-tests.elf oelib-tests.license oelib-tests.path
oelib-tests.types oelib-tests.utils
2016-12-13 16:15:00,014 - selftest - INFO - Running bitbake -e to get BBPATH
2016-12-13 16:15:03,143 - selftest - INFO - Checking that everything is in
order before running the tests
2016-12-13 16:15:06,512 - selftest - INFO - Running bitbake -p
2016-12-13 16:15:10,203 - selftest - INFO - test runner init'ed like
unittest
2016-12-13 16:15:13,428 - selftest - INFO - Loading tests from:
oeqa.selftest.oelib-tests.elf
2016-12-13 16:15:16,489 - selftest - INFO - Loading tests from:
oeqa.selftest.oelib-tests.license
2016-12-13 16:15:29,391 - selftest - INFO - Loading tests from:
oeqa.selftest.oelib-tests.path
2016-12-13 16:15:38,822 - selftest - INFO - Loading tests from:
oeqa.selftest.oelib-tests.types
2016-12-13 16:15:57,719 - selftest - INFO - Loading tests from:
oeqa.selftest.oelib-tests.utils

It took over a minute to load a few tests. Do you have any idea why the discovery is so slow?

Ross

#9 lore raw
Quoted 3 lines · Ross

It took over a minute to load a few tests. Do you have any idea why the discovery is so slow?

Oh, it's because oeselftest does bitbake calls isn't it.

Good news: you don't need to use oeSelfTest at all, the discovery works fine with standard unittest.TestCase objects.

Patch incoming. :)

Ross

#10 lore raw
Quoted 7 lines · Ross

On 13 December 2016 at 16:17, Burton, Ross <[email protected] <mailto:[email protected]>> wrote:

It took over a minute to load a few tests. Do you have any idea why the discovery is so slow?

at my host is very fast the load (1 second)

jgperezc@jgperezc:~/poky-oetest/build$ oe-selftest  -r oelib-tests.elf oelib-tests.license oelib-tests.path oelib-tests.types oelib-tests.utils
2016-12-13 10:48:28,333 - selftest - INFO - Running bitbake -e to get BBPATH
2016-12-13 10:48:29,125 - selftest - INFO - Checking that everything is in order before running the tests
2016-12-13 10:48:29,833 - selftest - INFO - Running bitbake -p
2016-12-13 10:48:52,181 - selftest - INFO - test runner init'ed like unittest
2016-12-13 10:48:52,995 - selftest - INFO - Loading tests from: oeqa.selftest.oelib-tests.elf
2016-12-13 10:48:52,998 - selftest - INFO - Loading tests from: oeqa.selftest.oelib-tests.license
2016-12-13 10:48:53,000 - selftest - INFO - Loading tests from: oeqa.selftest.oelib-tests.path
2016-12-13 10:48:53,001 - selftest - INFO - Loading tests from: oeqa.selftest.oelib-tests.types
2016-12-13 10:48:53,003 - selftest - INFO - Loading tests from: oeqa.selftest.oelib-tests.utils
2016-12-13 10:48:53,005 - selftest - INFO - Adding: "include selftest.inc" in local.conf
2016-12-13 10:48:53,005 - selftest - INFO - Adding: "include bblayers.inc" in bblayers.conf
Quoted 6 lines

Oh, it's because oeselftest does bitbake calls isn't it.

Good news: you don't need to use oeSelfTest at all, the discovery works fine with standard unittest.TestCase objects.

Patch incoming. :)

Ok, just wondering if oe-selftest -l will also list those test cases ??

Quoted 2 lines

Ross

Signature · 2 lines
Saludos
José
#11 lore raw
Quoted 2 lines · Jose Perez Carranza

at my host is very fast the load (1 second)

Okay, proof that I need a new build machine. :)

Quoted 2 lines

Ok, just wondering if oe-selftest -l will also list those test cases ??

Huh. -l doesn't, but -m does.

Ross