def test_doesnt_validate_doc_due_to_env_var(self, check_integrity, monkeypatch, test_plot) -> None: monkeypatch.setenv("BOKEH_VALIDATE_DOC", "false") with beu.OutputDocumentFor([test_plot]): pass assert not check_integrity.called
def test_single_model_with_no_document(self): p = SomeModel() assert p.document is None with beu.OutputDocumentFor([p], apply_theme=Theme(json={})): assert p.document is not None new_theme = p.document.theme assert p.document is not None assert p.document.theme is not new_theme
def test_error_on_mixed_list(self): p = SomeModel() d = Document() orig_theme = d.theme with pytest.raises(ValueError) as e: with beu.OutputDocumentFor([p, d]): pass assert str(e.value).endswith(_ODFERR) assert d.theme is orig_theme
def test_single_model_with_no_document(self): p = SomeModel() assert p.document is None with beu.OutputDocumentFor([p], apply_theme=beu.FromCurdoc): assert p.document is not None assert p.document.theme is curdoc().theme new_doc = p.document assert p.document is new_doc assert p.document.theme is not curdoc().theme
def test_single_model_with_document(self): # should use existing doc in with-block p = SomeModel() d = Document() orig_theme = d.theme d.add_root(p) with beu.OutputDocumentFor([p], apply_theme=beu.FromCurdoc): assert p.document is d assert d.theme is curdoc().theme assert p.document is d assert d.theme is orig_theme
def test_single_model_with_document(self) -> None: # should use existing doc in with-block p = SomeModel() d = Document() orig_theme = d.theme d.add_root(p) with beu.OutputDocumentFor([p]): assert p.document is d assert d.theme is orig_theme assert p.document is d assert d.theme is orig_theme
def test_single_model_with_document(self): # should use existing doc in with-block p = Model() d = Document() orig_theme = d.theme d.add_root(p) with beu.OutputDocumentFor([p], apply_theme=Theme(json={})): assert p.document is d assert d.theme is not orig_theme assert p.document is d assert d.theme is orig_theme
def test_with_doc_in_child_raises_error(self): doc = Document() p1 = SomeModel() p2 = OtherModel(child=SomeModel()) doc.add_root(p2.child) assert p1.document is None assert p2.document is None assert p2.child.document is doc with pytest.raises(RuntimeError) as e: with beu.OutputDocumentFor([p1, p2]): pass assert "already in a doc" in str(e.value)
def test_list_of_model_with_no_documents(self): # should create new (permanent) doc for inputs p1 = SomeModel() p2 = SomeModel() assert p1.document is None assert p2.document is None with beu.OutputDocumentFor([p1, p2]): assert p1.document is not None assert p2.document is not None assert p1.document is p2.document new_doc = p1.document new_theme = p1.document.theme assert p1.document is new_doc assert p1.document is p2.document assert p1.document.theme is new_theme
def test_list_of_model_same_as_roots(self): # should use existing doc in with-block p1 = SomeModel() p2 = SomeModel() d = Document() orig_theme = d.theme d.add_root(p1) d.add_root(p2) with beu.OutputDocumentFor([p1, p2], apply_theme=beu.FromCurdoc): assert p1.document is d assert p2.document is d assert d.theme is curdoc().theme assert p1.document is d assert p2.document is d assert d.theme is orig_theme
def test_list_of_model_same_as_roots(self): # should use existing doc in with-block p1 = Model() p2 = Model() d = Document() orig_theme = d.theme d.add_root(p1) d.add_root(p2) with beu.OutputDocumentFor([p1, p2], apply_theme=Theme(json={})): assert p1.document is d assert p2.document is d assert d.theme is not orig_theme assert p1.document is d assert p2.document is d assert d.theme is orig_theme
def test_list_of_model_same_as_roots_with_always_new(self): # should use new temp doc for everything inside with-block p1 = SomeModel() p2 = SomeModel() d = Document() orig_theme = d.theme d.add_root(p1) d.add_root(p2) with beu.OutputDocumentFor([p1, p2], always_new=True): assert p1.document is not d assert p2.document is not d assert p1.document is p2.document assert p2.document.theme is orig_theme assert p1.document is d assert p2.document is d assert d.theme is orig_theme
def test_list_of_model_subset_roots(self): # should use new temp doc for subset inside with-block p1 = SomeModel() p2 = SomeModel() d = Document() orig_theme = d.theme d.add_root(p1) d.add_root(p2) with beu.OutputDocumentFor([p1], apply_theme=beu.FromCurdoc): assert p1.document is not d assert p2.document is d assert p1.document.theme is curdoc().theme assert p2.document.theme is orig_theme assert p1.document is d assert p2.document is d assert d.theme is orig_theme
def test_list_of_model_with_no_documents(self): # should create new (permanent) doc for inputs p1 = SomeModel() p2 = SomeModel() assert p1.document is None assert p2.document is None with beu.OutputDocumentFor([p1, p2], apply_theme=beu.FromCurdoc): assert p1.document is not None assert p2.document is not None assert p1.document is p2.document new_doc = p1.document assert p1.document.theme is curdoc().theme assert p1.document is new_doc assert p2.document is new_doc assert p1.document is p2.document # should restore to default theme after with-block assert p1.document.theme is not curdoc().theme
def test_list_of_model_with_no_documents(self): # should create new (permanent) doc for inputs p1 = Model() p2 = Model() assert p1.document is None assert p2.document is None with beu.OutputDocumentFor([p1, p2], apply_theme=Theme(json={})): assert p1.document is not None assert p2.document is not None assert p1.document is p2.document new_doc = p1.document new_theme = p1.document.theme assert p1.document is new_doc assert p2.document is new_doc assert p1.document is p2.document # should restore to default theme after with-block assert p1.document.theme is not new_theme
def test_list_of_models_different_docs(self): # should use new temp doc for eveything inside with-block d = Document() orig_theme = d.theme p1 = SomeModel() p2 = SomeModel() d.add_root(p2) assert p1.document is None assert p2.document is not None with beu.OutputDocumentFor([p1, p2], apply_theme=beu.FromCurdoc): assert p1.document is not None assert p2.document is not None assert p1.document is not d assert p2.document is not d assert p1.document == p2.document assert p1.document.theme is curdoc().theme assert p1.document is None assert p2.document is not None assert p2.document.theme is orig_theme
def test_single_model_with_no_document(self): p = SomeModel() assert p.document is None with beu.OutputDocumentFor([p]): assert p.document is not None assert p.document is not None
def test_error_on_wrong_types(self, v): with pytest.raises(ValueError) as e: with beu.OutputDocumentFor(v): pass assert str(e.value).endswith(_ODFERR)
def test_error_on_empty_list(self): with pytest.raises(ValueError) as e: with beu.OutputDocumentFor([]): pass assert str(e.value).endswith(_ODFERR)
def test_validates_document_by_default(self, check_integrity, test_plot): with beu.OutputDocumentFor([test_plot]): pass assert check_integrity.called