Spaces:
Sleeping
Sleeping
Download tests/test_envstate_properties.py from gagan-devv/CloudOptRL: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/spaces/gagan-devv/CloudOptRL/resolve/main/tests/test_envstate_properties.py
- Command line
-
hf download hf://spaces/gagan-devv/CloudOptRL/tests/test_envstate_properties.py
-
curl -L -o test_envstate_properties.py https://huggingface.co/spaces/gagan-devv/CloudOptRL/resolve/main/tests/test_envstate_properties.py
3 kB
| """ | |
| Property-based tests for EnvState validation. | |
| This module validates EnvState field constraints using property-based testing | |
| to ensure robust validation across a wide range of inputs. | |
| """ | |
| import pytest | |
| from hypothesis import given, strategies as st | |
| from pydantic import ValidationError | |
| from env.config import EnvState | |
| class TestEnvStateValidation: | |
| """Property 2: EnvState Field Validation""" | |
| def test_valid_values_create_envstate(self, cpu, memory, request_rate, resources): | |
| """Test that valid values create EnvState without errors.""" | |
| state = EnvState( | |
| cpu=cpu, | |
| memory=memory, | |
| request_rate=request_rate, | |
| resources=resources | |
| ) | |
| assert state.cpu == cpu | |
| assert state.memory == memory | |
| assert state.request_rate == request_rate | |
| assert state.resources == resources | |
| def test_invalid_cpu_raises_validation_error(self, cpu): | |
| """Test that cpu > 100 raises ValidationError.""" | |
| with pytest.raises(ValidationError) as exc_info: | |
| EnvState(cpu=cpu, memory=50.0, request_rate=100.0, resources=3) | |
| assert "cpu" in str(exc_info.value).lower() | |
| def test_invalid_memory_raises_validation_error(self, memory): | |
| """Test that memory > 100 raises ValidationError.""" | |
| with pytest.raises(ValidationError) as exc_info: | |
| EnvState(cpu=50.0, memory=memory, request_rate=100.0, resources=3) | |
| assert "memory" in str(exc_info.value).lower() | |
| def test_invalid_resources_raises_validation_error(self, resources): | |
| """Test that resources < 1 raises ValidationError.""" | |
| with pytest.raises(ValidationError) as exc_info: | |
| EnvState(cpu=50.0, memory=50.0, request_rate=100.0, resources=resources) | |
| assert "resources" in str(exc_info.value).lower() | |
| def test_negative_request_rate_raises_validation_error(self, request_rate): | |
| """Test that negative request_rate raises ValidationError.""" | |
| with pytest.raises(ValidationError) as exc_info: | |
| EnvState(cpu=50.0, memory=50.0, request_rate=request_rate, resources=3) | |
| assert "request_rate" in str(exc_info.value).lower() | |