diff --git a/pre_commit/jsonschema_extensions.py b/pre_commit/jsonschema_extensions.py index 1187415e..d287bcaf 100644 --- a/pre_commit/jsonschema_extensions.py +++ b/pre_commit/jsonschema_extensions.py @@ -8,11 +8,8 @@ def extend_validator_cls(validator_cls, modify): validate_properties = validator_cls.VALIDATORS['properties'] def new_properties(validator, properties, instance, schema): - for error in validate_properties( - validator, properties, instance, schema, - ): - yield error - + # Exhaust the validator + list(validate_properties(validator, properties, instance, schema)) modify(properties, instance) return jsonschema.validators.extend( diff --git a/pre_commit/prefixed_command_runner.py b/pre_commit/prefixed_command_runner.py index 9649648c..d8a562a2 100644 --- a/pre_commit/prefixed_command_runner.py +++ b/pre_commit/prefixed_command_runner.py @@ -66,9 +66,9 @@ class PrefixedCommandRunner(object): proc = self.__popen(replaced_cmd, **popen_kwargs) stdout, stderr = proc.communicate(stdin) # TODO: stdout, stderr = from_bytes(stdout), from_bytes(stderr) - if stdout is not None and not isinstance(stdout, five.text): + if isinstance(stdout, bytes): stdout = five.text(stdout, 'utf-8') - if stderr is not None and not isinstance(stderr, five.text): + if isinstance(stderr, bytes): stderr = five.text(stderr, 'utf-8') returncode = proc.returncode diff --git a/tests/jsonschema_extensions_test.py b/tests/jsonschema_extensions_test.py index 5680a333..d5a3b4d2 100644 --- a/tests/jsonschema_extensions_test.py +++ b/tests/jsonschema_extensions_test.py @@ -1,3 +1,6 @@ +import jsonschema.exceptions +import pytest + from pre_commit.jsonschema_extensions import apply_defaults from pre_commit.jsonschema_extensions import remove_defaults @@ -78,3 +81,9 @@ def test_remove_defaults_removes_default(): {'properties': {'foo': {'default': 'bar'}}}, ) assert ret == {} + + +@pytest.mark.parametrize('func', (apply_defaults, remove_defaults)) +def test_still_validates_schema(func): + with pytest.raises(jsonschema.exceptions.ValidationError): + func({}, {'properties': {'foo': {}}, 'required': ['foo']}) diff --git a/tests/prefixed_command_runner_test.py b/tests/prefixed_command_runner_test.py index d6b1f186..cd8523a4 100644 --- a/tests/prefixed_command_runner_test.py +++ b/tests/prefixed_command_runner_test.py @@ -21,7 +21,7 @@ def test_CalledProcessError_str(): @pytest.fixture def popen_mock(): popen = mock.Mock(spec=subprocess.Popen) - popen.return_value.communicate.return_value = ('stdout', 'stderr') + popen.return_value.communicate.return_value = (b'stdout', b'stderr') return popen