def test_fmt_mimetype_error() -> None: with pytest.raises(ValueError) as err: fmt_to_mimetype("bad-fmt") assert "Unrecognized fmt='bad-fmt'" in str(err.value) with pytest.raises(ValueError) as err: mimetype_to_fmt("bad-mimetype") assert "Unrecognized mimetype='bad-mimetype'" in str(err.value)
def test_render_spec(spec: JSONDict) -> None: bundle = render(spec, fmts=FORMATS) assert len(bundle) == len(FORMATS) for mimetype, content in bundle.items(): fmt = mimetype_to_fmt(mimetype) if isinstance(content, dict): check_output(json.dumps(content), fmt) else: check_output(content, fmt)
def test_render_chart(chart: alt.TopLevelMixin) -> None: bundle = render(chart, fmts=FORMATS) assert len(bundle) == len(FORMATS) for mimetype, content in bundle.items(): fmt = mimetype_to_fmt(mimetype) if isinstance(content, dict): check_output(json.dumps(content), fmt) else: check_output(content, fmt)
def test_render_w_vega_cli_options( monkeypatch: MonkeyPatch, capsys: SysCapture, chart: alt.TopLevelMixin, vega_cli_options: Optional[List[str]], ) -> None: """Tests that `vega_cli_options` works with both NodeSaver and other Savers""" monkeypatch.setattr(NodeSaver, "enabled", lambda: True) monkeypatch.setattr(SeleniumSaver, "enabled", lambda: False) bundle = render(chart, fmts=["html", "svg"], vega_cli_options=vega_cli_options) assert len(bundle) == 2 for mimetype, content in bundle.items(): assert content is not None fmt = mimetype_to_fmt(mimetype) if isinstance(content, dict): check_output(json.dumps(content), fmt) else: check_output(content, fmt) stderr = capsys.readouterr().err if vega_cli_options: assert "DEBUG" in stderr
def test_fmt_mimetype(fmt: str) -> None: mimetype = fmt_to_mimetype(fmt) fmt_out = mimetype_to_fmt(mimetype) assert fmt == fmt_out