diff options
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r-- | meta/lib/oeqa/runtime/decorator/package.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/decorator/package.py b/meta/lib/oeqa/runtime/decorator/package.py new file mode 100644 index 0000000000..aa6ecb68fa --- /dev/null +++ b/meta/lib/oeqa/runtime/decorator/package.py | |||
@@ -0,0 +1,53 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.core.decorator import OETestDecorator, registerDecorator | ||
5 | from oeqa.core.utils.misc import strToSet | ||
6 | |||
7 | @registerDecorator | ||
8 | class OEHasPackage(OETestDecorator): | ||
9 | """ | ||
10 | Checks if image has packages (un)installed. | ||
11 | |||
12 | The argument must be a string, set, or list of packages that must be | ||
13 | installed or not present in the image. | ||
14 | |||
15 | The way to tell a package must not be in an image is using an | ||
16 | exclamation point ('!') before the name of the package. | ||
17 | |||
18 | If test depends on pkg1 or pkg2 you need to use: | ||
19 | @OEHasPackage({'pkg1', 'pkg2'}) | ||
20 | |||
21 | If test depends on pkg1 and pkg2 you need to use: | ||
22 | @OEHasPackage('pkg1') | ||
23 | @OEHasPackage('pkg2') | ||
24 | |||
25 | If test depends on pkg1 but pkg2 must not be present use: | ||
26 | @OEHasPackage({'pkg1', '!pkg2'}) | ||
27 | """ | ||
28 | |||
29 | attrs = ('need_pkgs',) | ||
30 | |||
31 | def setUpDecorator(self): | ||
32 | need_pkgs = set() | ||
33 | unneed_pkgs = set() | ||
34 | pkgs = strToSet(self.need_pkgs) | ||
35 | for pkg in pkgs: | ||
36 | if pkg.startswith('!'): | ||
37 | unneed_pkgs.add(pkg[1:]) | ||
38 | else: | ||
39 | need_pkgs.add(pkg) | ||
40 | |||
41 | if unneed_pkgs: | ||
42 | msg = 'Checking if %s is not installed' % ', '.join(unneed_pkgs) | ||
43 | self.logger.debug(msg) | ||
44 | if not self.case.tc.image_packages.isdisjoint(unneed_pkgs): | ||
45 | msg = "Test can't run with %s installed" % ', or'.join(unneed_pkgs) | ||
46 | self.case.skipTest(msg) | ||
47 | |||
48 | if need_pkgs: | ||
49 | msg = 'Checking if at least one of %s is installed' % ', '.join(need_pkgs) | ||
50 | self.logger.debug(msg) | ||
51 | if self.case.tc.image_packages.isdisjoint(need_pkgs): | ||
52 | msg = "Test requires %s to be installed" % ', or'.join(need_pkgs) | ||
53 | self.case.skipTest(msg) | ||