def test_draft3_schema_draft4_validator(self):
     stdout, stderr = StringIO(), StringIO()
     with self.assertRaises(SchemaError):
         cli.run(
             {
                 "validator": Draft4Validator,
                 "schema": {
                     "anyOf": [
                         {
                             "minimum": 20
                         },
                         {
                             "type": "string"
                         },
                         {
                             "required": True
                         },
                     ],
                 },
                 "instances": [1],
                 "error_format": "{error.message}",
             },
             stdout=stdout,
             stderr=stderr,
         )
Exemple #2
0
 def test_successful_validation(self):
     stdout, stderr = StringIO(), StringIO()
     exit_code = cli.run(
         {"validator": fake_validator(), "schema": {}, "instances": [1], "error_format": "{error.message}"},
         stdout=stdout,
         stderr=stderr,
     )
     self.assertFalse(stdout.getvalue())
     self.assertFalse(stderr.getvalue())
     self.assertEqual(exit_code, 0)
Exemple #3
0
 def test_successful_validation(self):
     stdout, stderr = StringIO(), StringIO()
     exit_code = cli.run(
         {
             "validator": fake_validator(),
             "schema": {},
             "instances": [1],
             "error_format": "{error.message}",
         },
         stdout=stdout,
         stderr=stderr,
     )
     self.assertFalse(stdout.getvalue())
     self.assertFalse(stderr.getvalue())
     self.assertEqual(exit_code, 0)
Exemple #4
0
 def test_unsuccessful_validation(self):
     error = ValidationError("I am an error!", instance=1)
     stdout, stderr = StringIO(), StringIO()
     exit_code = cli.run(
         {
             "validator": fake_validator([error]),
             "schema": {},
             "instances": [1],
             "error_format": "{error.instance} - {error.message}",
         },
         stdout=stdout,
         stderr=stderr,
     )
     self.assertFalse(stdout.getvalue())
     self.assertEqual(stderr.getvalue(), "1 - I am an error!")
     self.assertEqual(exit_code, 1)
Exemple #5
0
 def test_unsuccessful_validation(self):
     error = ValidationError("I am an error!", instance=1)
     stdout, stderr = StringIO(), StringIO()
     exit_code = cli.run(
         {
             "validator": fake_validator([error]),
             "schema": {},
             "instances": [1],
             "error_format": "{error.instance} - {error.message}",
         },
         stdout=stdout,
         stderr=stderr,
     )
     self.assertFalse(stdout.getvalue())
     self.assertEqual(stderr.getvalue(), "1 - I am an error!")
     self.assertEqual(exit_code, 1)
Exemple #6
0
 def test_unsuccessful_validation_multiple_instances(self):
     first_errors = [ValidationError("9", instance=1), ValidationError("8", instance=1)]
     second_errors = [ValidationError("7", instance=2)]
     stdout, stderr = StringIO(), StringIO()
     exit_code = cli.run(
         {
             "validator": fake_validator(first_errors, second_errors),
             "schema": {},
             "instances": [1, 2],
             "error_format": "{error.instance} - {error.message}\t",
         },
         stdout=stdout,
         stderr=stderr,
     )
     self.assertFalse(stdout.getvalue())
     self.assertEqual(stderr.getvalue(), "1 - 9\t1 - 8\t2 - 7\t")
     self.assertEqual(exit_code, 1)
Exemple #7
0
 def test_unsuccessful_validation_multiple_instances(self):
     first_errors = [
         ValidationError("9", instance=1),
         ValidationError("8", instance=1),
     ]
     second_errors = [ValidationError("7", instance=2)]
     stdout, stderr = StringIO(), StringIO()
     exit_code = cli.run(
         {
             "validator": fake_validator(first_errors, second_errors),
             "schema": {},
             "instances": [1, 2],
             "error_format": "{error.instance} - {error.message}\t",
         },
         stdout=stdout,
         stderr=stderr,
     )
     self.assertFalse(stdout.getvalue())
     self.assertEqual(stderr.getvalue(), "1 - 9\t1 - 8\t2 - 7\t")
     self.assertEqual(exit_code, 1)