Ejemplo n.º 1
0
def test_script_complex(shared_datadir: Path, monkeypatch):
    """Deploy and run a complex script with no report and multiple params"""
    monkeypatch.chdir(shared_datadir)
    # upload
    dp_cfg = sc.DatapaneCfg.create_initial(
        config_file=Path("dp_test_mod.yaml"))

    with sc.build_bundle(dp_cfg) as sdist:
        s = dp.Script.upload_pkg(sdist, dp_cfg)

    with deletable(s):
        assert "datapane-demos" in s.source_url
        assert len(s.requirements) == 1
        assert "pytil" in s.requirements

        # attempt run with missing required param `p2`
        with pytest.raises(HTTPError) as _:
            _ = s.run(parameters=dict(p1="A"))

        run = s.run(parameters=dict(p1="A", p2=1))
        assert run.script == s.url
        assert "p2" in run.parameter_vals
        assert run.status == "RUNNING"

        # poll until complete
        while not run.is_complete():
            time.sleep(2)
            run.refresh()

        # TODO - look for `on_datapane` in stdout
        assert run.status == "SUCCESS"
        assert run.report is None
        assert run.result == "hello , world!"
        assert "SAMPLE OUTPUT" in run.output
Ejemplo n.º 2
0
def test_run_bundle(rc, datadir: Path, monkeypatch, capsys):
    monkeypatch.chdir(datadir)
    # monkeypatch.setenv("DATAPANE_ON_DATAPANE", "true")
    monkeypatch.setenv("DATAPANE_BY_DATAPANE", "true")

    # TODO - we should prob use a pre-built sdist here...
    dp_config = DatapaneCfg.create_initial(
        config_file=Path("dp_test_mod.yaml"))
    with build_bundle(dp_config) as sdist:
        # whl_file = build_bundle(dp_config, sdist, shared_datadir, username="******", version=1)
        try:
            # NOTE - need to pass in all params as we're not setting defaults via dp-server
            res = _runner({
                "p1": "VAL",
                "p2": "xyz",
                "p3": True
            },
                          dp_config.script,
                          sdist=sdist)
        finally:
            subprocess.run(
                [sys.executable, "-m", "pip", "uninstall", "--yes", "pytil"],
                check=True)
    # asserts
    (out, err) = capsys.readouterr()
    assert "ran script" in out
    assert "p2=xyz" in out
    assert "WORLD" in out
    assert dp.Result.get() == "hello , world!"
    assert res.report_id is None
Ejemplo n.º 3
0
def test_script_basic(shared_datadir: Path, monkeypatch):
    """Deploying and running a basic report-generating script"""
    monkeypatch.chdir(shared_datadir)
    # upload
    name = gen_name()
    dp_cfg = sc.DatapaneCfg.create_initial()
    with sc.build_bundle(dp_cfg) as sdist:
        s = dp.Script.upload_pkg(sdist, dp_cfg, name=name)

    with deletable(s):
        # are fields added?
        check_name(s, name)

        # download and check the import was as expected
        assert s.script == dp_cfg.script.name
        sdist_file = s.download_pkg()
        # look into files
        tar = tarfile.open(sdist_file)
        assert "dp_script.py" in tar.getnames()

        ########################################################################
        # Test running
        # no need to test obj lookup (covered by other tests)
        # basic report gen
        params = dict(p1="A")

        run = s.run(parameters=params)
        while not run.is_complete():
            time.sleep(2)
            run.refresh()
        assert run.status == "SUCCESS"

        with deletable(dp.Report.by_id(run.report)) as report:
            assert report.web_url

        ########################################################################
        # Test scheduling
        cron1 = "00 00 * * SUN"
        cron2 = "00 00 * * SAT"

        # create schedule, update, and delete - we don't run atm
        with deletable(dp.Schedule.create(s, cron1, params)) as s1:
            assert s1.cron == cron1
            s1.update(cron=cron2)
            assert s1.cron == cron2
Ejemplo n.º 4
0
def test_script_complex_report(shared_datadir: Path, monkeypatch):
    """
    Deploy and run a complex script that generates a complex report
    NOTE - this doesn't test the FE rendering
    """
    monkeypatch.chdir(shared_datadir)
    # upload
    dp_cfg = sc.DatapaneCfg.create_initial(config_file=Path("dp_complex_report.yaml"))

    with sc.build_bundle(dp_cfg) as sdist:
        s = dp.Script.upload_pkg(sdist, dp_cfg)

    with deletable(s):
        run = s.run()
        # poll until complete
        while not run.is_complete():
            time.sleep(2)
            run.refresh()

        assert run.status == "SUCCESS"
        report = dp.Report.by_id(run.report)
        assert report.num_blocks == 11