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: Sun, 29 May 2011 18:57:48
Message-Id: 5337c280c32ad6534c713adc5047920014c5a6a3.mgorny@gentoo
1 commit: 5337c280c32ad6534c713adc5047920014c5a6a3
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Sun May 29 18:32:49 2011 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Sun May 29 18:32:49 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=5337c280
7
8 Cache instantiated tests.
9
10 ---
11 PMSTestSuite/library/__init__.py | 25 +++++++++++++++++--------
12 1 files changed, 17 insertions(+), 8 deletions(-)
13
14 diff --git a/PMSTestSuite/library/__init__.py b/PMSTestSuite/library/__init__.py
15 index 52aa8d2..a473888 100644
16 --- a/PMSTestSuite/library/__init__.py
17 +++ b/PMSTestSuite/library/__init__.py
18 @@ -22,6 +22,8 @@ from PMSTestSuite.library.case import TestCase
19 class TestLibrary(object):
20 """ Base class for a test library. """
21
22 + tests = None
23 +
24 def __iter__(self):
25 """
26 Iterate over all the tests in a test library, loading its modules
27 @@ -32,14 +34,21 @@ class TestLibrary(object):
28 - ImportError if submodule import fails.
29 """
30
31 - for t in self.test_names:
32 - # XXX: tests without a '.' in __init__?
33 - modname, clsname = t.rsplit('.', 1)
34 - modname = '%s.%s' % (self.modname, modname)
35 - mod = __import__(modname, {}, {}, [clsname], 0)
36 - cls = getattr(mod, clsname)
37 - for i in cls.inst_all():
38 - yield i
39 + if self.tests is not None:
40 + # tests already instantiated
41 + for t in self.tests:
42 + yield t
43 + else:
44 + self.tests = []
45 + for t in self.test_names:
46 + # XXX: tests without a '.' in __init__?
47 + modname, clsname = t.rsplit('.', 1)
48 + modname = '%s.%s' % (self.modname, modname)
49 + mod = __import__(modname, {}, {}, [clsname], 0)
50 + cls = getattr(mod, clsname)
51 + for i in cls.inst_all():
52 + self.tests.append(i)
53 + yield i
54
55 def __init__(self, modname):
56 self.modname = modname