示例#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')
示例#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')
示例#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)
示例#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)
示例#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)
示例#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")
示例#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)
示例#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,
    )
示例#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',
    )
示例#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,
    )
示例#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',
    )
示例#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)
示例#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)
示例#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)
示例#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',
    )
示例#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,
    )
示例#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)
示例#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}''')
示例#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}''')
示例#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}''')
示例#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}''')
示例#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")
示例#23
0
 def wrapper(*args, **kwds):
     with tt.monkeypatch(debugger.Pdb, 'run', staticmethod(eval)):
         return func(*args, **kwds)
示例#24
0
 def wrapper(*args, **kwds):
     with tt.monkeypatch(debugger.Pdb, 'run', staticmethod(eval)):
         return func(*args, **kwds)