-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
182 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
from six import iterkeys | ||
from six.moves.cPickle import dumps | ||
|
||
from bravado_core.model import _from_pickleable_representation | ||
from bravado_core.model import _to_pickleable_representation | ||
from bravado_core.model import ModelDocstring | ||
|
||
|
||
def test_ensure_pickleable_representation_is_pickleable(cat_type): | ||
pickleable_representation = _to_pickleable_representation('Cat', cat_type) | ||
# Ensures that the pickle.dump of the pickleable representation is pickleable | ||
# If the dumps call does not raise an exception then we were able to pickle | ||
# the model type | ||
dumps(pickleable_representation) | ||
|
||
|
||
def test_ensure_that_get_model_type__from_pickleable_representation_returns_the_original_model(cat_type): | ||
# Ensures that the pickle.dump of the pickleable representation is pickleable | ||
# If the dumps call does not raise an exception then we were able to pickle | ||
# the model type | ||
reconstructed_model_type = _from_pickleable_representation( | ||
model_pickleable_representation=_to_pickleable_representation('Cat', cat_type), | ||
) | ||
assert reconstructed_model_type.__name__ == 'Cat' | ||
|
||
def is_the_same(attr_name): | ||
if attr_name == '_swagger_spec': | ||
return cat_type._swagger_spec.is_equal(reconstructed_model_type._swagger_spec) | ||
elif attr_name == '__doc__': | ||
return ( | ||
isinstance(cat_type.__dict__[attr_name], ModelDocstring) and | ||
isinstance(reconstructed_model_type.__dict__[attr_name], ModelDocstring) | ||
) | ||
elif attr_name == '_abc_impl': | ||
# _abc_impl is of type builtins._abc_data which is not really comparable. So we'll ignore it | ||
return True | ||
else: | ||
return cat_type.__dict__[attr_name] == reconstructed_model_type.__dict__[attr_name] | ||
|
||
assert [ | ||
attribute_name | ||
for attribute_name in iterkeys(cat_type.__dict__) | ||
if not is_the_same(attribute_name) | ||
] == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
import mock | ||
import pytest | ||
from six.moves.cPickle import dumps | ||
from six.moves.cPickle import loads | ||
|
||
from bravado_core.spec import Spec | ||
from tests.conftest import get_url | ||
|
||
|
||
@pytest.mark.parametrize('validate_swagger_spec', [True, False]) | ||
@pytest.mark.parametrize('internally_dereference_refs', [True, False]) | ||
def test_ensure_spec_is_pickleable(petstore_dict, petstore_abspath, internally_dereference_refs, validate_swagger_spec): | ||
spec = Spec.from_dict( | ||
spec_dict=petstore_dict, | ||
origin_url=get_url(petstore_abspath), | ||
config={ | ||
'validate_swagger_spec': validate_swagger_spec, | ||
'internally_dereference_refs': internally_dereference_refs, | ||
}, | ||
) | ||
assert spec.is_equal(loads(dumps(spec))) | ||
|
||
|
||
def test_ensure_warning_presence_in_case_of_version_mismatch(petstore_spec): | ||
with mock.patch('bravado_core.spec._version', '0.0.0'): | ||
petstore_pickle = dumps(petstore_spec) | ||
|
||
with pytest.warns(UserWarning, match='different bravado-core version.*created by version 0.0.0, current version'): | ||
restored_petstore_spec = loads(petstore_pickle) | ||
assert petstore_spec.is_equal(restored_petstore_spec) |