##// END OF EJS Templates
- Make ipdoctest a little cleaner by giving it separate option names....
Fernando Perez -
r1910:8bc770ab
parent child
Show More
@@ -61,7 +61,7 def main():
61 # plugin needs to be gone through with a fine
61 # plugin needs to be gone through with a fine
62 # toothed comb to find what is causing the problem.
62 # toothed comb to find what is causing the problem.
63 # '--with-ipdoctest',
63 # '--with-ipdoctest',
64 '--doctest-tests','--doctest-extension=txt',
64 '--ipdoctest-tests','--ipdoctest-extension=txt',
65 '--detailed-errors',
65 '--detailed-errors',
66
66
67 # We add --exe because of setuptools' imbecility (it
67 # We add --exe because of setuptools' imbecility (it
@@ -81,11 +81,13 def main():
81 (':' in arg and '.py' in arg):
81 (':' in arg and '.py' in arg):
82 has_tests = True
82 has_tests = True
83 break
83 break
84
84 # If nothing was specifically requested, test full IPython
85 # If nothing was specifically requested, test full IPython
85 if not has_tests:
86 if not has_tests:
86 argv.append('IPython')
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 plugins = [IPythonDoctest(EXCLUDE)]
91 plugins = [IPythonDoctest(EXCLUDE)]
90 for p in nose.plugins.builtin.plugins:
92 for p in nose.plugins.builtin.plugins:
91 plug = p()
93 plug = p()
@@ -123,6 +123,13 class ipnsdict(dict):
123 def start_ipython():
123 def start_ipython():
124 """Start a global IPython shell, which we need for IPython-specific syntax.
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 import new
133 import new
127
134
128 import IPython
135 import IPython
@@ -691,6 +698,7 class ExtensionDoctest(doctests.Doctest):
691 to exclude any filename which matches them from inclusion in the test
698 to exclude any filename which matches them from inclusion in the test
692 suite (using pattern.search(), NOT pattern.match() ).
699 suite (using pattern.search(), NOT pattern.match() ).
693 """
700 """
701
694 if exclude_patterns is None:
702 if exclude_patterns is None:
695 exclude_patterns = []
703 exclude_patterns = []
696 self.exclude_patterns = map(re.compile,exclude_patterns)
704 self.exclude_patterns = map(re.compile,exclude_patterns)
@@ -836,11 +844,30 class IPythonDoctest(ExtensionDoctest):
836 optionflags=optionflags,
844 optionflags=optionflags,
837 checker=self.checker)
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 Plugin.configure(self, options, config)
868 Plugin.configure(self, options, config)
842 self.doctest_tests = options.doctest_tests
869 self.doctest_tests = options.ipdoctest_tests
843 self.extension = tolist(options.doctestExtension)
870 self.extension = tolist(options.ipdoctestExtension)
844
871
845 self.parser = IPDocTestParser()
872 self.parser = IPDocTestParser()
846 self.finder = DocTestFinder(parser=self.parser)
873 self.finder = DocTestFinder(parser=self.parser)
@@ -6,8 +6,9 This is used by a companion test case.
6 import gc
6 import gc
7
7
8 class C(object):
8 class C(object):
9 def __del__(self):
9 def __del__(self):
10 print 'deleting object...'
10 pass
11 #print 'deleting object...' # dbg
11
12
12 c = C()
13 c = C()
13
14
@@ -39,13 +39,10 def doctest_ivars():
39 Out[6]: 1
39 Out[6]: 1
40 """
40 """
41
41
42 @dec.skip_doctest
42 #@dec.skip_doctest
43 def doctest_refs():
43 def doctest_refs():
44 """DocTest reference holding issues when running scripts.
44 """DocTest reference holding issues when running scripts.
45
45
46 In [32]: run show_refs.py
46 In [32]: run show_refs.py
47 c referrers: [<type 'dict'>]
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 import sys
26
26
27 class A(object):
27 class A(object):
28 def __del__(self):
28 def __del__(self):
29 print 'object A deleted'
29 print 'obj_del.py: object A deleted'
30
30
31 a = A()
31 a = A()
32
32
@@ -16,11 +16,12 class C(object):
16 self.name = name
16 self.name = name
17
17
18 def __del__(self):
18 def __del__(self):
19 print 'Deleting object:',self.name
19 print 'tclass.py: deleting object:',self.name
20
20
21 try:
21 try:
22 name = sys.argv[1]
22 name = sys.argv[1]
23 except IndexError:
23 except IndexError:
24 pass
24 pass
25 else:
25 else:
26 c = C(name)
26 if name.startswith('C'):
27 c = C(name)
@@ -37,7 +37,7 def test_rehashx():
37 def doctest_run_ns():
37 def doctest_run_ns():
38 """Classes declared %run scripts must be instantiable afterwards.
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 In [12]: isinstance(f(),foo)
42 In [12]: isinstance(f(),foo)
43 Out[12]: True
43 Out[12]: True
@@ -47,12 +47,10 def doctest_run_ns():
47 def doctest_run_ns2():
47 def doctest_run_ns2():
48 """Classes declared %run scripts must be instantiable afterwards.
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
52 In [5]: run tclass C-second_pass
53
53 tclass.py: deleting object: C-first_pass
54 In [5]: run tclass second_pass
55 Deleting object: first_pass
56 """
54 """
57
55
58
56
@@ -85,7 +83,7 def test_obj_del():
85 test_dir = os.path.dirname(__file__)
83 test_dir = os.path.dirname(__file__)
86 del_file = os.path.join(test_dir,'obj_del.py')
84 del_file = os.path.join(test_dir,'obj_del.py')
87 out = _ip.IP.getoutput('ipython %s' % del_file)
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 def test_shist():
89 def test_shist():
General Comments 0
You need to be logged in to leave comments. Login now