##// END OF EJS Templates
Checkpoint where tests are recognized. Random tests not working yet.
Fernando Perez -
Show More
@@ -4,8 +4,12 b' PREFIX=~/tmp/local'
4
4
5 plugin: IPython_doctest_plugin.egg-info
5 plugin: IPython_doctest_plugin.egg-info
6
6
7 dtest: plugin dtexample.py
8 nosetests -vs --with-ipdoctest --doctest-tests --doctest-extension=txt \
9 dtexample.py
10
7 test: plugin dtexample.py
11 test: plugin dtexample.py
8 nosetests -s --with-ipdoctest --doctest-tests --doctest-extension=txt \
12 nosetests -vs --with-ipdoctest --doctest-tests --doctest-extension=txt \
9 dtexample.py test*.txt
13 dtexample.py test*.txt
10
14
11 deb: plugin dtexample.py
15 deb: plugin dtexample.py
@@ -70,3 +70,38 b' def ipfunc():'
70
70
71 return 'ipfunc'
71 return 'ipfunc'
72
72
73
74 def ranfunc():
75 """A function with some random output.
76
77 >>> 1+3 #random
78 junk goes here...
79
80 >>> 1+3
81 4
82
83 >>> 1+2 #random
84 again, anything goes
85 """
86 return 'ranfunc'
87
88
89 def ranf2():
90 """A function whose examples are all all random
91
92 Examples:
93
94 #all-random
95
96 >>> 1+3 #random
97 junk goes here...
98
99 >>> 1+3
100 klasdfj;
101
102 >>> 1+2 #random
103 again, anything goes
104
105 """
106 return 'ranf2'
107
@@ -222,6 +222,20 b' class DocTestCase(doctests.DocTestCase):'
222 for purposes of determining the test address, if it is provided.
222 for purposes of determining the test address, if it is provided.
223 """
223 """
224
224
225 # Note: this method was taken from numpy's nosetester module.
226
227 # Subclass nose.plugins.doctests.DocTestCase to work around a bug in
228 # its constructor that blocks non-default arguments from being passed
229 # down into doctest.DocTestCase
230 ## def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
231 ## checker=None, obj=None, result_var='_'):
232 ## self._result_var = result_var
233 ## self._nose_obj = obj
234 ## doctest.DocTestCase.__init__(self, test,
235 ## optionflags=optionflags,
236 ## setUp=setUp, tearDown=tearDown,
237 ## checker=checker)
238
225 # doctests loaded via find(obj) omit the module name
239 # doctests loaded via find(obj) omit the module name
226 # so we need to override id, __repr__ and shortDescription
240 # so we need to override id, __repr__ and shortDescription
227 # bonus: this will squash a 2.3 vs 2.4 incompatiblity
241 # bonus: this will squash a 2.3 vs 2.4 incompatiblity
@@ -235,6 +249,7 b' class DocTestCase(doctests.DocTestCase):'
235 return name
249 return name
236
250
237
251
252
238 # A simple subclassing of the original with a different class name, so we can
253 # A simple subclassing of the original with a different class name, so we can
239 # distinguish and treat differently IPython examples from pure python ones.
254 # distinguish and treat differently IPython examples from pure python ones.
240 class IPExample(doctest.Example): pass
255 class IPExample(doctest.Example): pass
@@ -311,7 +326,7 b' class IPDocTestParser(doctest.DocTestParser):'
311 used for error messages.
326 used for error messages.
312 """
327 """
313
328
314 #print 'Parse string:\n',string # dbg
329 print 'Parse string:\n',string # dbg
315
330
316 string = string.expandtabs()
331 string = string.expandtabs()
317 # If all lines begin with the same indentation, then strip it.
332 # If all lines begin with the same indentation, then strip it.
@@ -376,6 +391,8 b' class IPDocTestParser(doctest.DocTestParser):'
376 # Add any remaining post-example text to `output`.
391 # Add any remaining post-example text to `output`.
377 output.append(string[charno:])
392 output.append(string[charno:])
378
393
394 #print 'OUT:',output # dbg
395
379 return output
396 return output
380
397
381 def _parse_example(self, m, name, lineno,ip2py=False):
398 def _parse_example(self, m, name, lineno,ip2py=False):
@@ -501,6 +518,8 b' class ExtensionDoctest(doctests.Doctest):'
501 return tests
518 return tests
502
519
503 def loadTestsFromFile(self, filename):
520 def loadTestsFromFile(self, filename):
521 print 'lTF',filename # dbg
522
504 if is_extension_module(filename):
523 if is_extension_module(filename):
505 for t in self.loadTestsFromExtensionModule(filename):
524 for t in self.loadTestsFromExtensionModule(filename):
506 yield t
525 yield t
@@ -510,7 +529,6 b' class ExtensionDoctest(doctests.Doctest):'
510 pass
529 pass
511
530
512 if self.extension and anyp(filename.endswith, self.extension):
531 if self.extension and anyp(filename.endswith, self.extension):
513 #print 'lTF',filename # dbg
514 name = os.path.basename(filename)
532 name = os.path.basename(filename)
515 dh = open(filename)
533 dh = open(filename)
516 try:
534 try:
@@ -532,7 +550,7 b' class ExtensionDoctest(doctests.Doctest):'
532 Modified version that accepts extension modules as valid containers for
550 Modified version that accepts extension modules as valid containers for
533 doctests.
551 doctests.
534 """
552 """
535 #print 'Filename:',filename # dbg
553 print 'Filename:',filename # dbg
536
554
537 # temporarily hardcoded list, will move to driver later
555 # temporarily hardcoded list, will move to driver later
538 exclude = ['IPython/external/',
556 exclude = ['IPython/external/',
@@ -553,14 +571,9 b' class ExtensionDoctest(doctests.Doctest):'
553 else:
571 else:
554 return doctests.Doctest.wantFile(self,filename)
572 return doctests.Doctest.wantFile(self,filename)
555
573
556 # NOTE: the method below is a *copy* of the one in the nose doctests
574 # NOTE: the method below is almost a copy of the original one in nose, with
557 # plugin, but we have to replicate it here in order to have it resolve the
575 # a few modifications to control output checking.
558 # DocTestCase (last line) to our local copy, since the nose plugin doesn't
576
559 # provide a public hook for what TestCase class to use. The alternative
560 # would be to monkeypatch doctest in the stdlib, but that's ugly and
561 # brittle, since a change in plugin load order can break it. So for now,
562 # we just paste this in here, inelegant as this may be.
563
564 def loadTestsFromModule(self, module):
577 def loadTestsFromModule(self, module):
565 #print 'lTM',module # dbg
578 #print 'lTM',module # dbg
566
579
@@ -581,6 +594,15 b' class ExtensionDoctest(doctests.Doctest):'
581 test.filename = module_file
594 test.filename = module_file
582 yield DocTestCase(test)
595 yield DocTestCase(test)
583
596
597 # always use whitespace and ellipsis options
598 optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
599 #checker = DoctestOutputChecker()
600 checker = None
601 yield DocTestCase(test,
602 optionflags=optionflags,
603 checker=checker)
604
605
584
606
585 class IPythonDoctest(ExtensionDoctest):
607 class IPythonDoctest(ExtensionDoctest):
586 """Nose Plugin that supports doctests in extension modules.
608 """Nose Plugin that supports doctests in extension modules.
@@ -594,5 +616,4 b' class IPythonDoctest(ExtensionDoctest):'
594 self.doctest_tests = options.doctest_tests
616 self.doctest_tests = options.doctest_tests
595 self.extension = tolist(options.doctestExtension)
617 self.extension = tolist(options.doctestExtension)
596 self.parser = IPDocTestParser()
618 self.parser = IPDocTestParser()
597 #self.finder = DocTestFinder(parser=IPDocTestParser())
598 self.finder = DocTestFinder(parser=self.parser)
619 self.finder = DocTestFinder(parser=self.parser)
General Comments 0
You need to be logged in to leave comments. Login now