Show More
@@ -4,8 +4,12 PREFIX=~/tmp/local | |||
|
4 | 4 | |
|
5 | 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 | 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 | 13 | dtexample.py test*.txt |
|
10 | 14 | |
|
11 | 15 | deb: plugin dtexample.py |
@@ -70,3 +70,38 def ipfunc(): | |||
|
70 | 70 | |
|
71 | 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 class DocTestCase(doctests.DocTestCase): | |||
|
222 | 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 | 239 | # doctests loaded via find(obj) omit the module name |
|
226 | 240 | # so we need to override id, __repr__ and shortDescription |
|
227 | 241 | # bonus: this will squash a 2.3 vs 2.4 incompatiblity |
@@ -235,6 +249,7 class DocTestCase(doctests.DocTestCase): | |||
|
235 | 249 | return name |
|
236 | 250 | |
|
237 | 251 | |
|
252 | ||
|
238 | 253 | # A simple subclassing of the original with a different class name, so we can |
|
239 | 254 | # distinguish and treat differently IPython examples from pure python ones. |
|
240 | 255 | class IPExample(doctest.Example): pass |
@@ -311,7 +326,7 class IPDocTestParser(doctest.DocTestParser): | |||
|
311 | 326 | used for error messages. |
|
312 | 327 | """ |
|
313 | 328 | |
|
314 |
|
|
|
329 | print 'Parse string:\n',string # dbg | |
|
315 | 330 | |
|
316 | 331 | string = string.expandtabs() |
|
317 | 332 | # If all lines begin with the same indentation, then strip it. |
@@ -376,6 +391,8 class IPDocTestParser(doctest.DocTestParser): | |||
|
376 | 391 | # Add any remaining post-example text to `output`. |
|
377 | 392 | output.append(string[charno:]) |
|
378 | 393 | |
|
394 | #print 'OUT:',output # dbg | |
|
395 | ||
|
379 | 396 | return output |
|
380 | 397 | |
|
381 | 398 | def _parse_example(self, m, name, lineno,ip2py=False): |
@@ -501,6 +518,8 class ExtensionDoctest(doctests.Doctest): | |||
|
501 | 518 | return tests |
|
502 | 519 | |
|
503 | 520 | def loadTestsFromFile(self, filename): |
|
521 | print 'lTF',filename # dbg | |
|
522 | ||
|
504 | 523 | if is_extension_module(filename): |
|
505 | 524 | for t in self.loadTestsFromExtensionModule(filename): |
|
506 | 525 | yield t |
@@ -510,7 +529,6 class ExtensionDoctest(doctests.Doctest): | |||
|
510 | 529 | pass |
|
511 | 530 | |
|
512 | 531 | if self.extension and anyp(filename.endswith, self.extension): |
|
513 | #print 'lTF',filename # dbg | |
|
514 | 532 | name = os.path.basename(filename) |
|
515 | 533 | dh = open(filename) |
|
516 | 534 | try: |
@@ -532,7 +550,7 class ExtensionDoctest(doctests.Doctest): | |||
|
532 | 550 | Modified version that accepts extension modules as valid containers for |
|
533 | 551 | doctests. |
|
534 | 552 | """ |
|
535 |
|
|
|
553 | print 'Filename:',filename # dbg | |
|
536 | 554 | |
|
537 | 555 | # temporarily hardcoded list, will move to driver later |
|
538 | 556 | exclude = ['IPython/external/', |
@@ -553,14 +571,9 class ExtensionDoctest(doctests.Doctest): | |||
|
553 | 571 | else: |
|
554 | 572 | return doctests.Doctest.wantFile(self,filename) |
|
555 | 573 | |
|
556 |
# NOTE: the method below is a |
|
|
557 | # plugin, but we have to replicate it here in order to have it resolve the | |
|
558 | # DocTestCase (last line) to our local copy, since the nose plugin doesn't | |
|
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 | ||
|
574 | # NOTE: the method below is almost a copy of the original one in nose, with | |
|
575 | # a few modifications to control output checking. | |
|
576 | ||
|
564 | 577 | def loadTestsFromModule(self, module): |
|
565 | 578 | #print 'lTM',module # dbg |
|
566 | 579 | |
@@ -581,6 +594,15 class ExtensionDoctest(doctests.Doctest): | |||
|
581 | 594 | test.filename = module_file |
|
582 | 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 | 607 | class IPythonDoctest(ExtensionDoctest): |
|
586 | 608 | """Nose Plugin that supports doctests in extension modules. |
@@ -594,5 +616,4 class IPythonDoctest(ExtensionDoctest): | |||
|
594 | 616 | self.doctest_tests = options.doctest_tests |
|
595 | 617 | self.extension = tolist(options.doctestExtension) |
|
596 | 618 | self.parser = IPDocTestParser() |
|
597 | #self.finder = DocTestFinder(parser=IPDocTestParser()) | |
|
598 | 619 | self.finder = DocTestFinder(parser=self.parser) |
General Comments 0
You need to be logged in to leave comments.
Login now