Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/utils/test_unstable.py
8414 views
1
from __future__ import annotations
2
3
from typing import TYPE_CHECKING
4
5
import pytest
6
7
from polars._utils.unstable import issue_unstable_warning, unstable
8
from polars.exceptions import UnstableWarning
9
10
if TYPE_CHECKING:
11
from tests.conftest import PlMonkeyPatch
12
13
14
def test_issue_unstable_warning(plmonkeypatch: PlMonkeyPatch) -> None:
15
plmonkeypatch.setenv("POLARS_WARN_UNSTABLE", "1")
16
17
msg = "`func` is considered unstable."
18
expected = (
19
msg
20
+ " It may be changed at any point without it being considered a breaking change."
21
)
22
with pytest.warns(UnstableWarning, match=expected):
23
issue_unstable_warning(msg)
24
25
26
def test_issue_unstable_warning_default(plmonkeypatch: PlMonkeyPatch) -> None:
27
plmonkeypatch.setenv("POLARS_WARN_UNSTABLE", "1")
28
29
msg = "this functionality is considered unstable."
30
with pytest.warns(UnstableWarning, match=msg):
31
issue_unstable_warning()
32
33
34
def test_issue_unstable_warning_setting_disabled(
35
recwarn: pytest.WarningsRecorder,
36
) -> None:
37
issue_unstable_warning()
38
assert len(recwarn) == 0
39
40
41
def test_unstable_decorator(plmonkeypatch: PlMonkeyPatch) -> None:
42
plmonkeypatch.setenv("POLARS_WARN_UNSTABLE", "1")
43
44
@unstable()
45
def hello() -> None: ...
46
47
msg = "`hello` is considered unstable."
48
with pytest.warns(UnstableWarning, match=msg):
49
hello()
50
51
52
def test_unstable_decorator_setting_disabled(recwarn: pytest.WarningsRecorder) -> None:
53
@unstable()
54
def hello() -> None: ...
55
56
hello()
57
assert len(recwarn) == 0
58
59