From 6b4e9015744ab8c9f17a6b8e23387cd676b1d827 Mon Sep 17 00:00:00 2001 From: roberto berto Date: Sun, 2 Nov 2025 22:54:44 +0000 Subject: feat: v0.4.0 - Architecture refactor, bug fixes, and quality improvements - Fixed #25: config_file_save/load now include path: [] in payload - Added exception hierarchy (SDKError, HttpError, ApiError, ValidationError) - Added utility functions (json, ids, paths) - Added structured logging with request ID tracking - Added optional Pydantic validation models - Refactored to pyvyos.core.* structure with backward compatibility shims - Moved JSON specs to docs/development/vyos_api/ - Added comprehensive test suite (19 shim tests, 16 utils tests, 6 exception tests) - Updated pyproject.toml for uv sync editable installation - Added development documentation (architecture, roadmap, quality guidelines) Maintains 100% backward compatibility with 0.3.0 --- tests/test_exceptions.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/test_exceptions.py (limited to 'tests/test_exceptions.py') diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 0000000..22a4f34 --- /dev/null +++ b/tests/test_exceptions.py @@ -0,0 +1,51 @@ +"""Tests for pyvyos.exceptions module.""" + +import pytest + +from pyvyos.exceptions import SDKError, HttpError, ApiError, ValidationError + + +def test_sdk_error_base(): + """Test SDKError is base exception.""" + assert issubclass(HttpError, SDKError) + assert issubclass(ApiError, SDKError) + assert issubclass(ValidationError, SDKError) + + +def test_http_error(): + """Test HttpError creation and attributes.""" + error = HttpError(status=404, message="Not Found") + assert error.status == 404 + assert error.message == "Not Found" + assert "404" in str(error) + assert "Not Found" in str(error) + + +def test_api_error(): + """Test ApiError creation.""" + error = ApiError(message="API failure") + assert error.message == "API failure" + assert "API failure" in str(error) + + +def test_api_error_with_details(): + """Test ApiError with details.""" + details = {"code": "ERR001", "field": "path"} + error = ApiError(message="Validation failed", details=details) + assert error.message == "Validation failed" + assert error.details == details + + +def test_validation_error(): + """Test ValidationError creation.""" + error = ValidationError(message="Invalid path format") + assert error.message == "Invalid path format" + assert "Invalid path format" in str(error) + + +def test_exceptions_raiseable(): + """Test that exceptions can be raised and caught.""" + with pytest.raises(HttpError) as exc_info: + raise HttpError(status=500, message="Internal Error") + assert exc_info.value.status == 500 + -- cgit v1.2.3