Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_reraise_without_value_extra_message():
with pytest.raises(ValidationError) as caught:
exceptions.raise_from(ValidationError, None, 'asdf')
# The first is obvious from pytest.raises. The rest tests
# known attributes
assert caught.type == ValidationError
assert str(caught.value) == 'asdf'
def test_reraise_with_value_no_extra_message():
with pytest.raises(ValidationError) as caught:
try:
raise RuntimeError("foo")
except RuntimeError as inner:
exceptions.raise_from(ValidationError, inner)
# The first is obvious from pytest.raises. The rest tests
# known attributes
assert caught.type == ValidationError
assert str(caught.value) == 'foo'
def test_reraise_without_value_no_extra_message():
with pytest.raises(ValidationError) as caught:
exceptions.raise_from(ValidationError, None)
# The first is obvious from pytest.raises. The rest tests
# known attributes
assert caught.type == ValidationError
assert str(caught.value) == ''
def test_reraise_with_empty_value_string_extra_message():
with pytest.raises(ValidationError) as caught:
try:
raise RuntimeError()
except RuntimeError as inner:
exceptions.raise_from(ValidationError, inner, 'asdf')
# The first is obvious from pytest.raises. The rest tests
# known attributes
assert caught.type == ValidationError
assert str(caught.value) == 'asdf'
def _validate_openapi_spec_validator(self, spec_version): # pragma: nocover
from openapi_spec_validator import validate_v2_spec, validate_v3_spec
from jsonschema.exceptions import ValidationError as JSEValidationError
from jsonschema.exceptions import RefResolutionError
# Validate according to detected version. Unsupported versions are
# already caught outside of this function.
from .util.exceptions import raise_from
if spec_version[0] == 3:
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_3_PREFIX, spec_version)
try:
validate_v3_spec(self.specification)
except TypeError as type_ex:
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v3_ex:
raise_from(ValidationError, v3_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)
elif spec_version[0] == 2:
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version)
try:
validate_v2_spec(self.specification)
except TypeError as type_ex: # pragma: nocover
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v2_ex:
raise_from(ValidationError, v2_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)
except TypeError as type_ex:
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v3_ex:
raise_from(ValidationError, v3_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)
elif spec_version[0] == 2:
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version)
try:
validate_v2_spec(self.specification)
except TypeError as type_ex: # pragma: nocover
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v2_ex:
raise_from(ValidationError, v2_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)
from jsonschema.exceptions import ValidationError as JSEValidationError
from jsonschema.exceptions import RefResolutionError
# Validate according to detected version. Unsupported versions are
# already caught outside of this function.
from .util.exceptions import raise_from
if spec_version[0] == 3:
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_3_PREFIX, spec_version)
try:
validate_v3_spec(self.specification)
except TypeError as type_ex:
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v3_ex:
raise_from(ValidationError, v3_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)
elif spec_version[0] == 2:
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version)
try:
validate_v2_spec(self.specification)
except TypeError as type_ex: # pragma: nocover
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v2_ex:
raise_from(ValidationError, v2_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)
def _validate_swagger_spec_validator(self, spec_version): # pragma: nocover
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version)
from swagger_spec_validator.common import SwaggerValidationError as SSVErr
from swagger_spec_validator.validator20 import validate_spec
try:
validate_spec(self.specification)
except SSVErr as ex:
from .util.exceptions import raise_from
raise_from(ValidationError, ex)
def _validate_flex(self, spec_version): # pragma: nocover
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version)
from flex.exceptions import ValidationError as JSEValidationError
from flex.core import parse as validate
try:
validate(self.specification)
except JSEValidationError as ex:
from .util.exceptions import raise_from
raise_from(ValidationError, ex)
# Validate according to detected version. Unsupported versions are
# already caught outside of this function.
from .util.exceptions import raise_from
if spec_version[0] == 3:
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_3_PREFIX, spec_version)
try:
validate_v3_spec(self.specification)
except TypeError as type_ex:
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v3_ex:
raise_from(ValidationError, v3_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)
elif spec_version[0] == 2:
# Set the version independently of whether validation succeeds
self.__set_version(BaseParser.SPEC_VERSION_2_PREFIX, spec_version)
try:
validate_v2_spec(self.specification)
except TypeError as type_ex: # pragma: nocover
raise_from(ValidationError, type_ex, self._strict_warning())
except JSEValidationError as v2_ex:
raise_from(ValidationError, v2_ex)
except RefResolutionError as ref_ex:
raise_from(ValidationError, ref_ex)