Proxy for DocTestCase: provides an address() method that returns the correct address for the doctest case. Otherwise acts as a proxy to the test case. To provide hints for address(), an obj may also be passed -- this will be used as the test object for purposes of determining the tes
| 194 | |
| 195 | |
| 196 | class DocTestCase(doctests.DocTestCase): |
| 197 | """Proxy for DocTestCase: provides an address() method that |
| 198 | returns the correct address for the doctest case. Otherwise |
| 199 | acts as a proxy to the test case. To provide hints for address(), |
| 200 | an obj may also be passed -- this will be used as the test object |
| 201 | for purposes of determining the test address, if it is provided. |
| 202 | """ |
| 203 | |
| 204 | # Note: this method was taken from numpy's nosetester module. |
| 205 | |
| 206 | # Subclass nose.plugins.doctests.DocTestCase to work around a bug in |
| 207 | # its constructor that blocks non-default arguments from being passed |
| 208 | # down into doctest.DocTestCase |
| 209 | |
| 210 | def __init__(self, test, optionflags=0, setUp=None, tearDown=None, |
| 211 | checker=None, obj=None, result_var='_'): |
| 212 | self._result_var = result_var |
| 213 | doctests.DocTestCase.__init__(self, test, |
| 214 | optionflags=optionflags, |
| 215 | setUp=setUp, tearDown=tearDown, |
| 216 | checker=checker) |
| 217 | # Now we must actually copy the original constructor from the stdlib |
| 218 | # doctest class, because we can't call it directly and a bug in nose |
| 219 | # means it never gets passed the right arguments. |
| 220 | |
| 221 | self._dt_optionflags = optionflags |
| 222 | self._dt_checker = checker |
| 223 | self._dt_test = test |
| 224 | self._dt_test_globs_ori = test.globs |
| 225 | self._dt_setUp = setUp |
| 226 | self._dt_tearDown = tearDown |
| 227 | |
| 228 | # XXX - store this runner once in the object! |
| 229 | runner = IPDocTestRunner(optionflags=optionflags, |
| 230 | checker=checker, verbose=False) |
| 231 | self._dt_runner = runner |
| 232 | |
| 233 | |
| 234 | # Each doctest should remember the directory it was loaded from, so |
| 235 | # things like %run work without too many contortions |
| 236 | self._ori_dir = os.path.dirname(test.filename) |
| 237 | |
| 238 | # Modified runTest from the default stdlib |
| 239 | def runTest(self): |
| 240 | test = self._dt_test |
| 241 | runner = self._dt_runner |
| 242 | |
| 243 | old = sys.stdout |
| 244 | new = StringIO() |
| 245 | optionflags = self._dt_optionflags |
| 246 | |
| 247 | if not (optionflags & REPORTING_FLAGS): |
| 248 | # The option flags don't include any reporting flags, |
| 249 | # so add the default reporting flags |
| 250 | optionflags |= _unittest_reportflags |
| 251 | |
| 252 | try: |
| 253 | # Save our current directory and switch out to the one where the |
no outgoing calls