Example #1
0
 def test_opt_validate(self):
     inputs = [
         ({
             'a': 1,
             'arr': [1.0]
         }, True),
         ({
             'a': 1,
             'arr': [1.0],
             'b': 1.2
         }, True),
         ({
             'a': 2,
             'arr': [],
             'oarr': [{
                 'z': 1
             }]
         }, False),
         ({
             'a': 2,
             'arr': [],
             'oarr': [{
                 'x': 1
             }]
         }, True),
         ({
             'a': 1
         }, False),
     ]
     sch = schema.Schema(optionals)
     for doc, expect_ok in inputs:
         self.check(sch, doc, expect_ok)
Example #2
0
 def test_basic_validate(self):
     inputs = [
         ({'a': 1, 'b': 2.3, 'arr': [1.0], 'oarr': []}, True),
         ({'a': 1, 'b': 2.3, 'arr': [1.0], 'oarr': [{'x': 1}]}, True),
         ({'a': 1, 'b': 2.3, 'arr': [1.0], 'oarr': [{'z': 1}]}, False),
         ({'a': 1, 'b': 2.3, 'arr': [1.0], 'oarr': [{'x': [1, 2]}]}, False),
         ({'a': 1, 'b': 2.3, 'arr': [1.0], 'oarr': [{'x': Exception}]}, False)
     ]
     sch = schema.Schema(basic)
     for doc, expect_ok in inputs:
         self.check(sch, doc, expect_ok)
Example #3
0
 def test_create_js(self):
     for ex in (self.example_mine, self.example_mine_nounder):
         s = schema.Schema(ex)
         self.assertIn(s.json_schema(), (self.example_js, self.example_js2))
Example #4
0
 def test_unknown_type(self):
     try:
         schema.Schema({'a': '__foo__'})
     except schema.SchemaTypeError:
         pass