def test_call_decorated_kwargs_on_trait_change(): """test calling @interact(foo=bar) decorated functions""" d = {} with tt.monkeypatch(interaction, 'display', record_display): @interact(a='kwarg') def foo(a='default'): d['a'] = a return a nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget( w, cls=widgets.TextWidget, value='kwarg', ) # test calling the function directly a = foo('hello') nt.assert_equal(a, 'hello') nt.assert_equal(d['a'], 'hello') # test that setting trait values calls the function w.value = 'called' nt.assert_equal(d['a'], 'called')
def test_call_decorated_kwargs_on_trait_change(): """test calling @interact(foo=bar) decorated functions""" d = {} with tt.monkeypatch(interaction, 'display', record_display): @interact(a='kwarg') def foo(a='default'): d['a'] = a return a nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget( w, cls=widgets.Text, value='kwarg', ) # test calling the function directly a = foo('hello') nt.assert_equal(a, 'hello') nt.assert_equal(d['a'], 'hello') # test that setting trait values calls the function w.value = 'called' nt.assert_equal(d['a'], 'called')
def check_latex_to_png_dvipng_fails_when_no_cmd(command): def mock_find_cmd(arg): if arg == command: raise FindCmdError with monkeypatch(latextools, "find_cmd", mock_find_cmd): nt.assert_equals(latextools.latex_to_png_dvipng("whatever", True), None)
def test_call_interact_kwargs(): def foo(a="default"): pass with tt.monkeypatch(interaction, "display", record_display): ifoo = interact(foo, a=10) nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.IntSlider, value=10)
def test_decorator_no_call(): with tt.monkeypatch(interaction, "display", record_display): @interact def foo(a="default"): pass nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.Text, value="default")
def test_decorator_kwarg(): with tt.monkeypatch(interaction, "display", record_display): @interact(a=5) def foo(a): pass nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.IntSlider, value=5)
def test_decorator_kwarg(): with tt.monkeypatch(interaction, 'display', record_display): @interact(a=5) def foo(a): pass nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.IntSlider, value=5, )
def test_decorator_no_call(): with tt.monkeypatch(interaction, 'display', record_display): @interact def foo(a='default'): pass nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.Text, value='default', )
def test_call_interact_kwargs(): def foo(a='default'): pass with tt.monkeypatch(interaction, 'display', record_display): ifoo = interact(foo, a=10) nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.IntSlider, value=10, )
def test_call_interact(): def foo(a='default'): pass with tt.monkeypatch(interaction, 'display', record_display): ifoo = interact(foo) nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.Text, value='default', )
def test_interact_instancemethod(): class Foo(object): def show(self, x): print(x) f = Foo() with tt.monkeypatch(interaction, "display", record_display): g = interact(f.show, x=(1, 10)) nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.IntSlider, value=5)
def test_latex_to_png_mpl_runs(): """ Test that latex_to_png_mpl just runs without error. """ def mock_kpsewhich(filename): nt.assert_equals(filename, "breqn.sty") return None for (s, wrap) in [("$x^2$", False), ("x^2", True)]: yield (latextools.latex_to_png_mpl, s, wrap) with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): yield (latextools.latex_to_png_mpl, s, wrap)
def test_latex_to_png_dvipng_runs(): """ Test that latex_to_png_dvipng just runs without error. """ def mock_kpsewhich(filename): nt.assert_equals(filename, "breqn.sty") return None for (s, wrap) in [("$$x^2$$", False), ("x^2", True)]: yield (latextools.latex_to_png_dvipng, s, wrap) with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): yield (latextools.latex_to_png_dvipng, s, wrap)
def test_call_interact(): def foo(a='default'): pass with tt.monkeypatch(interaction, 'display', record_display): ifoo = interact(foo) nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget( w, cls=widgets.TextWidget, value='default', )
def test_interact_instancemethod(): class Foo(object): def show(self, x): print(x) f = Foo() with tt.monkeypatch(interaction, 'display', record_display): g = interact(f.show, x=(1,10)) nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.IntSlider, value=5, )
def test_handle_image_PIL(self): import PIL.Image open_called_with = [] show_called_with = [] def fake_open(arg): open_called_with.append(arg) return Struct(show=lambda: show_called_with.append(None)) with monkeypatch(PIL.Image, 'open', fake_open): self.shell.handle_image_PIL(self.data, self.mime) self.assertEqual(len(open_called_with), 1) self.assertEqual(len(show_called_with), 1) self.assertEqual(open_called_with[0].getvalue(), self.raw)
def test_genelatex_wrap_without_breqn(): """ Test genelatex with wrap=True for the case breqn.sty is not installed. """ def mock_kpsewhich(filename): nt.assert_equals(filename, "breqn.sty") return None with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): nt.assert_equals( '\n'.join(latextools.genelatex("x^2", True)), r'''\documentclass{article} \usepackage{amsmath} \usepackage{amsthm} \usepackage{amssymb} \usepackage{bm} \pagestyle{empty} \begin{document} $$x^2$$ \end{document}''')
def test_genelatex_no_wrap(): """ Test genelatex with wrap=False. """ def mock_kpsewhich(filename): assert False, ("kpsewhich should not be called " "(called with {0})".format(filename)) with monkeypatch(latextools, "kpsewhich", mock_kpsewhich): nt.assert_equals( '\n'.join(latextools.genelatex("body text", False)), r'''\documentclass{article} \usepackage{amsmath} \usepackage{amsthm} \usepackage{amssymb} \usepackage{bm} \pagestyle{empty} \begin{document} body text \end{document}''')
def test_call_decorated_kwargs_on_trait_change(): """test calling @interact(foo=bar) decorated functions""" d = {} with tt.monkeypatch(interaction, "display", record_display): @interact(a="kwarg") def foo(a="default"): d["a"] = a return a nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, cls=widgets.Text, value="kwarg") # test calling the function directly a = foo("hello") nt.assert_equal(a, "hello") nt.assert_equal(d["a"], "hello") # test that setting trait values calls the function w.value = "called" nt.assert_equal(d["a"], "called")
def wrapper(*args, **kwds): with tt.monkeypatch(debugger.Pdb, 'run', staticmethod(eval)): return func(*args, **kwds)