def test_dict(self): template = { 'person': [{ 'id': int, obiwan.noneable('name'): str, obiwan.optional('age'): int }] } tests = [{ 'person': [{ 'id': 1, 'name': None }] }, { 'person': [{ 'id': 1, 'name': None, 'age': 14 }] }, { 'person': [{ 'id': 1, 'name': "Adam" }] }] for test in tests: obiwan.duckable(test, template)
def test_strict(self): template = { obiwan.options: [obiwan.strict], 'id': int, obiwan.optional('opt'): int, } obiwan.duckable({'id': 1}, template) obiwan.duckable({'id': 1, 'opt': 2}, template) self.assertRaises(obiwan.ObiwanError, obiwan.duckable, {'id': 1, 'x': 2}, template)
def test_strict(self): template = { obiwan.options: [obiwan.strict], 'id': int, obiwan.optional('opt'): int, } obiwan.duckable({'id': 1}, template) obiwan.duckable({'id': 1, 'opt': 2}, template) self.assertRaises(obiwan.ObiwanError, obiwan.duckable, { 'id': 1, 'x': 2 }, template)
def test_dict(self): template = { 'person': [{ 'id': int, obiwan.noneable('name'): str, obiwan.optional('age'): int }] } tests = [ {'person': [{'id': 1, 'name': None}]}, {'person': [{'id': 1, 'name': None, 'age': 14}]}, {'person': [{'id': 1, 'name': "Adam"}]} ] for test in tests: obiwan.duckable(test, template)
def test_subtype(self): base = { 'id': int, } parent = { obiwan.options: [obiwan.subtype(base)], obiwan.optional('y'): int, } template = { obiwan.options: [obiwan.strict, obiwan.subtype(parent)], 'x': int, } obiwan.duckable({'id': 1, 'x': 2}, template) obiwan.duckable({'id': 1, 'x': 2, 'y': 3}, template) self.assertRaises(obiwan.ObiwanError, obiwan.duckable, {'id': 1}, template) self.assertRaises(obiwan.ObiwanError, obiwan.duckable, {'id': 1, 'x': 2, 'z': 3}, template)
def test_subtype(self): base = { 'id': int, } parent = { obiwan.options: [obiwan.subtype(base)], obiwan.optional('y'): int, } template = { obiwan.options: [obiwan.strict, obiwan.subtype(parent)], 'x': int, } obiwan.duckable({'id': 1, 'x': 2}, template) obiwan.duckable({'id': 1, 'x': 2, 'y': 3}, template) self.assertRaises(obiwan.ObiwanError, obiwan.duckable, {'id': 1}, template) self.assertRaises(obiwan.ObiwanError, obiwan.duckable, { 'id': 1, 'x': 2, 'z': 3 }, template)