Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/docs/test_user_guide.py
6939 views
1
"""Run all Python code snippets."""
2
3
import os
4
import runpy
5
import sys
6
from collections.abc import Iterator
7
from pathlib import Path
8
9
import matplotlib as mpl
10
import pytest
11
12
# Do not show plots
13
mpl.use("Agg")
14
15
# Get paths to Python code snippets
16
repo_root = Path(__file__).parent.parent.parent.parent
17
python_snippets_dir = repo_root / "docs" / "source" / "src" / "python"
18
snippet_paths = list(python_snippets_dir.rglob("*.py"))
19
20
# Skip visualization snippets
21
snippet_paths = [p for p in snippet_paths if "visualization" not in str(p)]
22
23
# Skip UDF section on Python 3.13 as numba does not support it yet
24
if sys.version_info >= (3, 13):
25
snippet_paths = [p for p in snippet_paths if "user-defined-functions" not in str(p)]
26
27
28
@pytest.fixture(scope="module")
29
def _change_test_dir() -> Iterator[None]:
30
"""Change path to repo root to accommodate data paths in code snippets."""
31
current_path = Path().resolve()
32
os.chdir(repo_root)
33
yield
34
os.chdir(current_path)
35
36
37
@pytest.mark.docs
38
@pytest.mark.parametrize("path", snippet_paths)
39
@pytest.mark.usefixtures("_change_test_dir")
40
def test_run_python_snippets(path: Path) -> None:
41
runpy.run_path(str(path))
42
43