From dd253d0771245cd6c3febbeff32b81850c0103e3 Mon Sep 17 00:00:00 2001 From: b-long Date: Thu, 4 Jun 2026 08:48:52 -0400 Subject: [PATCH] fix: fix/increase testing, fix misconfiguration --- .pre-commit-config.yaml | 17 +++++---- tests/test_sdk.py | 79 +++++++++++++++++++++-------------------- uv.lock | 2 +- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f1e18f1..100195d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,12 +5,11 @@ default_install_hook_types: - post-rewrite exclude: | (?x)^( - otdf_python/.* - | otdf-python-proto/proto-files/.* - | otdf-python-proto/generated/.* - | otdf-python-proto/src/otdf_python_proto/.* - | otdf-python-proto/buf.yaml - | otdf-python-proto/buf.gen.yaml + otdf-python-proto/generated/.* + | packages/otdf-python-proto/src/otdf_python_proto/.* + | packages/otdf-python-proto/proto-files/.* + | packages/otdf-python-proto/buf.yaml + | packages/otdf-python-proto/buf.gen.yaml )$ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks# @@ -29,12 +28,12 @@ repos: [ "--ignore-words-list", "b-long, otdf_python", - "--skip=uv.lock,otdf-python-proto/uv.lock", + "--skip=uv.lock", ] - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.15.12 + rev: v0.15.15 hooks: # Run the linter. - id: ruff-check @@ -45,4 +44,4 @@ repos: hooks: - id: conventional-pre-commit stages: [commit-msg] - args: [--verbose, feat, fix, docs, style, test, chore, ci] + args: [--verbose, feat, fix, docs, style, refactor, perf, revert, build, test, chore, ci] diff --git a/tests/test_sdk.py b/tests/test_sdk.py index 1289209d..86f51c16 100644 --- a/tests/test_sdk.py +++ b/tests/test_sdk.py @@ -1,5 +1,6 @@ """Basic tests for the Python SDK class.""" +import pytest from otdf_python.sdk import SDK @@ -23,84 +24,84 @@ def test_sdk_init_and_close(): # Test context manager exit calls close with SDK(services): pass - # Optionally, check if close was called if you want + assert services.closed def test_split_key_exception(): """Test SDK SplitKeyException.""" - try: + with pytest.raises(SDK.SplitKeyException, match="split key error"): raise SDK.SplitKeyException("split key error") - except SDK.SplitKeyException: - pass def test_data_size_not_supported(): """Test SDK DataSizeNotSupported exception.""" - try: + with pytest.raises(SDK.DataSizeNotSupported, match="too large"): raise SDK.DataSizeNotSupported("too large") - except SDK.DataSizeNotSupported: - pass def test_kas_info_missing(): """Test SDK KasInfoMissing exception.""" - try: + with pytest.raises(SDK.KasInfoMissing, match="kas info missing"): raise SDK.KasInfoMissing("kas info missing") - except SDK.KasInfoMissing: - pass def test_kas_public_key_missing(): """Test SDK KasPublicKeyMissing exception.""" - try: + with pytest.raises(SDK.KasPublicKeyMissing, match="kas pubkey missing"): raise SDK.KasPublicKeyMissing("kas pubkey missing") - except SDK.KasPublicKeyMissing: - pass def test_tamper_exception(): - """Test SDK TamperException.""" - try: + """Test SDK TamperException prefixes message with [tamper detected].""" + with pytest.raises(SDK.TamperException, match=r"\[tamper detected\] tamper"): raise SDK.TamperException("tamper") - except SDK.TamperException: - pass def test_root_signature_validation_exception(): - """Test SDK RootSignatureValidationException.""" - try: + """Test SDK RootSignatureValidationException includes tamper prefix.""" + with pytest.raises( + SDK.RootSignatureValidationException, match=r"\[tamper detected\] root sig" + ): raise SDK.RootSignatureValidationException("root sig") - except SDK.RootSignatureValidationException: - pass def test_segment_signature_mismatch(): - """Test SDK SegmentSignatureMismatch exception.""" - try: + """Test SDK SegmentSignatureMismatch includes tamper prefix.""" + with pytest.raises( + SDK.SegmentSignatureMismatch, match=r"\[tamper detected\] seg sig" + ): raise SDK.SegmentSignatureMismatch("seg sig") - except SDK.SegmentSignatureMismatch: - pass def test_kas_bad_request_exception(): """Test SDK KasBadRequestException.""" - try: + with pytest.raises(SDK.KasBadRequestException, match="kas bad req"): raise SDK.KasBadRequestException("kas bad req") - except SDK.KasBadRequestException: - pass -def test_kas_allowlist_exception(): - """Test SDK KasAllowlistException.""" - try: - raise SDK.KasAllowlistException("kas allowlist") - except SDK.KasAllowlistException: - pass +def test_kas_allowlist_exception_custom_message(): + """Test SDK KasAllowlistException with explicit message.""" + with pytest.raises(SDK.KasAllowlistException, match="kas allowlist"): + raise SDK.KasAllowlistException( + "http://kas.example.com", message="kas allowlist" + ) + + +def test_kas_allowlist_exception_auto_message(): + """Test SDK KasAllowlistException auto-generates message from url and origins.""" + exc = SDK.KasAllowlistException( + "http://kas.example.com", allowed_origins={"http://allowed.com"} + ) + assert exc.url == "http://kas.example.com" + assert "http://kas.example.com" in str(exc) + assert "http://allowed.com" in str(exc) def test_assertion_exception(): - """Test SDK AssertionException.""" - try: - raise SDK.AssertionException("assertion", "id123") - except SDK.AssertionException: - pass + """Test SDK AssertionException stores assertion_id.""" + exc = SDK.AssertionException("assertion failed", "id123") + assert str(exc) == "assertion failed" + assert exc.assertion_id == "id123" + + with pytest.raises(SDK.AssertionException, match="assertion failed"): + raise SDK.AssertionException("assertion failed", "id123") diff --git a/uv.lock b/uv.lock index 632b47f0..6a430aa6 100644 --- a/uv.lock +++ b/uv.lock @@ -439,7 +439,7 @@ wheels = [ [[package]] name = "otdf-python" -version = "0.6.0" +version = "0.7.1" source = { editable = "packages/otdf-python" } dependencies = [ { name = "connect-python" },