Tests added.

Some bug solved.
This commit is contained in:
2026-04-12 19:04:20 +02:00
parent 779d8cee44
commit b2220b5bbd
11 changed files with 607 additions and 4 deletions

62
tests/test_errors.py Normal file
View File

@@ -0,0 +1,62 @@
import pytest
from appengine import AEErrs, AppEngineException, is_number
class TestIsNumber:
def test_integer_string(self):
assert is_number("42") is True
def test_float_string(self):
assert is_number("3.14") is True
def test_negative_string(self):
assert is_number("-1.5") is True
def test_non_numeric_string(self):
assert is_number("hello") is False
def test_empty_string(self):
assert is_number("") is False
class TestAEErrs:
def test_parse_error_value(self):
assert AEErrs.PARSE_ERROR.value == -32700
def test_invalid_request_value(self):
assert AEErrs.INVALID_REQUEST.value == -32600
def test_meth_not_found_value(self):
assert AEErrs.METH_NOT_FOUND.value == -32601
def test_invalid_params_value(self):
assert AEErrs.INVALID_PARAMS.value == -32602
def test_internal_error_value(self):
assert AEErrs.INTERNAL_ERROR.value == -32000
def test_str_parse_error(self):
assert "Invalid JSON" in str(AEErrs.PARSE_ERROR)
def test_str_invalid_request(self):
assert "not a valid object" in str(AEErrs.INVALID_REQUEST)
class TestAppEngineException:
def test_default_message(self):
exc = AppEngineException(AEErrs.INTERNAL_ERROR)
assert exc.value == AEErrs.INTERNAL_ERROR.value
assert "Internal error" in exc.mesg
def test_custom_message(self):
exc = AppEngineException(AEErrs.INVALID_PARAMS, "bad param")
assert exc.value == AEErrs.INVALID_PARAMS.value
assert exc.mesg == "bad param"
def test_inherits_exception(self):
assert isinstance(AppEngineException(AEErrs.INTERNAL_ERROR), Exception)
def test_raise_and_catch(self):
with pytest.raises(AppEngineException) as exc_info:
raise AppEngineException(AEErrs.METH_NOT_FOUND, "not found")
assert exc_info.value.value == AEErrs.METH_NOT_FOUND.value