File: test_examples.py

package info (click to toggle)
python-thinc 8.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,804 kB
  • sloc: python: 15,818; javascript: 1,554; ansic: 342; makefile: 20; sh: 13
file content (58 lines) | stat: -rw-r--r-- 1,749 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
from pathlib import Path

import pytest


@pytest.fixture
def test_files(nb_file):
    pytest.importorskip("nbconvert")
    pytest.importorskip("nbformat")
    import nbconvert
    import nbformat
    from nbconvert.preprocessors import ExecutePreprocessor

    if not Path(nb_file).exists():
        return
    kernel_name = os.environ.get("NOTEBOOK_KERNEL", "python3")
    with open(nb_file) as f:
        nb = nbformat.read(f, as_version=4)
    proc = ExecutePreprocessor(timeout=600, kernel_name=kernel_name)
    proc.allow_errors = True
    proc.preprocess(nb, {"metadata": {"path": "/"}})
    cells_with_outputs = [c for c in nb.cells if "outputs" in c]
    for cell in cells_with_outputs:
        for output in cell["outputs"]:
            if output.output_type == "error":
                for l in output.traceback:
                    print(l)
                raise Exception(f"{output.ename}: {output.evalue}")


@pytest.mark.parametrize(
    "nb_file",
    (
        "examples/01_intro_model_definition_methods.ipynb",
        "examples/05_benchmarking_layers.ipynb",
    ),
)
def test_ipython_notebooks(test_files: None):
    ...


@pytest.mark.skip(reason="these notebooks need special software or hardware")
@pytest.mark.parametrize(
    "nb_file",
    (
        "examples/00_intro_to_thinc.ipynb",
        "examples/02_transformers_tagger_bert.ipynb",
        "examples/03_pos_tagger_basic_cnn.ipynb",
        "examples/03_textcat_basic_neural_bow.ipynb",
        "examples/04_configure_gpu_memory.ipynb",
        "examples/04_parallel_training_ray.ipynb",
        "examples/05_visualizing_models.ipynb",
        "examples/06_predicting_like_terms.ipynb",
    ),
)
def test_ipython_notebooks_slow(test_files: None):
    ...