##// END OF EJS Templates
- Make ipdoctest a little cleaner by giving it separate option names....
Fernando Perez -
Show More
@@ -61,7 +61,7 b' def main():'
61 61 # plugin needs to be gone through with a fine
62 62 # toothed comb to find what is causing the problem.
63 63 # '--with-ipdoctest',
64 '--doctest-tests','--doctest-extension=txt',
64 '--ipdoctest-tests','--ipdoctest-extension=txt',
65 65 '--detailed-errors',
66 66
67 67 # We add --exe because of setuptools' imbecility (it
@@ -81,11 +81,13 b' def main():'
81 81 (':' in arg and '.py' in arg):
82 82 has_tests = True
83 83 break
84
84 85 # If nothing was specifically requested, test full IPython
85 86 if not has_tests:
86 87 argv.append('IPython')
87 88
88 # Construct list of plugins, omitting the existing doctest plugin.
89 # Construct list of plugins, omitting the existing doctest plugin, which
90 # ours replaces (and extends).
89 91 plugins = [IPythonDoctest(EXCLUDE)]
90 92 for p in nose.plugins.builtin.plugins:
91 93 plug = p()
@@ -123,6 +123,13 b' class ipnsdict(dict):'
123 123 def start_ipython():
124 124 """Start a global IPython shell, which we need for IPython-specific syntax.
125 125 """
126
127 # This function should only ever run once!
128 if hasattr(start_ipython,'already_called'):
129 return
130 start_ipython.already_called = True
131
132 # Ok, first time we're called, go ahead
126 133 import new
127 134
128 135 import IPython
@@ -691,6 +698,7 b' class ExtensionDoctest(doctests.Doctest):'
691 698 to exclude any filename which matches them from inclusion in the test
692 699 suite (using pattern.search(), NOT pattern.match() ).
693 700 """
701
694 702 if exclude_patterns is None:
695 703 exclude_patterns = []
696 704 self.exclude_patterns = map(re.compile,exclude_patterns)
@@ -836,11 +844,30 b' class IPythonDoctest(ExtensionDoctest):'
836 844 optionflags=optionflags,
837 845 checker=self.checker)
838 846
839 def configure(self, options, config):
847 def options(self, parser, env=os.environ):
848 Plugin.options(self, parser, env)
849 parser.add_option('--ipdoctest-tests', action='store_true',
850 dest='ipdoctest_tests',
851 default=env.get('NOSE_IPDOCTEST_TESTS',True),
852 help="Also look for doctests in test modules. "
853 "Note that classes, methods and functions should "
854 "have either doctests or non-doctest tests, "
855 "not both. [NOSE_IPDOCTEST_TESTS]")
856 parser.add_option('--ipdoctest-extension', action="append",
857 dest="ipdoctestExtension",
858 help="Also look for doctests in files with "
859 "this extension [NOSE_IPDOCTEST_EXTENSION]")
860 # Set the default as a list, if given in env; otherwise
861 # an additional value set on the command line will cause
862 # an error.
863 env_setting = env.get('NOSE_IPDOCTEST_EXTENSION')
864 if env_setting is not None:
865 parser.set_defaults(ipdoctestExtension=tolist(env_setting))
840 866
867 def configure(self, options, config):
841 868 Plugin.configure(self, options, config)
842 self.doctest_tests = options.doctest_tests
843 self.extension = tolist(options.doctestExtension)
869 self.doctest_tests = options.ipdoctest_tests
870 self.extension = tolist(options.ipdoctestExtension)
844 871
845 872 self.parser = IPDocTestParser()
846 873 self.finder = DocTestFinder(parser=self.parser)
@@ -6,8 +6,9 b' This is used by a companion test case.'
6 6 import gc
7 7
8 8 class C(object):
9 def __del__(self):
10 print 'deleting object...'
9 def __del__(self):
10 pass
11 #print 'deleting object...' # dbg
11 12
12 13 c = C()
13 14
@@ -39,13 +39,10 b' def doctest_ivars():'
39 39 Out[6]: 1
40 40 """
41 41
42 @dec.skip_doctest
42 #@dec.skip_doctest
43 43 def doctest_refs():
44 44 """DocTest reference holding issues when running scripts.
45 45
46 46 In [32]: run show_refs.py
47 47 c referrers: [<type 'dict'>]
48
49 In [33]: map(type,gc.get_referrers(c))
50 Out[33]: [<type 'dict'>]
51 48 """
@@ -26,7 +26,7 b' import sys'
26 26
27 27 class A(object):
28 28 def __del__(self):
29 print 'object A deleted'
29 print 'obj_del.py: object A deleted'
30 30
31 31 a = A()
32 32
@@ -16,11 +16,12 b' class C(object):'
16 16 self.name = name
17 17
18 18 def __del__(self):
19 print 'Deleting object:',self.name
19 print 'tclass.py: deleting object:',self.name
20 20
21 21 try:
22 22 name = sys.argv[1]
23 23 except IndexError:
24 24 pass
25 25 else:
26 c = C(name)
26 if name.startswith('C'):
27 c = C(name)
@@ -37,7 +37,7 b' def test_rehashx():'
37 37 def doctest_run_ns():
38 38 """Classes declared %run scripts must be instantiable afterwards.
39 39
40 In [11]: run tclass
40 In [11]: run tclass foo
41 41
42 42 In [12]: isinstance(f(),foo)
43 43 Out[12]: True
@@ -47,12 +47,10 b' def doctest_run_ns():'
47 47 def doctest_run_ns2():
48 48 """Classes declared %run scripts must be instantiable afterwards.
49 49
50 In [3]: run tclass.py
50 In [4]: run tclass C-first_pass
51 51
52 In [4]: run tclass first_pass
53
54 In [5]: run tclass second_pass
55 Deleting object: first_pass
52 In [5]: run tclass C-second_pass
53 tclass.py: deleting object: C-first_pass
56 54 """
57 55
58 56
@@ -85,7 +83,7 b' def test_obj_del():'
85 83 test_dir = os.path.dirname(__file__)
86 84 del_file = os.path.join(test_dir,'obj_del.py')
87 85 out = _ip.IP.getoutput('ipython %s' % del_file)
88 nt.assert_equals(out,'object A deleted')
86 nt.assert_equals(out,'obj_del.py: object A deleted')
89 87
90 88
91 89 def test_shist():
General Comments 0
You need to be logged in to leave comments. Login now