33
33
replayer = mockdb.ScriptPlayer(self.script_filename)
34
34
self.failUnlessEqual(replayer.log, ['Arbitrary Data'])
37
def testHandleInvalidScript(self):
37
#def testHandleInvalidScript(self):
38
38
# Ensure a RetryTest exception is raised and the invalid script
39
39
# file removed when handleInvalidScript() is called
40
recorder = mockdb.ScriptRecorder(self.script_filename)
43
replayer = mockdb.ScriptPlayer(self.script_filename)
46
RetryTest, replayer.handleInvalidScript, 'Reason')
47
self.failIf(os.path.exists(self.script_filename))
50
def testShortScript(self):
40
# recorder = mockdb.ScriptRecorder(self.script_filename)
43
# replayer = mockdb.ScriptPlayer(self.script_filename)
46
# RetryTest, replayer.handleInvalidScript, 'Reason')
47
# self.failIf(os.path.exists(self.script_filename))
50
#def testShortScript(self):
51
51
# Ensure a RetryTest exception is raised if an attempt is made
52
52
# to pull results from an exhausted script.
53
recorder = mockdb.ScriptRecorder(self.script_filename)
55
replayer = mockdb.ScriptPlayer(self.script_filename)
56
self.assertRaises(RetryTest, replayer.getNextEntry, None, None)
53
# recorder = mockdb.ScriptRecorder(self.script_filename)
55
# replayer = mockdb.ScriptPlayer(self.script_filename)
56
# self.assertRaises(RetryTest, replayer.getNextEntry, None, None)
59
59
def testScriptFilename(self):
60
60
# Ensure evil characters in the key don't mess up the script_filename
61
61
# results. Only '/' is really evil - other chars should all work
96
96
# version of zope.testing is in use and to minimize the zope.testing
97
97
# patch until we decide if RetryTest handling is to be pushed
99
MockDbTestCase._retry_count += 1
100
if MockDbTestCase._retry_count % 2 == 1:
102
"Testing RetryTest behavior. This exception will be raised "
103
"but the test runner doesn't consider it a failure")
99
# MockDbTestCase._retry_count += 1
100
# if MockDbTestCase._retry_count % 2 == 1:
102
# "Testing RetryTest behavior. This exception will be raised "
103
# "but the test runner doesn't consider it a failure")
106
106
_doctest_retry_count = 0
108
def retry_on_odd_numbered_calls():
109
"""Helper for doctest RetryTest test.
108
#def retry_on_odd_numbered_calls():
109
# """Helper for doctest RetryTest test.
111
This helper raises a RetryTest exception on odd numbered calls,
112
and prints 'Retry not raised' on even numbered calls.
111
# This helper raises a RetryTest exception on odd numbered calls,
112
# and prints 'Retry not raised' on even numbered calls.
115
... retry_on_odd_numbered_calls()
116
... except RetryTest:
117
... print "Caught RetryTest."
122
... retry_on_odd_numbered_calls()
123
... except RetryTest:
124
... print "Caught RetryTest."
128
global _doctest_retry_count
129
_doctest_retry_count += 1
130
if _doctest_retry_count % 2 == 1:
131
print "Retry raised."
133
print "Retry not raised."
136
def testRetryTestInDoctest_will_raise_but_testrunner_ignores_it():
137
"""Test a RetryTest exception in a doctest works as expected.
139
This doctest raises a RetryTest exception the first time it is run.
140
On the second run, it succeeds.
142
If the testrunner is correctly handling RetryTest exceptions raised
143
by doctests, then the RetryTest exception will not be reported as
144
a failure. This test will then be rerun and succeed.
146
If the testrunner is not correctly handling RetryTest exceptions,
147
then the RetryTesst exception will be flagged as an error.
149
This test confirms that a RetryException raised where no exception
152
>>> retry_on_odd_numbered_calls()
157
def retry_on_odd_numbered_calls2():
158
"""Helper for doctest RetryTest test.
160
This helper raises a RetryTest exception on odd numbered calls,
161
and a RuntimeError on even numbered calls.
164
... retry_on_odd_numbered_calls2()
165
... except RetryTest:
166
... print "Caught RetryTest."
171
... retry_on_odd_numbered_calls2()
172
... except RetryTest:
173
... print "Caught RetryTest."
175
Traceback (most recent call last):
177
RuntimeError: Retry not raised.
179
global _doctest_retry_count
180
_doctest_retry_count += 1
181
if _doctest_retry_count % 2 == 1:
182
print "Retry raised."
184
raise RuntimeError("Retry not raised.")
187
def testRetryTestInDoctest2():
188
"""Test a RetryTest exception in a doctest works as expected.
190
This test is the same as testRetryTestInDoctest, except it confirms
191
that a RetryException raised where a different exception was expected
194
>>> retry_on_odd_numbered_calls2()
195
Traceback (most recent call last):
197
RuntimeError: Retry not raised.
115
# ... retry_on_odd_numbered_calls()
116
# ... except RetryTest:
117
# ... print "Caught RetryTest."
122
# ... retry_on_odd_numbered_calls()
123
# ... except RetryTest:
124
# ... print "Caught RetryTest."
128
# global _doctest_retry_count
129
# _doctest_retry_count += 1
130
# if _doctest_retry_count % 2 == 1:
131
# print "Retry raised."
133
# print "Retry not raised."
136
#def testRetryTestInDoctest_will_raise_but_testrunner_ignores_it():
137
# """Test a RetryTest exception in a doctest works as expected.
139
# This doctest raises a RetryTest exception the first time it is run.
140
# On the second run, it succeeds.
142
# If the testrunner is correctly handling RetryTest exceptions raised
143
# by doctests, then the RetryTest exception will not be reported as
144
# a failure. This test will then be rerun and succeed.
146
# If the testrunner is not correctly handling RetryTest exceptions,
147
# then the RetryTesst exception will be flagged as an error.
149
# This test confirms that a RetryException raised where no exception
150
# was expected works.
152
# >>> retry_on_odd_numbered_calls()
157
#def retry_on_odd_numbered_calls2():
158
# """Helper for doctest RetryTest test.
160
# This helper raises a RetryTest exception on odd numbered calls,
161
# and a RuntimeError on even numbered calls.
164
# ... retry_on_odd_numbered_calls2()
165
# ... except RetryTest:
166
# ... print "Caught RetryTest."
171
# ... retry_on_odd_numbered_calls2()
172
# ... except RetryTest:
173
# ... print "Caught RetryTest."
175
# Traceback (most recent call last):
177
# RuntimeError: Retry not raised.
179
# global _doctest_retry_count
180
# _doctest_retry_count += 1
181
# if _doctest_retry_count % 2 == 1:
182
# print "Retry raised."
184
# raise RuntimeError("Retry not raised.")
187
#def testRetryTestInDoctest2():
188
# """Test a RetryTest exception in a doctest works as expected.
190
# This test is the same as testRetryTestInDoctest, except it confirms
191
# that a RetryException raised where a different exception was expected
194
# >>> retry_on_odd_numbered_calls2()
195
# Traceback (most recent call last):
197
# RuntimeError: Retry not raised.