diff options
-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] | ||