def test_type_info_wraps_in_array_if_array(self): prop = Property("foo", "desc", min_cardinality=0) prop.add_type(RefType("reef")) self.assertEqual(prop.type_info(), { 'type': 'array', 'items': {'$ref': 'reef'}, })
def test_base_type_info_returns_oneof_for_multiple_values(self): prop = Property("foo", "desc") prop.add_type(RefType("ref1")) prop.add_type(RefType("ref2")) self.assertEqual(prop.base_type_info(), { 'oneOf': [ {'$ref': 'ref1'}, {'$ref': 'ref2'}, ] })
def test_type_info_generates_flat_type_info_if_not_array(self): prop = Property("foo", "desc") prop.add_type(RefType("reef")) self.assertEqual(prop.type_info(), {'$ref': 'reef'})
def test_base_type_info_returns_type_for_single_value(self): prop = Property("foo", "desc") prop.add_type(RefType("reef")) self.assertEqual(prop.base_type_info(), {'$ref': 'reef'})
def test_add_enum_value_mutex_with_type_constraints(self): prop = Property("foo", "desc") prop.add_enum_value("steve") with self.assertRaises(ValueError): prop.add_type(PrimitiveType("string"))
def test_add_type_ignores_duplicates(self): prop = Property("foo", "desc") prop.add_type(PrimitiveType("string")) prop.add_type(PrimitiveType("string")) self.assertEqual(prop.allowed_types, [PrimitiveType("string")])
def test_add_type_allows_further_types_if_not_restrictive(self): prop = Property("foo", "desc") prop.add_type(PrimitiveType("string"), restrictive=False) # we just run this to see if it raises an exception, so there's no assertions in the test prop.add_type(RefType("argbl"))
def test_add_type_blocks_further_types_if_restrictive(self): prop = Property("foo", "desc") prop.add_type(PrimitiveType("string"), restrictive=True) with self.assertRaises(ValueError): prop.add_type(RefType("argbl"))
def test_add_type_adds_type(self): prop = Property("foo", "desc") self.assertEqual(len(prop.allowed_types), 0) prop.add_type(PrimitiveType("string")) self.assertEqual(prop.allowed_types, [PrimitiveType("string")])