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"
def test_view_names(): shell = MockIPythonShell({}) manager = ViewManager(AutoplotDisplay(), shell, { "a": TestView(), "b": TestView() }, "a") assert sorted(manager.view_names) == ["a", "b"]
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
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
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
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
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 == ()
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 == ()
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 == ""
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
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"
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 == {}
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
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
def test_invalid_view_name_constructor(): shell = MockIPythonShell({}) a = TestView() b = TestView() with pytest.raises(ValueError): ViewManager(AutoplotDisplay(), shell, {"a": a, "b": b}, "c")