From 5e5a03c001d72f21abd03758b5c29fdd91504a1a Mon Sep 17 00:00:00 2001 From: Michael Chisholm Date: Wed, 7 Aug 2019 10:16:18 -0400 Subject: [PATCH] Changed emitted deprecation warnings to a custom DeprecationWarning subclass. Changed the unit test to test for that specific warning category, instead of any DeprecationWarning. --- stix2/exceptions.py | 7 +++++++ stix2/test/v21/test_observed_data.py | 3 ++- stix2/v21/sdo.py | 4 ++-- tox.ini | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/stix2/exceptions.py b/stix2/exceptions.py index c680774..d2ec3fc 100644 --- a/stix2/exceptions.py +++ b/stix2/exceptions.py @@ -226,3 +226,10 @@ class MarkingNotFoundError(STIXError): def __str__(self): msg = "Marking {0} was not found in {1}!" return msg.format(self.key, self.cls.__class__.__name__) + + +class STIXDeprecationWarning(DeprecationWarning): + """ + Represents usage of a deprecated component of a STIX specification. + """ + pass diff --git a/stix2/test/v21/test_observed_data.py b/stix2/test/v21/test_observed_data.py index b4e3f31..c2999f8 100644 --- a/stix2/test/v21/test_observed_data.py +++ b/stix2/test/v21/test_observed_data.py @@ -1378,7 +1378,8 @@ def test_new_version_with_related_objects(): def test_objects_deprecation(): - with pytest.deprecated_call(): + with pytest.warns(stix2.exceptions.STIXDeprecationWarning): + stix2.v21.ObservedData( first_observed="2016-03-12T12:00:00Z", last_observed="2016-03-12T12:00:00Z", diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py index f04ea98..662007c 100644 --- a/stix2/v21/sdo.py +++ b/stix2/v21/sdo.py @@ -8,7 +8,7 @@ from six.moves.urllib.parse import quote_plus from ..core import STIXDomainObject from ..custom import _custom_object_builder -from ..exceptions import PropertyPresenceError +from ..exceptions import PropertyPresenceError, STIXDeprecationWarning from ..properties import ( BinaryProperty, BooleanProperty, EmbeddedObjectProperty, EnumProperty, FloatProperty, IDProperty, IntegerProperty, ListProperty, @@ -578,7 +578,7 @@ class ObservedData(STIXDomainObject): warnings.warn( "The 'objects' property of observed-data is deprecated in " "STIX 2.1.", - DeprecationWarning, + STIXDeprecationWarning, ) super(ObservedData, self).__init__(*args, **kwargs) diff --git a/tox.ini b/tox.ini index 5deb4ef..e075386 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ deps = taxii2-client medallion 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_*