Better Defaults Validation Implementation
This commit is contained in:
@@ -66,38 +66,25 @@ class TestArrayTypeParser(TestCase):
|
||||
|
||||
properties = {"items": {"type": "string"}, "default": ["a", 1, "c"]}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"All items in the default list must be of type str",
|
||||
)
|
||||
|
||||
def test_array_parser_with_invalid_default_type(self):
|
||||
parser = ArrayTypeParser()
|
||||
|
||||
properties = {"items": {"type": "string"}, "default": "not_a_list"}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception), "Default value must be a list, got str"
|
||||
)
|
||||
|
||||
def test_array_parser_with_invalid_default_min(self):
|
||||
parser = ArrayTypeParser()
|
||||
|
||||
properties = {"items": {"type": "string"}, "default": ["a"], "minItems": 2}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception), "Default list is below minItems limit of 2"
|
||||
)
|
||||
|
||||
def test_array_parser_with_invalid_default_max(self):
|
||||
parser = ArrayTypeParser()
|
||||
|
||||
@@ -107,9 +94,5 @@ class TestArrayTypeParser(TestCase):
|
||||
"maxItems": 3,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception), "Default list exceeds maxItems limit of 3"
|
||||
)
|
||||
|
||||
@@ -61,14 +61,9 @@ class TestFloatTypeParser(TestCase):
|
||||
"multipleOf": 0.5,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value must be a number, got str",
|
||||
)
|
||||
|
||||
def test_float_parser_with_default_invalid_maximum(self):
|
||||
parser = FloatTypeParser()
|
||||
|
||||
@@ -80,14 +75,9 @@ class TestFloatTypeParser(TestCase):
|
||||
"multipleOf": 0.5,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value exceeds maximum limit of 10.5",
|
||||
)
|
||||
|
||||
def test_float_parser_with_default_invalid_minimum(self):
|
||||
parser = FloatTypeParser()
|
||||
|
||||
@@ -99,14 +89,9 @@ class TestFloatTypeParser(TestCase):
|
||||
"multipleOf": 0.5,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value is below minimum limit of 1.0",
|
||||
)
|
||||
|
||||
def test_float_parser_with_default_invalid_exclusive_maximum(self):
|
||||
parser = FloatTypeParser()
|
||||
|
||||
@@ -118,14 +103,9 @@ class TestFloatTypeParser(TestCase):
|
||||
"multipleOf": 0.5,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value exceeds exclusive maximum limit of 10.5",
|
||||
)
|
||||
|
||||
def test_float_parser_with_default_invalid_exclusive_minimum(self):
|
||||
parser = FloatTypeParser()
|
||||
|
||||
@@ -137,14 +117,9 @@ class TestFloatTypeParser(TestCase):
|
||||
"multipleOf": 0.5,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value is below exclusive minimum limit of 1.0",
|
||||
)
|
||||
|
||||
def test_float_parser_with_default_invalid_multiple(self):
|
||||
parser = FloatTypeParser()
|
||||
|
||||
@@ -156,10 +131,5 @@ class TestFloatTypeParser(TestCase):
|
||||
"multipleOf": 2.0,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value 5.0 is not a multiple of 2.0",
|
||||
)
|
||||
|
||||
@@ -61,14 +61,9 @@ class TestIntTypeParser(TestCase):
|
||||
"multipleOf": 2,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value must be a number, got str",
|
||||
)
|
||||
|
||||
def test_int_parser_with_default_invalid_maximum(self):
|
||||
parser = IntTypeParser()
|
||||
|
||||
@@ -80,14 +75,9 @@ class TestIntTypeParser(TestCase):
|
||||
"multipleOf": 2,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value exceeds maximum limit of 10",
|
||||
)
|
||||
|
||||
def test_int_parser_with_default_invalid_minimum(self):
|
||||
parser = IntTypeParser()
|
||||
|
||||
@@ -99,14 +89,9 @@ class TestIntTypeParser(TestCase):
|
||||
"multipleOf": 2,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value is below minimum limit of 1",
|
||||
)
|
||||
|
||||
def test_int_parser_with_default_invalid_exclusive_maximum(self):
|
||||
parser = IntTypeParser()
|
||||
|
||||
@@ -118,14 +103,9 @@ class TestIntTypeParser(TestCase):
|
||||
"multipleOf": 2,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value exceeds exclusive maximum limit of 10",
|
||||
)
|
||||
|
||||
def test_int_parser_with_default_invalid_exclusive_minimum(self):
|
||||
parser = IntTypeParser()
|
||||
|
||||
@@ -137,14 +117,9 @@ class TestIntTypeParser(TestCase):
|
||||
"multipleOf": 2,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value is below exclusive minimum limit of 1",
|
||||
)
|
||||
|
||||
def test_int_parser_with_default_invalid_multipleOf(self):
|
||||
parser = IntTypeParser()
|
||||
|
||||
@@ -156,10 +131,5 @@ class TestIntTypeParser(TestCase):
|
||||
"multipleOf": 2,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(
|
||||
str(context.exception),
|
||||
"Default value 5 is not a multiple of 2",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user