Changed emitted deprecation warnings to a custom DeprecationWarning

subclass.  Changed the unit test to test for that specific
warning category, instead of any DeprecationWarning.
master
Michael Chisholm 2019-08-07 10:16:18 -04:00
parent 27beec4060
commit 5e5a03c001
4 changed files with 12 additions and 4 deletions

View File

@ -226,3 +226,10 @@ class MarkingNotFoundError(STIXError):
def __str__(self): def __str__(self):
msg = "Marking {0} was not found in {1}!" msg = "Marking {0} was not found in {1}!"
return msg.format(self.key, self.cls.__class__.__name__) return msg.format(self.key, self.cls.__class__.__name__)
class STIXDeprecationWarning(DeprecationWarning):
"""
Represents usage of a deprecated component of a STIX specification.
"""
pass

View File

@ -1378,7 +1378,8 @@ def test_new_version_with_related_objects():
def test_objects_deprecation(): def test_objects_deprecation():
with pytest.deprecated_call(): with pytest.warns(stix2.exceptions.STIXDeprecationWarning):
stix2.v21.ObservedData( stix2.v21.ObservedData(
first_observed="2016-03-12T12:00:00Z", first_observed="2016-03-12T12:00:00Z",
last_observed="2016-03-12T12:00:00Z", last_observed="2016-03-12T12:00:00Z",

View File

@ -8,7 +8,7 @@ from six.moves.urllib.parse import quote_plus
from ..core import STIXDomainObject from ..core import STIXDomainObject
from ..custom import _custom_object_builder from ..custom import _custom_object_builder
from ..exceptions import PropertyPresenceError from ..exceptions import PropertyPresenceError, STIXDeprecationWarning
from ..properties import ( from ..properties import (
BinaryProperty, BooleanProperty, EmbeddedObjectProperty, EnumProperty, BinaryProperty, BooleanProperty, EmbeddedObjectProperty, EnumProperty,
FloatProperty, IDProperty, IntegerProperty, ListProperty, FloatProperty, IDProperty, IntegerProperty, ListProperty,
@ -578,7 +578,7 @@ class ObservedData(STIXDomainObject):
warnings.warn( warnings.warn(
"The 'objects' property of observed-data is deprecated in " "The 'objects' property of observed-data is deprecated in "
"STIX 2.1.", "STIX 2.1.",
DeprecationWarning, STIXDeprecationWarning,
) )
super(ObservedData, self).__init__(*args, **kwargs) super(ObservedData, self).__init__(*args, **kwargs)

View File

@ -11,7 +11,7 @@ deps =
taxii2-client taxii2-client
medallion medallion
commands = commands =
pytest --cov=stix2 stix2/test/ --cov-report term-missing pytest --cov=stix2 stix2/test/ --cov-report term-missing -W ignore::stix2.exceptions.STIXDeprecationWarning
passenv = CI TRAVIS TRAVIS_* passenv = CI TRAVIS TRAVIS_*