Skip to content

Commit 2e5bc40

Browse files
committed
test: add validator tests for Settings config fields
1 parent 168f31c commit 2e5bc40

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_config.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Tests for Settings field validators."""
2+
3+
import pytest
4+
from pydantic import ValidationError
5+
6+
from token0.config import Settings
7+
8+
9+
def test_storage_mode_valid_values():
10+
assert Settings(storage_mode="lite").storage_mode == "lite"
11+
assert Settings(storage_mode="full").storage_mode == "full"
12+
13+
14+
def test_storage_mode_invalid_raises():
15+
with pytest.raises(ValidationError):
16+
Settings(storage_mode="prod")
17+
18+
19+
def test_text_density_threshold_valid():
20+
assert Settings(text_density_threshold=0.0).text_density_threshold == 0.0
21+
assert Settings(text_density_threshold=1.0).text_density_threshold == 1.0
22+
assert Settings(text_density_threshold=0.52).text_density_threshold == 0.52
23+
24+
25+
def test_text_density_threshold_out_of_range_raises():
26+
with pytest.raises(ValidationError):
27+
Settings(text_density_threshold=1.1)
28+
with pytest.raises(ValidationError):
29+
Settings(text_density_threshold=-0.1)
30+
31+
32+
def test_port_valid():
33+
assert Settings(port=8000).port == 8000
34+
assert Settings(port=1).port == 1
35+
assert Settings(port=65535).port == 65535
36+
37+
38+
def test_port_out_of_range_raises():
39+
with pytest.raises(ValidationError):
40+
Settings(port=0)
41+
with pytest.raises(ValidationError):
42+
Settings(port=65536)

0 commit comments

Comments
 (0)