コード例 #1
0
def test_invalid_view_name():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    with pytest.raises(ValueError):
        manager.active = "c"
コード例 #2
0
def test_view_names():
    shell = MockIPythonShell({})
    manager = ViewManager(AutoplotDisplay(), shell, {
        "a": TestView(),
        "b": TestView()
    }, "a")

    assert sorted(manager.view_names) == ["a", "b"]
コード例 #3
0
def test_set_plot_width():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.set_plot_width(Toast(Output()), 3)

    assert manager._changed
    assert a.plot_width == 3
    assert b.plot_width is None
コード例 #4
0
def test_set_ylabel():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.set_ylabel(Toast(Output()), "hello")

    assert manager._changed
    assert a.ylabel == "hello"
    assert b.ylabel is None
コード例 #5
0
def test_max_series_length():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.update_max_series_length(Toast(Output()), 20)

    assert manager._changed
    assert a.max_series_length == 20
    assert b.max_series_length is None
コード例 #6
0
def test_defrost():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.defrost(Toast(Output()))

    assert manager._changed
    assert a.defrosted
    assert not b.defrosted
コード例 #7
0
def test_rename_variable():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.rename_variable(Toast(Output()), "df", "ddf")

    assert manager._changed
    assert a.rename == ("df", "ddf")
    assert b.rename == ()
コード例 #8
0
def test_change_colour():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.change_colour(Toast(Output()), "df", "red")

    assert manager._changed
    assert a.colour == ("df", "red")
    assert b.colour == ()
コード例 #9
0
def test_show_variable():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    manager.show_variable(Toast(Output()), "df")

    assert manager._changed
    assert a.showed == "df"
    assert b.showed == ""
コード例 #10
0
def test_set_active():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    assert manager.active == "a"
    assert manager.active_view is a

    manager.active = "b"

    assert manager.active == "b"
    assert manager.active_view is b
コード例 #11
0
def test_active():
    shell = MockIPythonShell({})
    manager = ViewManager(AutoplotDisplay(), shell, {
        "a": TestView(),
        "b": TestView()
    }, "a")
    assert manager.active == "a"

    manager = ViewManager(AutoplotDisplay(), shell, {
        "a": TestView(),
        "b": TestView()
    }, "b")
    assert manager.active == "b"
コード例 #12
0
def test_redraw_filter_pandas():
    df = pd.DataFrame({"a": [1, 2, 3]})
    shell = MockIPythonShell({"n": 1, "df": df})
    a = TestView()
    b = TestView()
    manager = ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "a")

    assert manager._changed

    manager.redraw()

    assert not manager._changed

    assert a.variables == {"df": df}
    assert b.variables == {}
コード例 #13
0
    def with_params(user_ns: Dict[str, Any] = None, toast: Toast = None):
        if user_ns is None:
            user_ns = {}

        if toast is None:
            toast = mock_toast

        shell = MockIPythonShell(user_ns)
        plotter = MockPlotter(toast)
        handler = PlotterModel(plotter)
        view_manager = ViewManager(AutoplotDisplay(), shell,
                                   {"graph": handler}, "graph")
        magic = _make_magic(shell, toast, view_manager)
        view_manager.redraw()

        return magic
コード例 #14
0
    def with_params(
        user_ns: Dict[str, Any],
        reserved: Optional[Set[str]] = None,
        toast: Toast = None
    ) -> Tuple[MockIPythonShell, MockPlotter, PlotterModel]:
        if toast is None:
            toast = mock_toast

        # initialise mocks with parameters
        shell = MockIPythonShell(user_ns)
        plotter = MockPlotter(toast)

        # initialise cell event handler instance
        handler = PlotterModel(plotter)

        view_manager = ViewManager(AutoplotDisplay(), shell,
                                   {"graph": handler}, "graph")
        # optionally add reserved names
        if reserved is not None:
            view_manager._reserved = reserved

        view_manager.redraw()

        return shell, plotter, handler
コード例 #15
0
def test_invalid_view_name_constructor():
    shell = MockIPythonShell({})
    a = TestView()
    b = TestView()
    with pytest.raises(ValueError):
        ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "c")