diff options
| author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2016-11-09 10:33:42 -0600 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-01-23 12:05:18 +0000 |
| commit | abb55ab304af91f68a4e09176ce9c6b995d903e0 (patch) | |
| tree | 4cef8b212dec4af7eb373f9313064c2146122d04 /meta/lib | |
| parent | 08714d3b7e744b19dde2b102ed4d80fc171f07a1 (diff) | |
| download | poky-abb55ab304af91f68a4e09176ce9c6b995d903e0.tar.gz | |
oeqa/core: Add utils module for OEQA framework
misc: Functions for transform object to other types.
path: Functions for path handling.
test: Functions for operations related to test cases and suites.
[YOCTO #10232]
(From OE-Core rev: 102d04ccca3ca89d41b76a8c44e0ca0f436b7004)
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
| -rw-r--r-- | meta/lib/oeqa/core/utils/__init__.py | 0 | ||||
| -rw-r--r-- | meta/lib/oeqa/core/utils/misc.py | 37 | ||||
| -rw-r--r-- | meta/lib/oeqa/core/utils/path.py | 19 | ||||
| -rw-r--r-- | meta/lib/oeqa/core/utils/test.py | 71 |
4 files changed, 127 insertions, 0 deletions
diff --git a/meta/lib/oeqa/core/utils/__init__.py b/meta/lib/oeqa/core/utils/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/meta/lib/oeqa/core/utils/__init__.py | |||
diff --git a/meta/lib/oeqa/core/utils/misc.py b/meta/lib/oeqa/core/utils/misc.py new file mode 100644 index 0000000000..6ae58ad6c4 --- /dev/null +++ b/meta/lib/oeqa/core/utils/misc.py | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | # Copyright (C) 2016 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | def toList(obj, obj_type, obj_name="Object"): | ||
| 5 | if isinstance(obj, obj_type): | ||
| 6 | return [obj] | ||
| 7 | elif isinstance(obj, list): | ||
| 8 | return obj | ||
| 9 | else: | ||
| 10 | raise TypeError("%s must be %s or list" % (obj_name, obj_type)) | ||
| 11 | |||
| 12 | def toSet(obj, obj_type, obj_name="Object"): | ||
| 13 | if isinstance(obj, obj_type): | ||
| 14 | return {obj} | ||
| 15 | elif isinstance(obj, list): | ||
| 16 | return set(obj) | ||
| 17 | elif isinstance(obj, set): | ||
| 18 | return obj | ||
| 19 | else: | ||
| 20 | raise TypeError("%s must be %s or set" % (obj_name, obj_type)) | ||
| 21 | |||
| 22 | def strToList(obj, obj_name="Object"): | ||
| 23 | return toList(obj, str, obj_name) | ||
| 24 | |||
| 25 | def strToSet(obj, obj_name="Object"): | ||
| 26 | return toSet(obj, str, obj_name) | ||
| 27 | |||
| 28 | def intToList(obj, obj_name="Object"): | ||
| 29 | return toList(obj, int, obj_name) | ||
| 30 | |||
| 31 | def dataStoteToDict(d, variables): | ||
| 32 | data = {} | ||
| 33 | |||
| 34 | for v in variables: | ||
| 35 | data[v] = d.getVar(v, True) | ||
| 36 | |||
| 37 | return data | ||
diff --git a/meta/lib/oeqa/core/utils/path.py b/meta/lib/oeqa/core/utils/path.py new file mode 100644 index 0000000000..a21caad5cb --- /dev/null +++ b/meta/lib/oeqa/core/utils/path.py | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | # Copyright (C) 2016 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | import os | ||
| 5 | import sys | ||
| 6 | |||
| 7 | def findFile(file_name, directory): | ||
| 8 | """ | ||
| 9 | Search for a file in directory and returns its complete path. | ||
| 10 | """ | ||
| 11 | for r, d, f in os.walk(directory): | ||
| 12 | if file_name in f: | ||
| 13 | return os.path.join(r, file_name) | ||
| 14 | return None | ||
| 15 | |||
| 16 | def remove_safe(path): | ||
| 17 | if os.path.exists(path): | ||
| 18 | os.remove(path) | ||
| 19 | |||
diff --git a/meta/lib/oeqa/core/utils/test.py b/meta/lib/oeqa/core/utils/test.py new file mode 100644 index 0000000000..820b9976ab --- /dev/null +++ b/meta/lib/oeqa/core/utils/test.py | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | # Copyright (C) 2016 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | import os | ||
| 5 | import unittest | ||
| 6 | |||
| 7 | def getSuiteCases(suite): | ||
| 8 | """ | ||
| 9 | Returns individual test from a test suite. | ||
| 10 | """ | ||
| 11 | tests = [] | ||
| 12 | for item in suite: | ||
| 13 | if isinstance(item, unittest.suite.TestSuite): | ||
| 14 | tests.extend(getSuiteCases(item)) | ||
| 15 | elif isinstance(item, unittest.TestCase): | ||
| 16 | tests.append(item) | ||
| 17 | return tests | ||
| 18 | |||
| 19 | def getSuiteModules(suite): | ||
| 20 | """ | ||
| 21 | Returns modules in a test suite. | ||
| 22 | """ | ||
| 23 | modules = set() | ||
| 24 | for test in getSuiteCases(suite): | ||
| 25 | modules.add(getCaseModule(test)) | ||
| 26 | return modules | ||
| 27 | |||
| 28 | def getSuiteCasesInfo(suite, func): | ||
| 29 | """ | ||
| 30 | Returns test case info from suite. Info is fetched from func. | ||
| 31 | """ | ||
| 32 | tests = [] | ||
| 33 | for test in getSuiteCases(suite): | ||
| 34 | tests.append(func(test)) | ||
| 35 | return tests | ||
| 36 | |||
| 37 | def getSuiteCasesNames(suite): | ||
| 38 | """ | ||
| 39 | Returns test case names from suite. | ||
| 40 | """ | ||
| 41 | return getSuiteCasesInfo(suite, getCaseMethod) | ||
| 42 | |||
| 43 | def getSuiteCasesIDs(suite): | ||
| 44 | """ | ||
| 45 | Returns test case ids from suite. | ||
| 46 | """ | ||
| 47 | return getSuiteCasesInfo(suite, getCaseID) | ||
| 48 | |||
| 49 | def getCaseModule(test_case): | ||
| 50 | """ | ||
| 51 | Returns test case module name. | ||
| 52 | """ | ||
| 53 | return test_case.__module__ | ||
| 54 | |||
| 55 | def getCaseClass(test_case): | ||
| 56 | """ | ||
| 57 | Returns test case class name. | ||
| 58 | """ | ||
| 59 | return test_case.__class__.__name__ | ||
| 60 | |||
| 61 | def getCaseID(test_case): | ||
| 62 | """ | ||
| 63 | Returns test case complete id. | ||
| 64 | """ | ||
| 65 | return test_case.id() | ||
| 66 | |||
| 67 | def getCaseMethod(test_case): | ||
| 68 | """ | ||
| 69 | Returns test case method name. | ||
| 70 | """ | ||
| 71 | return getCaseID(test_case).split('.')[-1] | ||
