Show More
@@ -122,7 +122,7 b' class TimeitTemplateFiller(ast.NodeTransformer):' | |||
|
122 | 122 | |
|
123 | 123 | class Timer(timeit.Timer): |
|
124 | 124 | """Timer class that explicitly uses self.inner |
|
125 | ||
|
125 | ||
|
126 | 126 | which is an undocumented implementation detail of CPython, |
|
127 | 127 | not shared by PyPy. |
|
128 | 128 | """ |
@@ -462,7 +462,7 b' python-profiler package from non-free.""")' | |||
|
462 | 462 | """Run the named file inside IPython as a program. |
|
463 | 463 | |
|
464 | 464 | Usage:: |
|
465 | ||
|
465 | ||
|
466 | 466 | %run [-n -i -e -G] |
|
467 | 467 | [( -t [-N<N>] | -d [-b<N>] | -p [profile options] )] |
|
468 | 468 | ( -m mod | file ) [args] |
@@ -657,7 +657,7 b' python-profiler package from non-free.""")' | |||
|
657 | 657 | __name__save = self.shell.user_ns['__name__'] |
|
658 | 658 | prog_ns['__name__'] = '__main__' |
|
659 | 659 | main_mod = self.shell.user_module |
|
660 | ||
|
660 | ||
|
661 | 661 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must |
|
662 | 662 | # set the __file__ global in the script's namespace |
|
663 | 663 | # TK: Is this necessary in interactive mode? |
@@ -857,7 +857,7 b' python-profiler package from non-free.""")' | |||
|
857 | 857 | continue |
|
858 | 858 | else: |
|
859 | 859 | break |
|
860 | ||
|
860 | ||
|
861 | 861 | |
|
862 | 862 | except: |
|
863 | 863 | etype, value, tb = sys.exc_info() |
@@ -983,7 +983,7 b' python-profiler package from non-free.""")' | |||
|
983 | 983 | posix=False, strict=False) |
|
984 | 984 | if stmt == "" and cell is None: |
|
985 | 985 | return |
|
986 | ||
|
986 | ||
|
987 | 987 | timefunc = timeit.default_timer |
|
988 | 988 | number = int(getattr(opts, "n", 0)) |
|
989 | 989 | default_repeat = 7 if timeit.default_repeat < 7 else timeit.default_repeat |
@@ -1093,16 +1093,16 b' python-profiler package from non-free.""")' | |||
|
1093 | 1093 | The CPU and wall clock times are printed, and the value of the |
|
1094 | 1094 | expression (if any) is returned. Note that under Win32, system time |
|
1095 | 1095 | is always reported as 0, since it can not be measured. |
|
1096 | ||
|
1096 | ||
|
1097 | 1097 | This function can be used both as a line and cell magic: |
|
1098 | 1098 | |
|
1099 | 1099 | - In line mode you can time a single-line statement (though multiple |
|
1100 | 1100 | ones can be chained with using semicolons). |
|
1101 | 1101 | |
|
1102 | - In cell mode, you can time the cell body (a directly | |
|
1102 | - In cell mode, you can time the cell body (a directly | |
|
1103 | 1103 | following statement raises an error). |
|
1104 | 1104 | |
|
1105 | This function provides very basic timing functionality. Use the timeit | |
|
1105 | This function provides very basic timing functionality. Use the timeit | |
|
1106 | 1106 | magic for more control over the measurement. |
|
1107 | 1107 | |
|
1108 | 1108 | Examples |
@@ -1143,10 +1143,10 b' python-profiler package from non-free.""")' | |||
|
1143 | 1143 | """ |
|
1144 | 1144 | |
|
1145 | 1145 | # fail immediately if the given expression can't be compiled |
|
1146 | ||
|
1146 | ||
|
1147 | 1147 | if line and cell: |
|
1148 | 1148 | raise UsageError("Can't use statement directly after '%%time'!") |
|
1149 | ||
|
1149 | ||
|
1150 | 1150 | if cell: |
|
1151 | 1151 | expr = self.shell.input_transformer_manager.transform_cell(cell) |
|
1152 | 1152 | else: |
@@ -1196,7 +1196,7 b' python-profiler package from non-free.""")' | |||
|
1196 | 1196 | cpu_user = end[0]-st[0] |
|
1197 | 1197 | cpu_sys = end[1]-st[1] |
|
1198 | 1198 | cpu_tot = cpu_user+cpu_sys |
|
1199 | # On windows cpu_sys is always zero, so no new information to the next print | |
|
1199 | # On windows cpu_sys is always zero, so no new information to the next print | |
|
1200 | 1200 | if sys.platform != 'win32': |
|
1201 | 1201 | print("CPU times: user %s, sys: %s, total: %s" % \ |
|
1202 | 1202 | (_format_time(cpu_user),_format_time(cpu_sys),_format_time(cpu_tot))) |
@@ -1222,9 +1222,9 b' python-profiler package from non-free.""")' | |||
|
1222 | 1222 | so that magics are loaded in their transformed version to valid |
|
1223 | 1223 | Python. If this option is given, the raw input as typed at the |
|
1224 | 1224 | command line is used instead. |
|
1225 | ||
|
1226 | -q: quiet macro definition. By default, a tag line is printed | |
|
1227 | to indicate the macro has been created, and then the contents of | |
|
1225 | ||
|
1226 | -q: quiet macro definition. By default, a tag line is printed | |
|
1227 | to indicate the macro has been created, and then the contents of | |
|
1228 | 1228 | the macro are printed. If this option is given, then no printout |
|
1229 | 1229 | is produced once the macro is created. |
|
1230 | 1230 | |
@@ -1287,7 +1287,7 b' python-profiler package from non-free.""")' | |||
|
1287 | 1287 | return |
|
1288 | 1288 | macro = Macro(lines) |
|
1289 | 1289 | self.shell.define_macro(name, macro) |
|
1290 | if not ( 'q' in opts) : | |
|
1290 | if not ( 'q' in opts) : | |
|
1291 | 1291 | print('Macro `%s` created. To execute, type its name (without quotes).' % name) |
|
1292 | 1292 | print('=== Macro contents: ===') |
|
1293 | 1293 | print(macro, end=' ') |
@@ -1333,7 +1333,7 b' def parse_breakpoint(text, current_file):' | |||
|
1333 | 1333 | return current_file, int(text) |
|
1334 | 1334 | else: |
|
1335 | 1335 | return text[:colon], int(text[colon+1:]) |
|
1336 | ||
|
1336 | ||
|
1337 | 1337 | def _format_time(timespan, precision=3): |
|
1338 | 1338 | """Formats the timespan in a human readable form""" |
|
1339 | 1339 | |
@@ -1352,13 +1352,13 b' def _format_time(timespan, precision=3):' | |||
|
1352 | 1352 | break |
|
1353 | 1353 | return " ".join(time) |
|
1354 | 1354 | |
|
1355 | ||
|
1355 | ||
|
1356 | 1356 | # Unfortunately the unicode 'micro' symbol can cause problems in |
|
1357 | # certain terminals. | |
|
1357 | # certain terminals. | |
|
1358 | 1358 | # See bug: https://bugs.launchpad.net/ipython/+bug/348466 |
|
1359 | 1359 | # Try to prevent crashes by being more secure than it needs to |
|
1360 | 1360 | # E.g. eclipse is able to print a Β΅, but has no sys.stdout.encoding set. |
|
1361 | units = [u"s", u"ms",u'us',"ns"] # the save value | |
|
1361 | units = [u"s", u"ms",u'us',"ns"] # the save value | |
|
1362 | 1362 | if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding: |
|
1363 | 1363 | try: |
|
1364 | 1364 | u'\xb5'.encode(sys.stdout.encoding) |
@@ -1366,7 +1366,7 b' def _format_time(timespan, precision=3):' | |||
|
1366 | 1366 | except: |
|
1367 | 1367 | pass |
|
1368 | 1368 | scaling = [1, 1e3, 1e6, 1e9] |
|
1369 | ||
|
1369 | ||
|
1370 | 1370 | if timespan > 0.0: |
|
1371 | 1371 | order = min(-int(math.floor(math.log10(timespan)) // 3), 3) |
|
1372 | 1372 | else: |
@@ -120,16 +120,16 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
120 | 120 | newlen = len(ip.user_ns['In']) |
|
121 | 121 | self.assertEqual(oldlen+1, newlen) |
|
122 | 122 | self.assertEqual(ip.user_ns['In'][-1],'1;') |
|
123 | ||
|
123 | ||
|
124 | 124 | def test_magic_names_in_string(self): |
|
125 | 125 | ip.run_cell('a = """\n%exit\n"""') |
|
126 | 126 | self.assertEqual(ip.user_ns['a'], '\n%exit\n') |
|
127 | ||
|
127 | ||
|
128 | 128 | def test_trailing_newline(self): |
|
129 | 129 | """test that running !(command) does not raise a SyntaxError""" |
|
130 | 130 | ip.run_cell('!(true)\n', False) |
|
131 | 131 | ip.run_cell('!(true)\n\n\n', False) |
|
132 | ||
|
132 | ||
|
133 | 133 | def test_gh_597(self): |
|
134 | 134 | """Pretty-printing lists of objects with non-ascii reprs may cause |
|
135 | 135 | problems.""" |
@@ -139,7 +139,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
139 | 139 | import IPython.core.formatters |
|
140 | 140 | f = IPython.core.formatters.PlainTextFormatter() |
|
141 | 141 | f([Spam(),Spam()]) |
|
142 | ||
|
142 | ||
|
143 | 143 | |
|
144 | 144 | def test_future_flags(self): |
|
145 | 145 | """Check that future flags are used for parsing code (gh-777)""" |
@@ -162,7 +162,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
162 | 162 | finally: |
|
163 | 163 | # Reset compiler flags so we don't mess up other tests. |
|
164 | 164 | ip.compile.reset_compiler_flags() |
|
165 | ||
|
165 | ||
|
166 | 166 | def test_can_pickle(self): |
|
167 | 167 | "Can we pickle objects defined interactively (GH-29)" |
|
168 | 168 | ip = get_ipython() |
@@ -171,9 +171,9 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
171 | 171 | " def __init__(self,x=[]):\n" |
|
172 | 172 | " list.__init__(self,x)")) |
|
173 | 173 | ip.run_cell("w=Mylist([1,2,3])") |
|
174 | ||
|
174 | ||
|
175 | 175 | from pickle import dumps |
|
176 | ||
|
176 | ||
|
177 | 177 | # We need to swap in our main module - this is only necessary |
|
178 | 178 | # inside the test framework, because IPython puts the interactive module |
|
179 | 179 | # in place (but the test framework undoes this). |
@@ -184,7 +184,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
184 | 184 | finally: |
|
185 | 185 | sys.modules['__main__'] = _main |
|
186 | 186 | self.assertTrue(isinstance(res, bytes)) |
|
187 | ||
|
187 | ||
|
188 | 188 | def test_global_ns(self): |
|
189 | 189 | "Code in functions must be able to access variables outside them." |
|
190 | 190 | ip = get_ipython() |
@@ -234,7 +234,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
234 | 234 | ip.user_ns['f'] = b'Ca\xc3\xb1o' |
|
235 | 235 | # This should not raise any exception: |
|
236 | 236 | ip.var_expand(u'echo $f') |
|
237 | ||
|
237 | ||
|
238 | 238 | def test_var_expand_local(self): |
|
239 | 239 | """Test local variable expansion in !system and %magic calls""" |
|
240 | 240 | # !system |
@@ -244,7 +244,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
244 | 244 | ' return ret[0]\n') |
|
245 | 245 | res = ip.user_ns['test']() |
|
246 | 246 | nt.assert_in('ttt', res) |
|
247 | ||
|
247 | ||
|
248 | 248 | # %magic |
|
249 | 249 | ip.run_cell('def makemacro():\n' |
|
250 | 250 | ' macroname = "macro_var_expand_locals"\n' |
@@ -252,10 +252,10 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
252 | 252 | ip.user_ns['codestr'] = "str(12)" |
|
253 | 253 | ip.run_cell('makemacro()') |
|
254 | 254 | nt.assert_in('macro_var_expand_locals', ip.user_ns) |
|
255 | ||
|
255 | ||
|
256 | 256 | def test_var_expand_self(self): |
|
257 | 257 | """Test variable expansion with the name 'self', which was failing. |
|
258 | ||
|
258 | ||
|
259 | 259 | See https://github.com/ipython/ipython/issues/1878#issuecomment-7698218 |
|
260 | 260 | """ |
|
261 | 261 | ip.run_cell('class cTest:\n' |
@@ -264,7 +264,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
264 | 264 | ' res = !echo Variable: {self.classvar}\n' |
|
265 | 265 | ' return res[0]\n') |
|
266 | 266 | nt.assert_in('see me', ip.user_ns['cTest']().test()) |
|
267 | ||
|
267 | ||
|
268 | 268 | def test_bad_var_expand(self): |
|
269 | 269 | """var_expand on invalid formats shouldn't raise""" |
|
270 | 270 | # SyntaxError |
@@ -273,19 +273,19 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
273 | 273 | self.assertEqual(ip.var_expand(u"{asdf}"), u"{asdf}") |
|
274 | 274 | # ZeroDivisionError |
|
275 | 275 | self.assertEqual(ip.var_expand(u"{1/0}"), u"{1/0}") |
|
276 | ||
|
276 | ||
|
277 | 277 | def test_silent_postexec(self): |
|
278 | 278 | """run_cell(silent=True) doesn't invoke pre/post_run_cell callbacks""" |
|
279 | 279 | pre_explicit = mock.Mock() |
|
280 | 280 | pre_always = mock.Mock() |
|
281 | 281 | post_explicit = mock.Mock() |
|
282 | 282 | post_always = mock.Mock() |
|
283 | ||
|
283 | ||
|
284 | 284 | ip.events.register('pre_run_cell', pre_explicit) |
|
285 | 285 | ip.events.register('pre_execute', pre_always) |
|
286 | 286 | ip.events.register('post_run_cell', post_explicit) |
|
287 | 287 | ip.events.register('post_execute', post_always) |
|
288 | ||
|
288 | ||
|
289 | 289 | try: |
|
290 | 290 | ip.run_cell("1", silent=True) |
|
291 | 291 | assert pre_always.called |
@@ -303,29 +303,29 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
303 | 303 | ip.events.unregister('pre_execute', pre_always) |
|
304 | 304 | ip.events.unregister('post_run_cell', post_explicit) |
|
305 | 305 | ip.events.unregister('post_execute', post_always) |
|
306 | ||
|
306 | ||
|
307 | 307 | def test_silent_noadvance(self): |
|
308 | 308 | """run_cell(silent=True) doesn't advance execution_count""" |
|
309 | 309 | ec = ip.execution_count |
|
310 | 310 | # silent should force store_history=False |
|
311 | 311 | ip.run_cell("1", store_history=True, silent=True) |
|
312 | ||
|
312 | ||
|
313 | 313 | self.assertEqual(ec, ip.execution_count) |
|
314 | 314 | # double-check that non-silent exec did what we expected |
|
315 | 315 | # silent to avoid |
|
316 | 316 | ip.run_cell("1", store_history=True) |
|
317 | 317 | self.assertEqual(ec+1, ip.execution_count) |
|
318 | ||
|
318 | ||
|
319 | 319 | def test_silent_nodisplayhook(self): |
|
320 | 320 | """run_cell(silent=True) doesn't trigger displayhook""" |
|
321 | 321 | d = dict(called=False) |
|
322 | ||
|
322 | ||
|
323 | 323 | trap = ip.display_trap |
|
324 | 324 | save_hook = trap.hook |
|
325 | ||
|
325 | ||
|
326 | 326 | def failing_hook(*args, **kwargs): |
|
327 | 327 | d['called'] = True |
|
328 | ||
|
328 | ||
|
329 | 329 | try: |
|
330 | 330 | trap.hook = failing_hook |
|
331 | 331 | res = ip.run_cell("1", silent=True) |
@@ -350,10 +350,10 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
350 | 350 | In [2]: print 1,; print 2 |
|
351 | 351 | 1 2 |
|
352 | 352 | """ |
|
353 | ||
|
353 | ||
|
354 | 354 | def test_ofind_line_magic(self): |
|
355 | 355 | from IPython.core.magic import register_line_magic |
|
356 | ||
|
356 | ||
|
357 | 357 | @register_line_magic |
|
358 | 358 | def lmagic(line): |
|
359 | 359 | "A line magic" |
@@ -364,10 +364,10 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
364 | 364 | namespace = 'IPython internal', obj= lmagic.__wrapped__, |
|
365 | 365 | parent = None) |
|
366 | 366 | nt.assert_equal(lfind, info) |
|
367 | ||
|
367 | ||
|
368 | 368 | def test_ofind_cell_magic(self): |
|
369 | 369 | from IPython.core.magic import register_cell_magic |
|
370 | ||
|
370 | ||
|
371 | 371 | @register_cell_magic |
|
372 | 372 | def cmagic(line, cell): |
|
373 | 373 | "A cell magic" |
@@ -454,7 +454,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
454 | 454 | def my_handler(shell, etype, value, tb, tb_offset=None): |
|
455 | 455 | called.append(etype) |
|
456 | 456 | shell.showtraceback((etype, value, tb), tb_offset=tb_offset) |
|
457 | ||
|
457 | ||
|
458 | 458 | ip.set_custom_exc((ValueError,), my_handler) |
|
459 | 459 | try: |
|
460 | 460 | res = ip.run_cell("raise ValueError('test')") |
@@ -465,7 +465,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
465 | 465 | finally: |
|
466 | 466 | # Reset the custom exception hook |
|
467 | 467 | ip.set_custom_exc((), None) |
|
468 | ||
|
468 | ||
|
469 | 469 | @skipif(sys.version_info[0] >= 3, "no differences with __future__ in py3") |
|
470 | 470 | def test_future_environment(self): |
|
471 | 471 | "Can we run code with & without the shell's __future__ imports?" |
@@ -474,7 +474,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
474 | 474 | self.assertEqual(ip.user_ns['a'], 0.5) |
|
475 | 475 | ip.run_cell("b = 1/2", shell_futures=False) |
|
476 | 476 | self.assertEqual(ip.user_ns['b'], 0) |
|
477 | ||
|
477 | ||
|
478 | 478 | ip.compile.reset_compiler_flags() |
|
479 | 479 | # This shouldn't leak to the shell's compiler |
|
480 | 480 | ip.run_cell("from __future__ import division \nc=1/2", shell_futures=False) |
@@ -551,7 +551,7 b' class ExitCodeChecks(tt.TempFileMixin):' | |||
|
551 | 551 | def test_exit_code_error(self): |
|
552 | 552 | self.system('exit 1') |
|
553 | 553 | self.assertEqual(ip.user_ns['_exit_code'], 1) |
|
554 | ||
|
554 | ||
|
555 | 555 | @skipif(not hasattr(signal, 'SIGALRM')) |
|
556 | 556 | def test_exit_code_signal(self): |
|
557 | 557 | self.mktmp("import signal, time\n" |
@@ -559,7 +559,7 b' class ExitCodeChecks(tt.TempFileMixin):' | |||
|
559 | 559 | "time.sleep(1)\n") |
|
560 | 560 | self.system("%s %s" % (sys.executable, self.fname)) |
|
561 | 561 | self.assertEqual(ip.user_ns['_exit_code'], -signal.SIGALRM) |
|
562 | ||
|
562 | ||
|
563 | 563 | @onlyif_cmds_exist("csh") |
|
564 | 564 | def test_exit_code_signal_csh(self): |
|
565 | 565 | SHELL = os.environ.get('SHELL', None) |
@@ -630,26 +630,26 b' class TestAstTransform(unittest.TestCase):' | |||
|
630 | 630 | def setUp(self): |
|
631 | 631 | self.negator = Negator() |
|
632 | 632 | ip.ast_transformers.append(self.negator) |
|
633 | ||
|
633 | ||
|
634 | 634 | def tearDown(self): |
|
635 | 635 | ip.ast_transformers.remove(self.negator) |
|
636 | ||
|
636 | ||
|
637 | 637 | def test_run_cell(self): |
|
638 | 638 | with tt.AssertPrints('-34'): |
|
639 | 639 | ip.run_cell('print (12 + 22)') |
|
640 | ||
|
640 | ||
|
641 | 641 | # A named reference to a number shouldn't be transformed. |
|
642 | 642 | ip.user_ns['n'] = 55 |
|
643 | 643 | with tt.AssertNotPrints('-55'): |
|
644 | 644 | ip.run_cell('print (n)') |
|
645 | ||
|
645 | ||
|
646 | 646 | def test_timeit(self): |
|
647 | 647 | called = set() |
|
648 | 648 | def f(x): |
|
649 | 649 | called.add(x) |
|
650 | 650 | ip.push({'f':f}) |
|
651 | ||
|
652 |
with tt.AssertPrints(" |
|
|
651 | ||
|
652 | with tt.AssertPrints("best of "): | |
|
653 | 653 | ip.run_line_magic("timeit", "-n1 f(1)") |
|
654 | 654 | self.assertEqual(called, {-1}) |
|
655 | 655 | called.clear() |
@@ -657,29 +657,29 b' class TestAstTransform(unittest.TestCase):' | |||
|
657 | 657 | with tt.AssertPrints("average of "): |
|
658 | 658 | ip.run_cell_magic("timeit", "-n1 f(2)", "f(3)") |
|
659 | 659 | self.assertEqual(called, {-2, -3}) |
|
660 | ||
|
660 | ||
|
661 | 661 | def test_time(self): |
|
662 | 662 | called = [] |
|
663 | 663 | def f(x): |
|
664 | 664 | called.append(x) |
|
665 | 665 | ip.push({'f':f}) |
|
666 | ||
|
666 | ||
|
667 | 667 | # Test with an expression |
|
668 | 668 | with tt.AssertPrints("Wall time: "): |
|
669 | 669 | ip.run_line_magic("time", "f(5+9)") |
|
670 | 670 | self.assertEqual(called, [-14]) |
|
671 | 671 | called[:] = [] |
|
672 | ||
|
672 | ||
|
673 | 673 | # Test with a statement (different code path) |
|
674 | 674 | with tt.AssertPrints("Wall time: "): |
|
675 | 675 | ip.run_line_magic("time", "a = f(-3 + -2)") |
|
676 | 676 | self.assertEqual(called, [5]) |
|
677 | ||
|
677 | ||
|
678 | 678 | def test_macro(self): |
|
679 | 679 | ip.push({'a':10}) |
|
680 | 680 | # The AST transformation makes this do a+=-1 |
|
681 | 681 | ip.define_macro("amacro", "a+=1\nprint(a)") |
|
682 | ||
|
682 | ||
|
683 | 683 | with tt.AssertPrints("9"): |
|
684 | 684 | ip.run_cell("amacro") |
|
685 | 685 | with tt.AssertPrints("8"): |
@@ -697,25 +697,25 b' class TestAstTransform2(unittest.TestCase):' | |||
|
697 | 697 | def setUp(self): |
|
698 | 698 | self.intwrapper = IntegerWrapper() |
|
699 | 699 | ip.ast_transformers.append(self.intwrapper) |
|
700 | ||
|
700 | ||
|
701 | 701 | self.calls = [] |
|
702 | 702 | def Integer(*args): |
|
703 | 703 | self.calls.append(args) |
|
704 | 704 | return args |
|
705 | 705 | ip.push({"Integer": Integer}) |
|
706 | ||
|
706 | ||
|
707 | 707 | def tearDown(self): |
|
708 | 708 | ip.ast_transformers.remove(self.intwrapper) |
|
709 | 709 | del ip.user_ns['Integer'] |
|
710 | ||
|
710 | ||
|
711 | 711 | def test_run_cell(self): |
|
712 | 712 | ip.run_cell("n = 2") |
|
713 | 713 | self.assertEqual(self.calls, [(2,)]) |
|
714 | ||
|
714 | ||
|
715 | 715 | # This shouldn't throw an error |
|
716 | 716 | ip.run_cell("o = 2.0") |
|
717 | 717 | self.assertEqual(ip.user_ns['o'], 2.0) |
|
718 | ||
|
718 | ||
|
719 | 719 | def test_timeit(self): |
|
720 | 720 | called = set() |
|
721 | 721 | def f(x): |
@@ -740,10 +740,10 b' class TestAstTransformError(unittest.TestCase):' | |||
|
740 | 740 | def test_unregistering(self): |
|
741 | 741 | err_transformer = ErrorTransformer() |
|
742 | 742 | ip.ast_transformers.append(err_transformer) |
|
743 | ||
|
743 | ||
|
744 | 744 | with tt.AssertPrints("unregister", channel='stderr'): |
|
745 | 745 | ip.run_cell("1 + 2") |
|
746 | ||
|
746 | ||
|
747 | 747 | # This should have been removed. |
|
748 | 748 | nt.assert_not_in(err_transformer, ip.ast_transformers) |
|
749 | 749 | |
@@ -792,18 +792,18 b' def test__IPYTHON__():' | |||
|
792 | 792 | class DummyRepr(object): |
|
793 | 793 | def __repr__(self): |
|
794 | 794 | return "DummyRepr" |
|
795 | ||
|
795 | ||
|
796 | 796 | def _repr_html_(self): |
|
797 | 797 | return "<b>dummy</b>" |
|
798 | ||
|
798 | ||
|
799 | 799 | def _repr_javascript_(self): |
|
800 | 800 | return "console.log('hi');", {'key': 'value'} |
|
801 | ||
|
801 | ||
|
802 | 802 | |
|
803 | 803 | def test_user_variables(): |
|
804 | 804 | # enable all formatters |
|
805 | 805 | ip.display_formatter.active_types = ip.display_formatter.format_types |
|
806 | ||
|
806 | ||
|
807 | 807 | ip.user_ns['dummy'] = d = DummyRepr() |
|
808 | 808 | keys = {'dummy', 'doesnotexist'} |
|
809 | 809 | r = ip.user_expressions({ key:key for key in keys}) |
@@ -818,14 +818,14 b' def test_user_variables():' | |||
|
818 | 818 | js, jsmd = d._repr_javascript_() |
|
819 | 819 | nt.assert_equal(data.get('application/javascript'), js) |
|
820 | 820 | nt.assert_equal(metadata.get('application/javascript'), jsmd) |
|
821 | ||
|
821 | ||
|
822 | 822 | dne = r['doesnotexist'] |
|
823 | 823 | nt.assert_equal(dne['status'], 'error') |
|
824 | 824 | nt.assert_equal(dne['ename'], 'NameError') |
|
825 | ||
|
825 | ||
|
826 | 826 | # back to text only |
|
827 | 827 | ip.display_formatter.active_types = ['text/plain'] |
|
828 | ||
|
828 | ||
|
829 | 829 | def test_user_expression(): |
|
830 | 830 | # enable all formatters |
|
831 | 831 | ip.display_formatter.active_types = ip.display_formatter.format_types |
@@ -843,14 +843,14 b' def test_user_expression():' | |||
|
843 | 843 | data = a['data'] |
|
844 | 844 | metadata = a['metadata'] |
|
845 | 845 | nt.assert_equal(data.get('text/plain'), '3') |
|
846 | ||
|
846 | ||
|
847 | 847 | b = r['b'] |
|
848 | 848 | nt.assert_equal(b['status'], 'error') |
|
849 | 849 | nt.assert_equal(b['ename'], 'ZeroDivisionError') |
|
850 | ||
|
850 | ||
|
851 | 851 | # back to text only |
|
852 | 852 | ip.display_formatter.active_types = ['text/plain'] |
|
853 | ||
|
853 | ||
|
854 | 854 | |
|
855 | 855 | |
|
856 | 856 |
General Comments 0
You need to be logged in to leave comments.
Login now