|
2 | 2 | # SPDX-License-Identifier: BSD-3-Clause
|
3 | 3 |
|
4 | 4 | import warnings
|
| 5 | +from collections.abc import Callable |
5 | 6 |
|
6 | 7 | import pytest
|
7 | 8 |
|
8 | 9 | import dataframely as dy
|
9 | 10 |
|
| 11 | +# --------------------- Nullability default change ------------------------------# |
10 | 12 |
|
11 |
| -def test_column_constructor_warns_about_nullable( |
| 13 | + |
| 14 | +def deprecated_default_nullable() -> None: |
| 15 | + """This function causes a FutureWarning because no value is specified for the |
| 16 | + `nullable` argument to the Column constructor.""" |
| 17 | + dy.Integer() |
| 18 | + |
| 19 | + |
| 20 | +def test_warning_deprecated_default_nullable( |
12 | 21 | monkeypatch: pytest.MonkeyPatch,
|
13 | 22 | ) -> None:
|
14 | 23 | monkeypatch.setenv("DATAFRAMELY_NO_FUTURE_WARNINGS", "")
|
15 | 24 | with pytest.warns(
|
16 | 25 | FutureWarning, match="The 'nullable' argument was not explicitly set"
|
17 | 26 | ):
|
18 |
| - dy.Integer() |
| 27 | + deprecated_default_nullable() |
| 28 | + |
| 29 | + |
| 30 | +# ------------------------- Nullable primary key ---------------------------------# |
| 31 | + |
| 32 | + |
| 33 | +def deprecated_nullable_primary_key() -> None: |
| 34 | + """This function causes a FutureWarning because both `nullable` and `primary_key` |
| 35 | + are set to `True` in the Column constructor.""" |
| 36 | + dy.Integer(primary_key=True, nullable=True) |
| 37 | + |
| 38 | + |
| 39 | +def test_warning_deprecated_nullable_primary_key( |
| 40 | + monkeypatch: pytest.MonkeyPatch, |
| 41 | +) -> None: |
| 42 | + monkeypatch.setenv("DATAFRAMELY_NO_FUTURE_WARNINGS", "") |
| 43 | + with pytest.warns(FutureWarning, match="Nullable primary keys are not supported"): |
| 44 | + deprecated_nullable_primary_key() |
19 | 45 |
|
20 | 46 |
|
| 47 | +# ------------------------- Common ---------------------------------# |
| 48 | + |
| 49 | + |
| 50 | +@pytest.mark.parametrize( |
| 51 | + "deprecated_behavior", |
| 52 | + [deprecated_default_nullable, deprecated_nullable_primary_key], |
| 53 | +) |
21 | 54 | @pytest.mark.parametrize("env_var", ["1", "True", "true"])
|
22 |
| -def test_future_warning_skip(monkeypatch: pytest.MonkeyPatch, env_var: str) -> None: |
| 55 | +def test_future_warning_skip( |
| 56 | + monkeypatch: pytest.MonkeyPatch, env_var: str, deprecated_behavior: Callable |
| 57 | +) -> None: |
| 58 | + """FutureWarnings should be avoidable by setting an environment variable.""" |
23 | 59 | monkeypatch.setenv("DATAFRAMELY_NO_FUTURE_WARNINGS", env_var)
|
24 |
| - |
25 | 60 | # Elevates FutureWarning to an exception
|
26 | 61 | with warnings.catch_warnings():
|
27 | 62 | warnings.simplefilter("error", FutureWarning)
|
28 |
| - dy.Integer() |
| 63 | + deprecated_behavior() |
0 commit comments