1 #Copyright (C) 2008 Codethink Ltd
3 #his program is free software; you can redistribute it and/or modify
4 #it under the terms of the GNU General Public License as published by
5 #the Free Software Foundation; either version 2 of the License, or
6 #(at your option) any later version.
8 #This program is distributed in the hope that it will be useful,
9 #but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 #GNU General Public License for more details.
12 #You should have received a copy of the GNU General Public License
13 #along with this program; if not, write to the Free Software
14 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 from Events import Events
18 PASY_TEST_NOT_STARTED = 0
19 PASY_TEST_IN_PROGRESS = 1
23 class PasyEvents(Events):
24 __events__ = ('finished', )
26 class PasyTestStep(object):
28 def __init__(self, name):
29 self.events = PasyEvents()
30 self._state = PASY_TEST_NOT_STARTED
36 if self._state == PASY_TEST_IN_PROGRESS:
37 self._state = PASY_TEST_WIN
38 self.events.finished()
41 if self._state == PASY_TEST_IN_PROGRESS:
42 self._state = PASY_TEST_FAIL
44 self.events.finished()
46 def assertEqual(self, a, b, msg):
51 self._state = PASY_TEST_IN_PROGRESS
58 class PasyTestFunc(PasyTestStep):
60 def __init__(self, name, func):
61 PasyTestStep.__init__(self, name)
67 class PasyTest(PasyTestStep):
71 def __init__(self, name, cont):
72 PasyTest.__init__(self, name)
77 for name in __tests__:
78 func = self.__getattr__(name)
79 self._addfunc(func.func_name, func)
81 def _addfunc(self, name, func):
82 functest = PasyTestFunc(self, func.func_name, func)
84 self._tests.append(functest)
87 self._iter = self._test_iterator
88 gobject.idle_add(self.idle_handler)
90 def idle_handler(self):
92 step = self._iter.next()
93 def finished_handler():
94 if step.state == PASY_TEST_WIN or self._cont == True:
95 gobject.idle_add(self.idle_handler)
96 elif step.state == PASY_TEST_FAIL and self._cont == False:
98 step.events.failed += finished_handler
100 except StopIteration:
101 # No More tests, check for success or fail
103 for test in self._tests:
104 succeeded = succeeded and (test.state == PASY_TEST_WIN)
111 def _test_iterator(self):
112 for test in self._tests: