コード例 #1
0
 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})
コード例 #2
0
 def test_objects_optional_fields_must_have_string_keys(self):
     with self.assertRaises(TypeError):
         json.objects(optional_fields={42: 24})
コード例 #3
0
 def test_objects_required_fields_must_have_string_keys(self):
     with self.assertRaises(TypeError):
         json.objects(required_fields={42: 24})
コード例 #4
0
 def test_objects_requires_any_fields_definition(self):
     with self.assertRaises(RuntimeError):
         json.objects()
コード例 #5
0
 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})
コード例 #6
0
 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)
コード例 #7
0
 def test_objects(self):
     st = json.objects(json.values())
     value = hypothesis.find(st, lambda _: True)
     self.assertIsInstance(value, dict)
     self.assertEqual(value, {})