Beispiel #1
0
 def test_matches_basic_types(self, capsys: Capture) -> None:
     p = bcpb.Property()
     for x in [1, 1.2, "a", np.arange(4), None, False, True, {}, []]:
             assert p.matches(x, x) is True
             assert p.matches(x, "junk") is False
     out, err = capsys.readouterr()
     assert err == ""
Beispiel #2
0
    def test_max_int(self, capsys: Capture) -> None:
        encoder = Serializer()
        rep = encoder.encode(2**64)
        assert rep == 2.0**64
        assert isinstance(rep, float)

        out, err = capsys.readouterr()
        assert out == ""
        assert err == ""  # "out of range integer may result in loss of precision"
Beispiel #3
0
def test_error(capsys: Capture) -> None:
    from bokeh.command.subcommands.info import Info
    old_invoke = Info.invoke
    def err(x, y): raise RuntimeError("foo")
    Info.invoke = err
    with pytest.raises(SystemExit):
        main(["bokeh", "info"])
    out, err = capsys.readouterr()
    assert err == 'ERROR: foo\n'
    Info.invoke = old_invoke
Beispiel #4
0
 def test_matches_compatible_arrays(self, capsys: Capture) -> None:
     p = bcpb.Property()
     a = np.arange(5)
     b = np.arange(5)
     assert p.matches(a, b) is True
     assert p.matches(a, b+1) is False
     for x in [1, 1.2, "a", np.arange(4), None, False]:
             assert p.matches(a, x) is False
             assert p.matches(x, b) is False
     out, err = capsys.readouterr()
     assert err == ""
Beispiel #5
0
def test_no_script(capsys: Capture) -> None:
    with TmpDir(prefix="bokeh-json-no-script") as dirname:
        with WorkingDir(dirname):
            with pytest.raises(SystemExit):
                main(["bokeh", "json"])
        out, err = capsys.readouterr()
        too_few = "the following arguments are required: DIRECTORY-OR-SCRIPT"
        assert err == f"""usage: bokeh json [-h] [--indent LEVEL] [-o FILENAME] [--args ...]
                  DIRECTORY-OR-SCRIPT [DIRECTORY-OR-SCRIPT ...]
bokeh json: error: {too_few}
"""
        assert out == ""
Beispiel #6
0
    def test_matches_non_dict_containers_with_array_false(self, capsys: Capture) -> None:
        p = bcpb.Property()
        d1 = [np.arange(10)]
        d2 = [np.arange(10)]
        assert p.matches(d1, d1) is True  # because object identity
        assert p.matches(d1, d2) is False

        t1 = (np.arange(10),)
        t2 = (np.arange(10),)
        assert p.matches(t1, t1) is True  # because object identity
        assert p.matches(t1, t2) is False

        out, err = capsys.readouterr()
        assert err == ""
Beispiel #7
0
def test_run(capsys: Capture) -> None:
    main(["bokeh", "info"])
    out, err = capsys.readouterr()
    lines = out.split("\n")
    assert len(lines) == 8
    assert lines[0].startswith("Python version")
    assert lines[1].startswith("IPython version")
    assert lines[2].startswith("Tornado version")
    assert lines[3].startswith("Bokeh version")
    assert lines[4].startswith("BokehJS static")
    assert lines[5].startswith("node.js version")
    assert lines[6].startswith("npm version")
    assert lines[7] == ""
    assert err == ""
Beispiel #8
0
    def test_matches_dicts_with_index_values(self, capsys: Capture, pd) -> None:
        p = bcpb.Property()
        d1 = pd.DataFrame(dict(foo=np.arange(10)))
        d2 = pd.DataFrame(dict(foo=np.arange(10)))

        assert p.matches(d1.index, d1.index) is True
        assert p.matches(d1.index, d2.index) is True

        # XXX not sure if this is preferable to have match, or not
        assert p.matches(d1.index, list(range(10))) is True

        assert p.matches(d1.index, np.arange(11)) is False
        assert p.matches(d1.index, np.arange(10)+1) is False
        assert p.matches(d1.index, 10) is False
        out, err = capsys.readouterr()
        assert err == ""
Beispiel #9
0
    def test_matches_dicts_with_array_values(self, capsys: Capture) -> None:
        p = bcpb.Property()
        d1 = dict(foo=np.arange(10))
        d2 = dict(foo=np.arange(10))

        assert p.matches(d1, d1) is True
        assert p.matches(d1, d2) is True

        # XXX not sure if this is preferable to have match, or not
        assert p.matches(d1, dict(foo=list(range(10)))) is True

        assert p.matches(d1, dict(foo=np.arange(11))) is False
        assert p.matches(d1, dict(bar=np.arange(10))) is False
        assert p.matches(d1, dict(bar=10)) is False
        out, err = capsys.readouterr()
        assert err == ""
Beispiel #10
0
def test_die(capsys: Capture) -> None:
    with pytest.raises(SystemExit):
        util.die("foo")
    out, err = capsys.readouterr()
    assert err == "foo\n"
    assert out == ""
Beispiel #11
0
 def test_matches_incompatible_arrays(self, capsys: Capture) -> None:
     p = bcpb.Property()
     a = np.arange(5)
     b = np.arange(5).astype(str)
     assert p.matches(a, b) is False
     out, err = capsys.readouterr()
Beispiel #12
0
def test_run_static(capsys: Capture) -> None:
    main(["bokeh", "info", "--static"])
    out, err = capsys.readouterr()
    assert err == ""
    assert out.endswith(join('bokeh', 'server', 'static') + '\n')
Beispiel #13
0
def test_license(capsys: Capture) -> None:
    b.license()
    out, err = capsys.readouterr()
    assert out == _LICENSE
Beispiel #14
0
def test_no_subcommand(capsys: Capture) -> None:
    with pytest.raises(SystemExit):
        main(["bokeh"])
    out, err = capsys.readouterr()
    assert err == "ERROR: Must specify subcommand, one of: build, info, init, json, sampledata, secret, serve or static\n"
    assert out == ""
Beispiel #15
0
def _assert_version_output(capsys: Capture):
    out, err = capsys.readouterr()
    err_expected = ""
    out_expected = ("%s\n" % __version__)
    assert err == err_expected
    assert out == out_expected