feat: adds simple tests for internal exceptions
This commit is contained in:
0
tests/exceptions/__init__.py
Normal file
0
tests/exceptions/__init__.py
Normal file
21
tests/exceptions/test_internal_assertion_exception.py
Normal file
21
tests/exceptions/test_internal_assertion_exception.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from jambo.exceptions.internal_assertion_exception import InternalAssertionException
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestInternalAssertionException(TestCase):
|
||||||
|
def test_inheritance(self):
|
||||||
|
self.assertTrue(issubclass(InternalAssertionException, AssertionError))
|
||||||
|
|
||||||
|
def test_message(self):
|
||||||
|
message = "This is an internal assertion error."
|
||||||
|
|
||||||
|
expected_message = (
|
||||||
|
f"Internal Assertion Failed: {message}\n"
|
||||||
|
"This is likely a bug in Jambo. Please report it at"
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(InternalAssertionException) as ctx:
|
||||||
|
raise InternalAssertionException(message)
|
||||||
|
|
||||||
|
self.assertEqual(str(ctx.exception), expected_message)
|
||||||
44
tests/exceptions/test_invalid_schema_exception.py
Normal file
44
tests/exceptions/test_invalid_schema_exception.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
from jambo.exceptions.invalid_schema_exception import InvalidSchemaException
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestInternalAssertionException(TestCase):
|
||||||
|
def test_inheritance(self):
|
||||||
|
self.assertTrue(issubclass(InvalidSchemaException, ValueError))
|
||||||
|
|
||||||
|
def test_message(self):
|
||||||
|
message = "This is an internal assertion error."
|
||||||
|
|
||||||
|
expected_message = f"Invalid JSON Schema: {message}"
|
||||||
|
|
||||||
|
with self.assertRaises(InvalidSchemaException) as ctx:
|
||||||
|
raise InvalidSchemaException(message)
|
||||||
|
|
||||||
|
self.assertEqual(str(ctx.exception), expected_message)
|
||||||
|
|
||||||
|
def test_invalid_field(self):
|
||||||
|
message = "This is an internal assertion error."
|
||||||
|
invalid_field = "testField"
|
||||||
|
|
||||||
|
expected_message = (
|
||||||
|
f"Invalid JSON Schema: {message} (invalid field: {invalid_field})"
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(InvalidSchemaException) as ctx:
|
||||||
|
raise InvalidSchemaException(message, invalid_field=invalid_field)
|
||||||
|
|
||||||
|
self.assertEqual(str(ctx.exception), expected_message)
|
||||||
|
|
||||||
|
def test_cause(self):
|
||||||
|
message = "This is an internal assertion error."
|
||||||
|
cause = ValueError("Underlying cause")
|
||||||
|
|
||||||
|
expected_message = (
|
||||||
|
f"Invalid JSON Schema: {message} (caused by ValueError: Underlying cause)"
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(InvalidSchemaException) as ctx:
|
||||||
|
raise InvalidSchemaException(message, cause=cause)
|
||||||
|
|
||||||
|
self.assertEqual(str(ctx.exception), expected_message)
|
||||||
31
tests/exceptions/test_unsupported_schema_exception.py
Normal file
31
tests/exceptions/test_unsupported_schema_exception.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from jambo.exceptions.unsupported_schema_exception import UnsupportedSchemaException
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestUnsupportedSchemaException(TestCase):
|
||||||
|
def test_inheritance(self):
|
||||||
|
self.assertTrue(issubclass(UnsupportedSchemaException, ValueError))
|
||||||
|
|
||||||
|
def test_message(self):
|
||||||
|
message = "This is an internal assertion error."
|
||||||
|
|
||||||
|
expected_message = f"Unsupported JSON Schema: {message}"
|
||||||
|
|
||||||
|
with self.assertRaises(UnsupportedSchemaException) as ctx:
|
||||||
|
raise UnsupportedSchemaException(message)
|
||||||
|
|
||||||
|
self.assertEqual(str(ctx.exception), expected_message)
|
||||||
|
|
||||||
|
def test_unsupported_field(self):
|
||||||
|
message = "This is an internal assertion error."
|
||||||
|
invalid_field = "testField"
|
||||||
|
|
||||||
|
expected_message = (
|
||||||
|
f"Unsupported JSON Schema: {message} (unsupported field: {invalid_field})"
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(UnsupportedSchemaException) as ctx:
|
||||||
|
raise UnsupportedSchemaException(message, unsupported_field=invalid_field)
|
||||||
|
|
||||||
|
self.assertEqual(str(ctx.exception), expected_message)
|
||||||
@@ -19,6 +19,17 @@ class TestArrayTypeParser(TestCase):
|
|||||||
self.assertEqual(type_parsing.__origin__, list)
|
self.assertEqual(type_parsing.__origin__, list)
|
||||||
self.assertEqual(element_type, str)
|
self.assertEqual(element_type, str)
|
||||||
|
|
||||||
|
def test_array_parser_with_no_items(self):
|
||||||
|
parser = ArrayTypeParser()
|
||||||
|
|
||||||
|
properties = {
|
||||||
|
"default": ["a", "b", "c", "d"],
|
||||||
|
"maxItems": 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
with self.assertRaises(InvalidSchemaException):
|
||||||
|
parser.from_properties("placeholder", properties)
|
||||||
|
|
||||||
def test_array_parser_with_options_unique(self):
|
def test_array_parser_with_options_unique(self):
|
||||||
parser = ArrayTypeParser()
|
parser = ArrayTypeParser()
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,17 @@ class TestOneOfTypeParser(TestCase):
|
|||||||
ref_cache={},
|
ref_cache={},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(InvalidSchemaException):
|
||||||
|
OneOfTypeParser().from_properties_impl(
|
||||||
|
"test_field",
|
||||||
|
{
|
||||||
|
"oneOf": [], # should throw because oneOf must be a list with at least one item
|
||||||
|
},
|
||||||
|
required=True,
|
||||||
|
context={},
|
||||||
|
ref_cache={},
|
||||||
|
)
|
||||||
|
|
||||||
with self.assertRaises(InvalidSchemaException):
|
with self.assertRaises(InvalidSchemaException):
|
||||||
SchemaConverter.build(
|
SchemaConverter.build(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user