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/oeqa/core/utils/test.py | |
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/oeqa/core/utils/test.py')
-rw-r--r-- | meta/lib/oeqa/core/utils/test.py | 71 |
1 files changed, 71 insertions, 0 deletions
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] | ||