Esempio n. 1
0
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')
Esempio n. 2
0
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')
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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")
Esempio n. 7
0
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)
Esempio n. 8
0
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,
    )
Esempio n. 9
0
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',
    )
Esempio n. 10
0
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,
    )
Esempio n. 11
0
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',
    )
Esempio n. 12
0
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)
Esempio n. 13
0
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)
Esempio n. 14
0
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)
Esempio n. 15
0
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',
    )
Esempio n. 16
0
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,
    )
Esempio n. 17
0
    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)
Esempio n. 18
0
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}''')
Esempio n. 19
0
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}''')
Esempio n. 20
0
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}''')
Esempio n. 21
0
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}''')
Esempio n. 22
0
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")
Esempio n. 23
0
 def wrapper(*args, **kwds):
     with tt.monkeypatch(debugger.Pdb, 'run', staticmethod(eval)):
         return func(*args, **kwds)
Esempio n. 24
0
 def wrapper(*args, **kwds):
     with tt.monkeypatch(debugger.Pdb, 'run', staticmethod(eval)):
         return func(*args, **kwds)