Esempio n. 1
0
def test_py_transport(tutorial_path, tmp_path, tmp_env):
    fname = tutorial_path / 'transport' / 'py_transport.ipynb'
    nb, errors = run_notebook(fname, tmp_path, tmp_env)
    assert errors == []

    # FIXME use get_cell_by_name instead of assuming cell count/order is fixed
    assert np.isclose(get_cell_output(nb, -5)['lvl'], 153.6750030517578)
Esempio n. 2
0
def test_tutorial(nb_path, cell_values, run_args, tmp_path, tmp_env):
    """Test tutorial in the IPython or IR notebook at *fname*.

    If *cell_values* are given, values in the specified cells are tested.
    """
    # Add the tutorial directory to PYTHONPATH. The tutorials are executed in
    # `tmp_path`; but they import from a tools.py file in the same directory as
    # the notebook, ie. under `tutorial_path`.
    # TODO remove the reliance on this 'hidden' code
    path_sep = ";" if sys.platform.startswith("win") else ":"
    tmp_env["PYTHONPATH"] = path_sep.join(
        [str(nb_path.parent),
         tmp_env.get("PYTHONPATH", "")])

    # Copy necessary data files to tmp_path
    if "westeros_baseline_using_xlsx_import_part2" in nb_path.parts[-1]:
        for fil in data_files:
            copyfile(nb_path.parent / fil, tmp_path / fil)

    # The notebook can be run without errors
    nb, errors = run_notebook(nb_path, tmp_path, tmp_env, **run_args)
    assert errors == []

    for cell, value in cell_values:
        # Cell identified by name or index has a particular value
        assert np.isclose(get_cell_output(nb, cell), value)
Esempio n. 3
0
def test_py_transport_scenario(tutorial_path, tmp_path, tmp_env):
    fname = tutorial_path / 'transport' / 'py_transport_scenario.ipynb'
    nb, errors = run_notebook(fname, tmp_path, tmp_env)
    assert errors == []

    assert np.isclose(get_cell_output(nb, 'scen-z')['lvl'], 153.675)
    assert np.isclose(get_cell_output(nb, 'scen-detroit-z')['lvl'], 161.324)
Esempio n. 4
0
def test_py_transport_scenario(tutorial_path, tmp_path, tmp_env):
    fname = tutorial_path / "transport" / "py_transport_scenario.ipynb"
    nb, errors = run_notebook(fname, tmp_path, tmp_env)
    assert errors == []

    assert np.isclose(get_cell_output(nb, "scen-z")["lvl"], 153.675)
    assert np.isclose(get_cell_output(nb, "scen-detroit-z")["lvl"], 161.324)
Esempio n. 5
0
def test_computationerror_ipython(test_data_path, tmp_path, tmp_env):
    # NB this requires nbformat >= 5.0, because the output kind "evalue" was
    #    different pre-5.0
    fname = test_data_path / 'reporting-exceptions.ipynb'
    nb, _ = run_notebook(fname, tmp_path, tmp_env, allow_errors=True)

    observed = get_cell_output(nb, 0, kind='evalue')
    assert EXPECTED.match(observed), observed
Esempio n. 6
0
def test_tutorial(nb_path, cell_values, tmp_path, tmp_env):
    """Test tutorial in the IPython notebook at *fname*.

    If *cell_values* are given, values in the specified cells are tested.
    """
    # The notebook can be run without errors
    nb, errors = run_notebook(nb_path, tmp_path, tmp_env)
    assert errors == []

    for cell, value in cell_values:
        # Cell identified by name or index has a particular value
        assert np.isclose(get_cell_output(nb, cell), value)
Esempio n. 7
0
def test_tutorial(nb_path, cell_values, run_args, tmp_path, tmp_env):
    """Test tutorial in the IPython or IR notebook at *fname*.

    If *cell_values* are given, values in the specified cells are tested.
    """
    # Copy necessary data files to tmp_path
    if "westeros_baseline_using_xlsx_import_part2" in nb_path.parts[-1]:
        for fil in data_files:
            copyfile(nb_path.parent / fil, tmp_path / fil)

    # The notebook can be run without errors
    nb, errors = run_notebook(nb_path, tmp_path, tmp_env, **run_args)
    assert errors == []

    for cell, value in cell_values:
        # Cell identified by name or index has a particular value
        assert np.isclose(get_cell_output(nb, cell), value)
Esempio n. 8
0
def test_R_transport_scenario(tutorial_path, tmp_path, tmp_env):
    fname = tutorial_path / 'transport' / 'R_transport_scenario.ipynb'
    nb, errors = run_notebook(fname, tmp_path, tmp_env, kernel='IR')
    assert errors == []
Esempio n. 9
0
def test_computationerror_ipython(test_data_path, tmp_path, tmp_env):
    fname = test_data_path / 'reporting-exceptions.ipynb'
    nb, _ = run_notebook(fname, tmp_path, tmp_env, allow_errors=True)

    observed = get_cell_output(nb, 0, kind='evalue')
    assert EXPECTED.match(observed), observed
Esempio n. 10
0
def test_R_transport_scenario(tutorial_path, tmp_path, tmp_env):
    fname = tutorial_path / "transport" / "R_transport_scenario.ipynb"
    nb, errors = run_notebook(fname, tmp_path, tmp_env, kernel="IR")
    assert errors == []