本文整理汇总了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)