1
- from io import BytesIO
2
1
from unittest import TestCase
3
2
import json
4
3
5
4
from jsonschema import Draft4Validator , ValidationError , cli
6
- from jsonschema .compat import StringIO
5
+ from jsonschema .compat import NativeIO
7
6
from jsonschema .exceptions import SchemaError
8
7
9
8
@@ -42,7 +41,7 @@ def fake_open(self, path):
42
41
contents = {}
43
42
else :
44
43
self .fail ("What is {!r}" .format (path ))
45
- return BytesIO (json .dumps (contents ))
44
+ return NativeIO (json .dumps (contents ))
46
45
47
46
def test_find_validator_by_fully_qualified_object_name (self ):
48
47
arguments = cli .parse_args (
@@ -68,7 +67,7 @@ def test_find_validator_in_jsonschema(self):
68
67
69
68
class TestCLI (TestCase ):
70
69
def test_draft3_schema_draft4_validator (self ):
71
- stdout , stderr = StringIO (), StringIO ()
70
+ stdout , stderr = NativeIO (), NativeIO ()
72
71
with self .assertRaises (SchemaError ):
73
72
cli .run (
74
73
{
@@ -88,7 +87,7 @@ def test_draft3_schema_draft4_validator(self):
88
87
)
89
88
90
89
def test_successful_validation (self ):
91
- stdout , stderr = StringIO (), StringIO ()
90
+ stdout , stderr = NativeIO (), NativeIO ()
92
91
exit_code = cli .run (
93
92
{
94
93
"validator" : fake_validator (),
@@ -105,7 +104,7 @@ def test_successful_validation(self):
105
104
106
105
def test_unsuccessful_validation (self ):
107
106
error = ValidationError ("I am an error!" , instance = 1 )
108
- stdout , stderr = StringIO (), StringIO ()
107
+ stdout , stderr = NativeIO (), NativeIO ()
109
108
exit_code = cli .run (
110
109
{
111
110
"validator" : fake_validator ([error ]),
@@ -126,7 +125,7 @@ def test_unsuccessful_validation_multiple_instances(self):
126
125
ValidationError ("8" , instance = 1 ),
127
126
]
128
127
second_errors = [ValidationError ("7" , instance = 2 )]
129
- stdout , stderr = StringIO (), StringIO ()
128
+ stdout , stderr = NativeIO (), NativeIO ()
130
129
exit_code = cli .run (
131
130
{
132
131
"validator" : fake_validator (first_errors , second_errors ),
0 commit comments