本文整理匯總了Python中jsonschema.compat.StringIO方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.StringIO方法的具體用法?Python compat.StringIO怎麽用?Python compat.StringIO使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jsonschema.compat
的用法示例。
在下文中一共展示了compat.StringIO方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_draft3_schema_draft4_validator
# 需要導入模塊: from jsonschema import compat [as 別名]
# 或者: from jsonschema.compat import StringIO [as 別名]
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,
)
示例2: test_unsuccessful_validation
# 需要導入模塊: from jsonschema import compat [as 別名]
# 或者: from jsonschema.compat import StringIO [as 別名]
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)
示例3: test_unsuccessful_validation_multiple_instances
# 需要導入模塊: from jsonschema import compat [as 別名]
# 或者: from jsonschema.compat import StringIO [as 別名]
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)
示例4: test_successful_validation
# 需要導入模塊: from jsonschema import compat [as 別名]
# 或者: from jsonschema.compat import StringIO [as 別名]
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)