Skip to content

Commit

Permalink
Workaround for tests in Python 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bayandin committed Jun 20, 2014
1 parent e8ba6a6 commit be5097d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions jsonschema/cli.py
Expand Up @@ -40,8 +40,8 @@ def _json_file(path):
"-V", "--validator",
type=_namedAnyWithDefault,
help="the fully qualified object name of a validator to use, or, for "
"validators that are registered with jsonschema, simply the name "
"of the class.",
"validators that are registered with jsonschema, simply the name "
"of the class.",
)
parser.add_argument(
"schema",
Expand Down
39 changes: 22 additions & 17 deletions jsonschema/tests/test_cli.py
Expand Up @@ -18,14 +18,19 @@ def iter_errors(self, instance):


class TestParser(unittest.TestCase):

FakeValidator = fake_validator()

def setUp(self):
self.open = mock.mock_open(read_data='{}')
patch = mock.patch.object(cli, "open", self.open, create=True)
patch.start()
self.addCleanup(patch.stop)
mock_open = mock.mock_open()
patch_open = mock.patch.object(cli, "open", mock_open, create=True)
patch_open.start()
self.addCleanup(patch_open.stop)

mock_json_load = mock.Mock()
mock_json_load.return_value = {}
patch_json_load = mock.patch("json.load")
patch_json_load.start()
self.addCleanup(patch_json_load.stop)

def test_find_validator_by_fully_qualified_object_name(self):
arguments = cli.parse_args(
Expand Down Expand Up @@ -54,10 +59,10 @@ def test_successful_validation(self):
stdout, stderr = StringIO(), StringIO()
exit_code = cli.run(
{
"validator" : fake_validator(),
"schema" : {},
"instances" : [1],
"error_format" : "{error.message}",
"validator": fake_validator(),
"schema": {},
"instances": [1],
"error_format": "{error.message}",
},
stdout=stdout,
stderr=stderr,
Expand All @@ -71,10 +76,10 @@ def test_unsuccessful_validation(self):
stdout, stderr = StringIO(), StringIO()
exit_code = cli.run(
{
"validator" : fake_validator([error]),
"schema" : {},
"instances" : [1],
"error_format" : "{error.instance} - {error.message}",
"validator": fake_validator([error]),
"schema": {},
"instances": [1],
"error_format": "{error.instance} - {error.message}",
},
stdout=stdout,
stderr=stderr,
Expand All @@ -92,10 +97,10 @@ def test_unsuccessful_validation_multiple_instances(self):
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",
"validator": fake_validator(first_errors, second_errors),
"schema": {},
"instances": [1, 2],
"error_format": "{error.instance} - {error.message}\t",
},
stdout=stdout,
stderr=stderr,
Expand Down

0 comments on commit be5097d

Please sign in to comment.