def test_objects_with_required_and_optional_fields(self): st = json.objects(required_fields={'always': json.booleans()}, optional_fields={'maybe': json.booleans()}) self.assertEqual(hypothesis.find( st, lambda v: v['always'] and 'maybe' not in v), {'always': True}) self.assertEqual(hypothesis.find( st, lambda v: v['always'] and 'maybe' in v), {'always': True, 'maybe': False})
def test_objects_optional_fields_must_have_string_keys(self): with self.assertRaises(TypeError): json.objects(optional_fields={42: 24})
def test_objects_required_fields_must_have_string_keys(self): with self.assertRaises(TypeError): json.objects(required_fields={42: 24})
def test_objects_requires_any_fields_definition(self): with self.assertRaises(RuntimeError): json.objects()
def test_objects_may_contains_optional_fields(self): st = json.objects(optional_fields={'test': json.nulls()}) self.assertEqual(hypothesis.find(st, lambda v: 'test' not in v), {}) self.assertEqual(hypothesis.find(st, lambda v: 'test' in v), {'test': None})
def test_objects_always_contains_required_fields(self): st = json.objects(required_fields={'test': json.nulls()}) with self.assertRaises(NoSuchExample): hypothesis.find(st, lambda v: 'test' not in v)
def test_objects(self): st = json.objects(json.values()) value = hypothesis.find(st, lambda _: True) self.assertIsInstance(value, dict) self.assertEqual(value, {})