Beispiel #1
0
def test_regression_regex_replace_pass():
    """Test a regression that will succeed by regex replacing certain paths."""
    fixture = NBRegressionFixture()
    fixture.diff_ignore = (
        "/metadata/language_info/version",
        "/cells/*/execution_count",
        "/cells/*/outputs/*/execution_count",
        "/cells/12/outputs/0/data/text/latex",
        "/cells/9/outputs/0/metadata/application/json",
    )
    fixture.diff_replace = (
        ("/cells/*/outputs/*/traceback", r"\<module\>.*\n", "<module>\n"),
        ("/cells/*/outputs/*/traceback", r"[\-]+", "-"),
        (
            "/cells/*/outputs/*/traceback",
            r"\s*Traceback \(most recent call last\)",
            " Traceback (most recent call last)",
        ),
        (
            "/cells/*/outputs/*/traceback",
            r"\<ipython\-input\-[\-0-9a-zA-Z]*\>",
            "<ipython-input-XXX>",
        ),
    )
    fixture.check(os.path.join(PATH, "raw_files", "different_outputs.ipynb"))
Beispiel #2
0
def test_notebook1(nb_regression: nb.NBRegressionFixture, notebook):

    ## Generate from the un-run notebook
    nb_regression.force_regen = True
    nb_regression.check(notebook, False)

    ## Run notebook against generated
    ## ignore output for now
    nb_regression.diff_ignore = ("/cells/*/outputs/*/text", )
    nb_regression.force_regen = False
    nb_regression.check(notebook)
Beispiel #3
0
def test_jupyter_notebook():
    """Test that the `RmqThreadCommunicator` can be used in a Jupyter notebook."""
    from pytest_notebook.nb_regression import NBRegressionFixture

    fixture = NBRegressionFixture(exec_timeout=50)
    fixture.diff_color_words = False
    fixture.diff_ignore = ('/metadata/language_info/version', )

    my_dir = pathlib.Path(__file__).parent
    with open(my_dir / pathlib.Path('notebooks/communicator.ipynb')) as handle:
        fixture.check(handle)
Beispiel #4
0
def test_regression_diff_ignore_pass():
    """Test a regression that will succeed by ignoring certain notebook paths."""
    fixture = NBRegressionFixture()
    fixture.diff_ignore = (
        "/metadata/language_info/version",
        "/cells/*/execution_count",
        "/cells/*/outputs/*/traceback",
        "/cells/*/outputs/*/execution_count",
        "/cells/12/outputs/0/data/text/latex",
        "/cells/9/outputs/0/metadata/application/json",
    )
    fixture.check(os.path.join(PATH, "raw_files", "different_outputs.ipynb"))
def test_regression_coverage():
    """Test a regression that will fail."""
    fixture = NBRegressionFixture()
    fixture.diff_ignore = ("/metadata/language_info/version", )
    fixture.coverage = True
    result = fixture.check(
        os.path.join(PATH, "raw_files", "coverage_test", "call_package.ipynb"))

    assert COVERAGE_KEY in result.process_resources
    assert "!coverage.py:" in result.process_resources[COVERAGE_KEY]
    assert "package.py" in result.process_resources[COVERAGE_KEY]
    assert "[1,2,3]" in result.process_resources[COVERAGE_KEY]
Beispiel #6
0
def test_notebook1(nb_regression: nb.NBRegressionFixture, notebook):

    ## Generate from the un-run notebook
    nb_regression.force_regen = True
    try:
        nb_regression.check(notebook, False)
    except TimeoutError as te:
        assert (
            False
        ), f"pynotebook `{NOTEBOOK_NAME}` timed out after {nb_regression.exec_timeout}s during test: {te}.\nFor more details see: https://jupyterbook.org/content/execute.html#setting-execution-timeout"
    ## Run notebook against generated
    ## ignore output for now
    nb_regression.diff_ignore = ("/cells/*/outputs/*/text",)
    nb_regression.force_regen = False
    nb_regression.check(notebook)
Beispiel #7
0
import importlib_resources
from pytest_notebook.nb_regression import NBRegressionFixture

import notebooks

fixture = NBRegressionFixture(exec_timeout=300)
fixture.diff_color_words = False
fixture.diff_replace = (("/cells/*/outputs", "\\r", ""),)
# ignoring some output cells,
# because pd.DataFrame.value_counts' return value is inconsistent
fixture.diff_ignore = (
    "/cells/*/execution_count",
    "/metadata/language_info/version",
    "/cells/68/outputs/0/text",
    "/cells/69/outputs/0/text",
    "/cells/78/outputs/0/text",
    "/cells/134/outputs/0/text",
    "/cells/135/outputs/0/text",
    "/cells/136/outputs/0/text",
)


def cli_notebook_output():
    with importlib_resources.path(notebooks, "CLI.ipynb") as path:
        fixture.check(str(path))