Show More
@@ -23,6 +23,11 import tempfile | |||
|
23 | 23 | import textwrap |
|
24 | 24 | import unittest |
|
25 | 25 | |
|
26 | try: | |
|
27 | from unittest.mock import patch | |
|
28 | except ImportError: | |
|
29 | from mock import patch | |
|
30 | ||
|
26 | 31 | import nose.tools as nt |
|
27 | 32 | from nose import SkipTest |
|
28 | 33 | |
@@ -448,7 +453,7 class TestMagicRunWithPackage(unittest.TestCase): | |||
|
448 | 453 | def with_fake_debugger(func): |
|
449 | 454 | @functools.wraps(func) |
|
450 | 455 | def wrapper(*args, **kwds): |
|
451 |
with |
|
|
456 | with patch.object(debugger.Pdb, 'run', staticmethod(eval)): | |
|
452 | 457 | return func(*args, **kwds) |
|
453 | 458 | return wrapper |
|
454 | 459 |
@@ -5,10 +5,12 | |||
|
5 | 5 | |
|
6 | 6 | from __future__ import print_function |
|
7 | 7 | |
|
8 | from collections import OrderedDict | |
|
8 | try: | |
|
9 | from unittest.mock import patch | |
|
10 | except ImportError: | |
|
11 | from mock import patch | |
|
9 | 12 | |
|
10 | 13 | import nose.tools as nt |
|
11 | import IPython.testing.tools as tt | |
|
12 | 14 | |
|
13 | 15 | from IPython.kernel.comm import Comm |
|
14 | 16 | from IPython.html import widgets |
@@ -354,7 +356,7 def test_priority(): | |||
|
354 | 356 | |
|
355 | 357 | @nt.with_setup(clear_display) |
|
356 | 358 | def test_decorator_kwarg(): |
|
357 |
with |
|
|
359 | with patch.object(interaction, 'display', record_display): | |
|
358 | 360 | @interact(a=5) |
|
359 | 361 | def foo(a): |
|
360 | 362 | pass |
@@ -373,7 +375,7 def test_interact_instancemethod(): | |||
|
373 | 375 | |
|
374 | 376 | f = Foo() |
|
375 | 377 | |
|
376 |
with |
|
|
378 | with patch.object(interaction, 'display', record_display): | |
|
377 | 379 | g = interact(f.show, x=(1,10)) |
|
378 | 380 | nt.assert_equal(len(displayed), 1) |
|
379 | 381 | w = displayed[0].children[0] |
@@ -384,7 +386,7 def test_interact_instancemethod(): | |||
|
384 | 386 | |
|
385 | 387 | @nt.with_setup(clear_display) |
|
386 | 388 | def test_decorator_no_call(): |
|
387 |
with |
|
|
389 | with patch.object(interaction, 'display', record_display): | |
|
388 | 390 | @interact |
|
389 | 391 | def foo(a='default'): |
|
390 | 392 | pass |
@@ -399,7 +401,7 def test_decorator_no_call(): | |||
|
399 | 401 | def test_call_interact(): |
|
400 | 402 | def foo(a='default'): |
|
401 | 403 | pass |
|
402 |
with |
|
|
404 | with patch.object(interaction, 'display', record_display): | |
|
403 | 405 | ifoo = interact(foo) |
|
404 | 406 | nt.assert_equal(len(displayed), 1) |
|
405 | 407 | w = displayed[0].children[0] |
@@ -412,7 +414,7 def test_call_interact(): | |||
|
412 | 414 | def test_call_interact_kwargs(): |
|
413 | 415 | def foo(a='default'): |
|
414 | 416 | pass |
|
415 |
with |
|
|
417 | with patch.object(interaction, 'display', record_display): | |
|
416 | 418 | ifoo = interact(foo, a=10) |
|
417 | 419 | nt.assert_equal(len(displayed), 1) |
|
418 | 420 | w = displayed[0].children[0] |
@@ -425,7 +427,7 def test_call_interact_kwargs(): | |||
|
425 | 427 | def test_call_decorated_on_trait_change(): |
|
426 | 428 | """test calling @interact decorated functions""" |
|
427 | 429 | d = {} |
|
428 |
with |
|
|
430 | with patch.object(interaction, 'display', record_display): | |
|
429 | 431 | @interact |
|
430 | 432 | def foo(a='default'): |
|
431 | 433 | d['a'] = a |
@@ -449,7 +451,7 def test_call_decorated_on_trait_change(): | |||
|
449 | 451 | def test_call_decorated_kwargs_on_trait_change(): |
|
450 | 452 | """test calling @interact(foo=bar) decorated functions""" |
|
451 | 453 | d = {} |
|
452 |
with |
|
|
454 | with patch.object(interaction, 'display', record_display): | |
|
453 | 455 | @interact(a='kwarg') |
|
454 | 456 | def foo(a='default'): |
|
455 | 457 | d['a'] = a |
@@ -1,18 +1,18 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """Tests for IPython.utils.path.py""" |
|
3 | 3 | |
|
4 | #----------------------------------------------------------------------------- | |
|
5 | # Copyright (C) 2008-2011 The IPython Development Team | |
|
6 | # | |
|
7 | # Distributed under the terms of the BSD License. The full license is in | |
|
8 | # the file COPYING, distributed as part of this software. | |
|
9 | #----------------------------------------------------------------------------- | |
|
4 | # Copyright (c) IPython Development Team. | |
|
5 | # Distributed under the terms of the Modified BSD License. | |
|
6 | ||
|
7 | try: | |
|
8 | from unittest.mock import patch | |
|
9 | except ImportError: | |
|
10 | from mock import patch | |
|
10 | 11 | |
|
11 | 12 | import nose.tools as nt |
|
12 | 13 | |
|
13 | 14 | from IPython.lib import latextools |
|
14 | 15 | from IPython.testing.decorators import onlyif_cmds_exist, skipif_not_matplotlib |
|
15 | from IPython.testing.tools import monkeypatch | |
|
16 | 16 | from IPython.utils.process import FindCmdError |
|
17 | 17 | |
|
18 | 18 | |
@@ -29,7 +29,7 def check_latex_to_png_dvipng_fails_when_no_cmd(command): | |||
|
29 | 29 | if arg == command: |
|
30 | 30 | raise FindCmdError |
|
31 | 31 | |
|
32 |
with |
|
|
32 | with patch.object(latextools, "find_cmd", mock_find_cmd): | |
|
33 | 33 | nt.assert_equals(latextools.latex_to_png_dvipng("whatever", True), |
|
34 | 34 | None) |
|
35 | 35 | |
@@ -46,7 +46,7 def test_latex_to_png_dvipng_runs(): | |||
|
46 | 46 | for (s, wrap) in [(u"$$x^2$$", False), (u"x^2", True)]: |
|
47 | 47 | yield (latextools.latex_to_png_dvipng, s, wrap) |
|
48 | 48 | |
|
49 |
with |
|
|
49 | with patch.object(latextools, "kpsewhich", mock_kpsewhich): | |
|
50 | 50 | yield (latextools.latex_to_png_dvipng, s, wrap) |
|
51 | 51 | |
|
52 | 52 | @skipif_not_matplotlib |
@@ -61,7 +61,7 def test_latex_to_png_mpl_runs(): | |||
|
61 | 61 | for (s, wrap) in [("$x^2$", False), ("x^2", True)]: |
|
62 | 62 | yield (latextools.latex_to_png_mpl, s, wrap) |
|
63 | 63 | |
|
64 |
with |
|
|
64 | with patch.object(latextools, "kpsewhich", mock_kpsewhich): | |
|
65 | 65 | yield (latextools.latex_to_png_mpl, s, wrap) |
|
66 | 66 | |
|
67 | 67 | @skipif_not_matplotlib |
@@ -78,7 +78,7 def test_genelatex_no_wrap(): | |||
|
78 | 78 | assert False, ("kpsewhich should not be called " |
|
79 | 79 | "(called with {0})".format(filename)) |
|
80 | 80 | |
|
81 |
with |
|
|
81 | with patch.object(latextools, "kpsewhich", mock_kpsewhich): | |
|
82 | 82 | nt.assert_equals( |
|
83 | 83 | '\n'.join(latextools.genelatex("body text", False)), |
|
84 | 84 | r'''\documentclass{article} |
@@ -100,7 +100,7 def test_genelatex_wrap_with_breqn(): | |||
|
100 | 100 | nt.assert_equals(filename, "breqn.sty") |
|
101 | 101 | return "path/to/breqn.sty" |
|
102 | 102 | |
|
103 |
with |
|
|
103 | with patch.object(latextools, "kpsewhich", mock_kpsewhich): | |
|
104 | 104 | nt.assert_equals( |
|
105 | 105 | '\n'.join(latextools.genelatex("x^2", True)), |
|
106 | 106 | r'''\documentclass{article} |
@@ -125,7 +125,7 def test_genelatex_wrap_without_breqn(): | |||
|
125 | 125 | nt.assert_equals(filename, "breqn.sty") |
|
126 | 126 | return None |
|
127 | 127 | |
|
128 |
with |
|
|
128 | with patch.object(latextools, "kpsewhich", mock_kpsewhich): | |
|
129 | 129 | nt.assert_equals( |
|
130 | 130 | '\n'.join(latextools.genelatex("x^2", True)), |
|
131 | 131 | r'''\documentclass{article} |
@@ -444,17 +444,6 def make_tempfile(name): | |||
|
444 | 444 | os.unlink(name) |
|
445 | 445 | |
|
446 | 446 | |
|
447 | @contextmanager | |
|
448 | def monkeypatch(obj, name, attr): | |
|
449 | """ | |
|
450 | Context manager to replace attribute named `name` in `obj` with `attr`. | |
|
451 | """ | |
|
452 | orig = getattr(obj, name) | |
|
453 | setattr(obj, name, attr) | |
|
454 | yield | |
|
455 | setattr(obj, name, orig) | |
|
456 | ||
|
457 | ||
|
458 | 447 | def help_output_test(subcommand=''): |
|
459 | 448 | """test that `ipython [subcommand] -h` works""" |
|
460 | 449 | cmd = get_ipython_cmd() + [subcommand, '-h'] |
@@ -1,15 +1,16 | |||
|
1 | #----------------------------------------------------------------------------- | |
|
2 | # Copyright (C) 2012 The IPython Development Team | |
|
3 | # | |
|
4 | # Distributed under the terms of the BSD License. The full license is in | |
|
5 | # the file COPYING, distributed as part of this software. | |
|
6 | #----------------------------------------------------------------------------- | |
|
1 | # Copyright (c) IPython Development Team. | |
|
2 | # Distributed under the terms of the Modified BSD License. | |
|
7 | 3 | |
|
8 | 4 | import os |
|
9 | 5 | import sys |
|
10 | 6 | import unittest |
|
11 | 7 | import base64 |
|
12 | 8 | |
|
9 | try: | |
|
10 | from unittest.mock import patch | |
|
11 | except ImportError: | |
|
12 | from mock import patch | |
|
13 | ||
|
13 | 14 | from IPython.kernel import KernelClient |
|
14 | 15 | from IPython.terminal.console.interactiveshell import ZMQTerminalInteractiveShell |
|
15 | 16 | from IPython.utils.tempdir import TemporaryDirectory |
@@ -54,7 +55,7 class ZMQTerminalInteractiveShellTestCase(unittest.TestCase): | |||
|
54 | 55 | open_called_with.append(arg) |
|
55 | 56 | return Struct(show=lambda: show_called_with.append(None)) |
|
56 | 57 | |
|
57 |
with |
|
|
58 | with patch.object(PIL.Image, 'open', fake_open): | |
|
58 | 59 | self.shell.handle_image_PIL(self.data, self.mime) |
|
59 | 60 | |
|
60 | 61 | self.assertEqual(len(open_called_with), 1) |
General Comments 0
You need to be logged in to leave comments.
Login now