-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_utils.py
More file actions
104 lines (62 loc) · 2.9 KB
/
test_utils.py
File metadata and controls
104 lines (62 loc) · 2.9 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pytest
from dvpio._utils import deprecated_docs, deprecated_log, experimental_docs, experimental_log, is_parsed
@pytest.fixture()
def function_factory():
def sample_func():
"""Original docstring."""
pass
return sample_func
def test_is_parsed(function_factory):
sample_func = is_parsed(function_factory)
assert sample_func._is_parsed
def test_experimental_docs(function_factory):
sample_func = experimental_docs(function_factory)
assert "Warning: This function is experimental" in sample_func.__doc__
def test_experimental_log(function_factory):
sample_func = experimental_log(function_factory)
with pytest.warns(UserWarning, match="is experimental and may change"):
sample_func()
def test_deprecated_docs(function_factory):
sample_func = deprecated_docs(function_factory)
assert "Warning: This function is deprecated" in sample_func.__doc__
def test_deprecated_log_default_message(function_factory):
"""Test deprecated_log with default message using @ syntax."""
sample_func = deprecated_log()(function_factory)
with pytest.warns(
DeprecationWarning, match="Function sample_func is deprecated and will be removed in future versions"
):
sample_func()
def test_deprecated_log_custom_message(function_factory):
"""Test deprecated_log with custom message."""
custom_message = "This function is obsolete. Use new_function() instead."
sample_func = deprecated_log(custom_message)(function_factory)
with pytest.warns(DeprecationWarning, match="This function is obsolete. Use new_function\\(\\) instead."):
sample_func()
def test_deprecated_log_preserves_function_metadata(function_factory):
"""Test that deprecated_log preserves function name and docstring."""
sample_func = deprecated_log(function_factory)
assert sample_func.__name__ == function_factory.__name__
assert sample_func.__doc__ == function_factory.__doc__
def test_deprecated_log_preserves_return_value(function_factory):
"""Test that deprecated_log preserves function return value."""
def func_with_return():
return "test_value"
decorated_func = deprecated_log(func_with_return)
with pytest.warns(DeprecationWarning):
result = decorated_func()
assert result == "test_value"
def test_deprecated_log_preserves_arguments():
"""Test that deprecated_log passes through arguments correctly."""
def func_with_args(a, b, c=None):
return (a, b, c)
decorated_func = deprecated_log(func_with_args)
with pytest.warns(DeprecationWarning):
result = decorated_func(1, 2, c=3)
assert result == (1, 2, 3)
def test_deprecated_log_warning_category():
"""Test that deprecated_log uses correct warning category."""
def sample_func():
pass
decorated_func = deprecated_log(sample_func)
with pytest.warns(DeprecationWarning):
decorated_func()