Skip to content

Commit be5097d

Browse files
committed
Workaround for tests in Python 3.4
related bug: http://bugs.python.org/issue21750
1 parent e8ba6a6 commit be5097d

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

jsonschema/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def _json_file(path):
4040
"-V", "--validator",
4141
type=_namedAnyWithDefault,
4242
help="the fully qualified object name of a validator to use, or, for "
43-
"validators that are registered with jsonschema, simply the name "
44-
"of the class.",
43+
"validators that are registered with jsonschema, simply the name "
44+
"of the class.",
4545
)
4646
parser.add_argument(
4747
"schema",

jsonschema/tests/test_cli.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ def iter_errors(self, instance):
1818

1919

2020
class TestParser(unittest.TestCase):
21-
2221
FakeValidator = fake_validator()
2322

2423
def setUp(self):
25-
self.open = mock.mock_open(read_data='{}')
26-
patch = mock.patch.object(cli, "open", self.open, create=True)
27-
patch.start()
28-
self.addCleanup(patch.stop)
24+
mock_open = mock.mock_open()
25+
patch_open = mock.patch.object(cli, "open", mock_open, create=True)
26+
patch_open.start()
27+
self.addCleanup(patch_open.stop)
28+
29+
mock_json_load = mock.Mock()
30+
mock_json_load.return_value = {}
31+
patch_json_load = mock.patch("json.load")
32+
patch_json_load.start()
33+
self.addCleanup(patch_json_load.stop)
2934

3035
def test_find_validator_by_fully_qualified_object_name(self):
3136
arguments = cli.parse_args(
@@ -54,10 +59,10 @@ def test_successful_validation(self):
5459
stdout, stderr = StringIO(), StringIO()
5560
exit_code = cli.run(
5661
{
57-
"validator" : fake_validator(),
58-
"schema" : {},
59-
"instances" : [1],
60-
"error_format" : "{error.message}",
62+
"validator": fake_validator(),
63+
"schema": {},
64+
"instances": [1],
65+
"error_format": "{error.message}",
6166
},
6267
stdout=stdout,
6368
stderr=stderr,
@@ -71,10 +76,10 @@ def test_unsuccessful_validation(self):
7176
stdout, stderr = StringIO(), StringIO()
7277
exit_code = cli.run(
7378
{
74-
"validator" : fake_validator([error]),
75-
"schema" : {},
76-
"instances" : [1],
77-
"error_format" : "{error.instance} - {error.message}",
79+
"validator": fake_validator([error]),
80+
"schema": {},
81+
"instances": [1],
82+
"error_format": "{error.instance} - {error.message}",
7883
},
7984
stdout=stdout,
8085
stderr=stderr,
@@ -92,10 +97,10 @@ def test_unsuccessful_validation_multiple_instances(self):
9297
stdout, stderr = StringIO(), StringIO()
9398
exit_code = cli.run(
9499
{
95-
"validator" : fake_validator(first_errors, second_errors),
96-
"schema" : {},
97-
"instances" : [1, 2],
98-
"error_format" : "{error.instance} - {error.message}\t",
100+
"validator": fake_validator(first_errors, second_errors),
101+
"schema": {},
102+
"instances": [1, 2],
103+
"error_format": "{error.instance} - {error.message}\t",
99104
},
100105
stdout=stdout,
101106
stderr=stderr,

0 commit comments

Comments
 (0)