Show More
@@ -97,17 +97,22 b' class ncdict(dict):' | |||||
97 | # with the test globals. Once we move over to a clean magic system, this will |
|
97 | # with the test globals. Once we move over to a clean magic system, this will | |
98 | # be done with much less ugliness. |
|
98 | # be done with much less ugliness. | |
99 |
|
99 | |||
100 |
def |
|
100 | def _run_ns_sync(self,arg_s,runner=None): | |
101 | """ |
|
101 | """Modified version of %run that syncs testing namespaces. | |
|
102 | ||||
|
103 | This is strictly needed for running doctests that call %run. | |||
102 | """ |
|
104 | """ | |
103 | #print 'HA!' # dbg |
|
105 | ||
104 |
|
106 | out = _ip.IP.magic_run_ori(arg_s,runner) | ||
105 | return _ip.IP.magic_run_ori(arg_s,runner) |
|
107 | _run_ns_sync.test_globs.update(_ip.user_ns) | |
|
108 | return out | |||
106 |
|
109 | |||
107 |
|
110 | |||
108 | def start_ipython(): |
|
111 | def start_ipython(): | |
109 | """Start a global IPython shell, which we need for IPython-specific syntax. |
|
112 | """Start a global IPython shell, which we need for IPython-specific syntax. | |
110 | """ |
|
113 | """ | |
|
114 | import new | |||
|
115 | ||||
111 | import IPython |
|
116 | import IPython | |
112 |
|
117 | |||
113 | def xsys(cmd): |
|
118 | def xsys(cmd): | |
@@ -147,8 +152,7 b' def start_ipython():' | |||||
147 | # doctest machinery would miss them. |
|
152 | # doctest machinery would miss them. | |
148 | _ip.system = xsys |
|
153 | _ip.system = xsys | |
149 |
|
154 | |||
150 | import new |
|
155 | im = new.instancemethod(_run_ns_sync,_ip.IP, _ip.IP.__class__) | |
151 | im = new.instancemethod(_my_run,_ip.IP, _ip.IP.__class__) |
|
|||
152 | _ip.IP.magic_run_ori = _ip.IP.magic_run |
|
156 | _ip.IP.magic_run_ori = _ip.IP.magic_run | |
153 | _ip.IP.magic_run = im |
|
157 | _ip.IP.magic_run = im | |
154 |
|
158 | |||
@@ -648,13 +652,19 b' class IPDocTestRunner(doctest.DocTestRunner):' | |||||
648 | # keyboard interrupts.) |
|
652 | # keyboard interrupts.) | |
649 | try: |
|
653 | try: | |
650 | # Don't blink! This is where the user's code gets run. |
|
654 | # Don't blink! This is where the user's code gets run. | |
|
655 | ||||
|
656 | # Hack: ipython needs access to the execution context of the | |||
|
657 | # example, so that it can propagate user variables loaded by | |||
|
658 | # %run into test.globs. We put them here into our modified | |||
|
659 | # %run as a function attribute. Our new %run will then only | |||
|
660 | # make the namespace update when called (rather than | |||
|
661 | # unconconditionally updating test.globs here for all examples, | |||
|
662 | # most of which won't be calling %run anyway). | |||
|
663 | _run_ns_sync.test_globs = test.globs | |||
|
664 | ||||
651 | exec compile(example.source, filename, "single", |
|
665 | exec compile(example.source, filename, "single", | |
652 | compileflags, 1) in test.globs |
|
666 | compileflags, 1) in test.globs | |
653 | self.debugger.set_continue() # ==== Example Finished ==== |
|
667 | self.debugger.set_continue() # ==== Example Finished ==== | |
654 | # ipython |
|
|||
655 | #_ip.user_ns.update(test.globs) |
|
|||
656 | test.globs.update(_ip.user_ns) |
|
|||
657 | # |
|
|||
658 | exception = None |
|
668 | exception = None | |
659 | except KeyboardInterrupt: |
|
669 | except KeyboardInterrupt: | |
660 | raise |
|
670 | raise | |
@@ -726,6 +736,10 b' class IPDocTestRunner(doctest.DocTestRunner):' | |||||
726 | return failures, tries |
|
736 | return failures, tries | |
727 |
|
737 | |||
728 |
|
738 | |||
|
739 | # Unfortunately doctest has chosen to implement a couple of key methods as | |||
|
740 | # private (__run, in particular). We are forced to copy the entire run | |||
|
741 | # method here just so we can override that one. Ugh. | |||
|
742 | ||||
729 | def run(self, test, compileflags=None, out=None, clear_globs=True): |
|
743 | def run(self, test, compileflags=None, out=None, clear_globs=True): | |
730 | """ |
|
744 | """ | |
731 | Run the examples in `test`, and display the results using the |
|
745 | Run the examples in `test`, and display the results using the |
General Comments 0
You need to be logged in to leave comments.
Login now