Skip to content

Commit 9fa3dab

Browse files
committed
test: add unit tests for _Warnings warning helpers
1 parent 17a9887 commit 9fa3dab

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

test/test_warnings.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import warnings
2+
3+
import pytest
4+
5+
from weaviate.warnings import _Warnings
6+
7+
8+
def _capture(func, *args):
9+
with warnings.catch_warnings(record=True) as caught:
10+
warnings.simplefilter("always")
11+
func(*args)
12+
assert len(caught) == 1
13+
return caught[0]
14+
15+
16+
def test_auth_with_anon_weaviate_emits_user_warning():
17+
record = _capture(_Warnings.auth_with_anon_weaviate)
18+
assert issubclass(record.category, UserWarning)
19+
assert "Auth001" in str(record.message)
20+
21+
22+
def test_auth_negative_expiration_time_includes_value():
23+
record = _capture(_Warnings.auth_negative_expiration_time, 30)
24+
assert issubclass(record.category, UserWarning)
25+
assert "Auth003" in str(record.message)
26+
assert "30" in str(record.message)
27+
28+
29+
def test_auth_no_refresh_token_without_length():
30+
record = _capture(_Warnings.auth_no_refresh_token)
31+
assert "Auth002" in str(record.message)
32+
assert "no expiration time" in str(record.message)
33+
34+
35+
def test_auth_no_refresh_token_with_length():
36+
record = _capture(_Warnings.auth_no_refresh_token, 60)
37+
assert "Auth002" in str(record.message)
38+
assert "only valid for 60s" in str(record.message)
39+
40+
41+
@pytest.mark.parametrize(
42+
"func, args, code",
43+
[
44+
(_Warnings.sharding_actual_count_is_deprecated, ("actualCount",), "Dep018"),
45+
(_Warnings.deprecated_tenant_type, ("HOT", "ACTIVE"), "Dep021"),
46+
],
47+
)
48+
def test_deprecation_warnings(func, args, code):
49+
record = _capture(func, *args)
50+
assert issubclass(record.category, DeprecationWarning)
51+
assert code in str(record.message)

0 commit comments

Comments
 (0)