Nose Plugin that supports doctests in extension modules.
| 701 | |
| 702 | |
| 703 | class IPythonDoctest(ExtensionDoctest): |
| 704 | """Nose Plugin that supports doctests in extension modules. |
| 705 | """ |
| 706 | name = 'ipdoctest' # call nosetests with --with-ipdoctest |
| 707 | enabled = True |
| 708 | |
| 709 | def makeTest(self, obj, parent): |
| 710 | """Look for doctests in the given object, which will be a |
| 711 | function, method or class. |
| 712 | """ |
| 713 | #print 'Plugin analyzing:', obj, parent # dbg |
| 714 | # always use whitespace and ellipsis options |
| 715 | optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS |
| 716 | |
| 717 | doctests = self.finder.find(obj, module=getmodule(parent)) |
| 718 | if doctests: |
| 719 | for test in doctests: |
| 720 | if len(test.examples) == 0: |
| 721 | continue |
| 722 | |
| 723 | yield DocTestCase(test, obj=obj, |
| 724 | optionflags=optionflags, |
| 725 | checker=self.checker) |
| 726 | |
| 727 | def options(self, parser, env=os.environ): |
| 728 | #print "Options for nose plugin:", self.name # dbg |
| 729 | Plugin.options(self, parser, env) |
| 730 | parser.add_option('--ipdoctest-tests', action='store_true', |
| 731 | dest='ipdoctest_tests', |
| 732 | default=env.get('NOSE_IPDOCTEST_TESTS',True), |
| 733 | help="Also look for doctests in test modules. " |
| 734 | "Note that classes, methods and functions should " |
| 735 | "have either doctests or non-doctest tests, " |
| 736 | "not both. [NOSE_IPDOCTEST_TESTS]") |
| 737 | parser.add_option('--ipdoctest-extension', action="append", |
| 738 | dest="ipdoctest_extension", |
| 739 | help="Also look for doctests in files with " |
| 740 | "this extension [NOSE_IPDOCTEST_EXTENSION]") |
| 741 | # Set the default as a list, if given in env; otherwise |
| 742 | # an additional value set on the command line will cause |
| 743 | # an error. |
| 744 | env_setting = env.get('NOSE_IPDOCTEST_EXTENSION') |
| 745 | if env_setting is not None: |
| 746 | parser.set_defaults(ipdoctest_extension=tolist(env_setting)) |
| 747 | |
| 748 | def configure(self, options, config): |
| 749 | #print "Configuring nose plugin:", self.name # dbg |
| 750 | Plugin.configure(self, options, config) |
| 751 | # Pull standard doctest plugin out of config; we will do doctesting |
| 752 | config.plugins.plugins = [p for p in config.plugins.plugins |
| 753 | if p.name != 'doctest'] |
| 754 | self.doctest_tests = options.ipdoctest_tests |
| 755 | self.extension = tolist(options.ipdoctest_extension) |
| 756 | |
| 757 | self.parser = IPDocTestParser() |
| 758 | self.finder = DocTestFinder(parser=self.parser) |
| 759 | self.checker = IPDoctestOutputChecker() |
| 760 | self.globs = None |