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
8393 views
1
"""Run all Python code snippets."""
2
3
import os
4
import runpy
5
import sys
6
import warnings
7
from collections.abc import Iterator
8
from pathlib import Path
9
10
with warnings.catch_warnings():
11
# matplotlib had some deprecated calls into pyparsing
12
warnings.simplefilter("ignore", DeprecationWarning)
13
import matplotlib as mpl
14
import pytest
15
16
# Do not show plots
17
mpl.use("Agg")
18
19
# Get paths to Python code snippets
20
repo_root = Path(__file__).parent.parent.parent.parent
21
python_snippets_dir = repo_root / "docs" / "source" / "src" / "python"
22
snippet_paths = list(python_snippets_dir.rglob("*.py"))
23
24
# Skip visualization snippets
25
snippet_paths = [p for p in snippet_paths if "visualization" not in str(p)]
26
27
# Skip UDF section on Python 3.13 as numba does not support it yet
28
if sys.version_info >= (3, 13):
29
snippet_paths = [p for p in snippet_paths if "user-defined-functions" not in str(p)]
30
31
32
@pytest.fixture(scope="module")
33
def _change_test_dir() -> Iterator[None]:
34
"""Change path to repo root to accommodate data paths in code snippets."""
35
current_path = Path().resolve()
36
os.chdir(repo_root)
37
yield
38
os.chdir(current_path)
39
40
41
@pytest.mark.docs
42
@pytest.mark.parametrize("path", snippet_paths)
43
@pytest.mark.usefixtures("_change_test_dir")
44
def test_run_python_snippets(path: Path) -> None:
45
runpy.run_path(str(path))
46
47