Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pms-test-suite:master commit in: pmstestsuite/library/
Date: Wed, 29 Jun 2011 17:53:01
Message-Id: 4b45ef360b363c7fc472e6d746ee68e70ee61837.mgorny@gentoo
1 commit: 4b45ef360b363c7fc472e6d746ee68e70ee61837
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jun 29 17:30:32 2011 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Wed Jun 29 17:32:35 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=4b45ef36
7
8 Support grabbing relevant_ and supported_eapis from a prop.
9
10 As Python doesn't supply us with class properties, we need a little
11 function to handle transforming them as necessary. Hopefully it won't be
12 an ugly hack as it uses the property object public API.
13
14 ---
15 pmstestsuite/library/case.py | 23 +++++++++++++++++++----
16 1 files changed, 19 insertions(+), 4 deletions(-)
17
18 diff --git a/pmstestsuite/library/case.py b/pmstestsuite/library/case.py
19 index e87f15d..3ab5197 100644
20 --- a/pmstestsuite/library/case.py
21 +++ b/pmstestsuite/library/case.py
22 @@ -114,8 +114,20 @@ class EbuildTestCase(TestCase):
23 inherits = []
24 phase_funcs = {}
25
26 + @classmethod
27 + def _eval_prop(cls, prop_or_obj):
28 + """
29 + Evaluate and return the value of a property when passed a property
30 + object, or return the passed value otherwise.
31 + """
32 +
33 + if isinstance(prop_or_obj, property):
34 + return prop_or_obj.fget(cls)
35 + else:
36 + return prop_or_obj
37 +
38 @property
39 - def supported_eapis(self):
40 + def supported_eapis(cls):
41 """
42 A list of EAPIs for which the test is able to run and gives
43 predictible results. Defaults to all available EAPIs.
44 @@ -126,7 +138,7 @@ class EbuildTestCase(TestCase):
45 return (0, 1, 2, 3, 4)
46
47 @property
48 - def relevant_eapis(self):
49 + def relevant_eapis(cls):
50 """
51 A list of EAPIs for which the test should be run by default (in
52 non-thorough mode). This should list all the EAPIs where
53 @@ -134,7 +146,7 @@ class EbuildTestCase(TestCase):
54
55 When unset, defaults to a random element of .supported_eapis().
56 """
57 - return random.choice(self.supported_eapis)
58 + return (random.choice(cls._eval_prop(cls.supported_eapis)),)
59
60 @classmethod
61 def inst_all(cls, *args, **kwargs):
62 @@ -143,7 +155,10 @@ class EbuildTestCase(TestCase):
63
64 Returns an iterator over a list of test case instances.
65 """
66 - for eapi in cls.relevant_eapis:
67 +
68 + # sadly, no @classproperty
69 + # but property object attributes are official
70 + for eapi in cls._eval_prop(cls.relevant_eapis):
71 kwargs['eapi'] = eapi
72 yield cls(*args, **kwargs)