From 32ff00559e90624419e62a1b802214fc82c26112 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Tue, 18 Apr 2017 14:42:59 -0500 Subject: [PATCH] Rename exception class. --- stix2/base.py | 4 ++-- stix2/exceptions.py | 4 ++-- stix2/test/test_bundle.py | 6 +++--- stix2/test/test_indicator.py | 8 ++++---- stix2/test/test_malware.py | 4 ++-- stix2/test/test_markings.py | 2 +- stix2/test/test_relationship.py | 4 ++-- stix2/test/test_report.py | 2 +- stix2/test/test_sighting.py | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/stix2/base.py b/stix2/base.py index ca44daf..db4b8c3 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -4,7 +4,7 @@ import collections import datetime as dt import json -from .exceptions import STIXValueError, MissingFieldsError +from .exceptions import InvalidValueError, MissingFieldsError from .utils import format_datetime, get_timestamp, NOW __all__ = ['STIXJSONEncoder', '_STIXBase'] @@ -42,7 +42,7 @@ class _STIXBase(collections.Mapping): try: kwargs[prop_name] = prop.validate(kwargs[prop_name]) except ValueError as exc: - raise STIXValueError(self.__class__, prop_name, reason=str(exc)) + raise InvalidValueError(self.__class__, prop_name, reason=str(exc)) def __init__(self, **kwargs): cls = self.__class__ diff --git a/stix2/exceptions.py b/stix2/exceptions.py index e64a3de..138eb18 100644 --- a/stix2/exceptions.py +++ b/stix2/exceptions.py @@ -2,11 +2,11 @@ class STIXError(Exception): """Base class for errors generated in the stix2 library.""" -class STIXValueError(STIXError, ValueError): +class InvalidValueError(STIXError, ValueError): """An invalid value was provided to a STIX object's __init__.""" def __init__(self, cls, prop_name, reason): - super(STIXValueError, self).__init__() + super(InvalidValueError, self).__init__() self.cls = cls self.prop_name = prop_name self.reason = reason diff --git a/stix2/test/test_bundle.py b/stix2/test/test_bundle.py index b247473..6386a66 100644 --- a/stix2/test/test_bundle.py +++ b/stix2/test/test_bundle.py @@ -51,7 +51,7 @@ def test_empty_bundle(): def test_bundle_with_wrong_type(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Bundle(type="not-a-bundle") assert excinfo.value.cls == stix2.Bundle @@ -61,7 +61,7 @@ def test_bundle_with_wrong_type(): def test_bundle_id_must_start_with_bundle(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Bundle(id='my-prefix--') assert excinfo.value.cls == stix2.Bundle @@ -71,7 +71,7 @@ def test_bundle_id_must_start_with_bundle(): def test_bundle_with_wrong_spec_version(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Bundle(spec_version="1.2") assert excinfo.value.cls == stix2.Bundle diff --git a/stix2/test/test_indicator.py b/stix2/test/test_indicator.py index b532c3a..5c42556 100644 --- a/stix2/test/test_indicator.py +++ b/stix2/test/test_indicator.py @@ -67,7 +67,7 @@ def test_indicator_autogenerated_fields(indicator): def test_indicator_type_must_be_indicator(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Indicator(type='xxx', **INDICATOR_KWARGS) assert excinfo.value.cls == stix2.Indicator @@ -77,7 +77,7 @@ def test_indicator_type_must_be_indicator(): def test_indicator_id_must_start_with_indicator(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Indicator(id='my-prefix--', **INDICATOR_KWARGS) assert excinfo.value.cls == stix2.Indicator @@ -105,7 +105,7 @@ def test_indicator_required_field_pattern(): def test_indicator_created_ref_invalid_format(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Indicator(created_by_ref='myprefix--12345678', **INDICATOR_KWARGS) assert excinfo.value.cls == stix2.Indicator @@ -115,7 +115,7 @@ def test_indicator_created_ref_invalid_format(): def test_indicator_revoked_invalid(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Indicator(revoked='false', **INDICATOR_KWARGS) assert excinfo.value.cls == stix2.Indicator diff --git a/stix2/test/test_malware.py b/stix2/test/test_malware.py index ca83f33..6c5dbd2 100644 --- a/stix2/test/test_malware.py +++ b/stix2/test/test_malware.py @@ -51,7 +51,7 @@ def test_malware_autogenerated_fields(malware): def test_malware_type_must_be_malware(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Malware(type='xxx', **MALWARE_KWARGS) assert excinfo.value.cls == stix2.Malware @@ -61,7 +61,7 @@ def test_malware_type_must_be_malware(): def test_malware_id_must_start_with_malware(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Malware(id='my-prefix--', **MALWARE_KWARGS) assert excinfo.value.cls == stix2.Malware diff --git a/stix2/test/test_markings.py b/stix2/test/test_markings.py index 1cdc546..56ce771 100644 --- a/stix2/test/test_markings.py +++ b/stix2/test/test_markings.py @@ -87,7 +87,7 @@ def test_granular_example(): def test_granular_example_with_bad_selector(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.GranularMarking( marking_ref="marking-definition--613f2e26-407d-48c7-9eca-b8e91df99dc9", selectors=["abc[0]"] # missing "." diff --git a/stix2/test/test_relationship.py b/stix2/test/test_relationship.py index 527dbee..e4fa17e 100644 --- a/stix2/test/test_relationship.py +++ b/stix2/test/test_relationship.py @@ -54,7 +54,7 @@ def test_relationship_autogenerated_fields(relationship): def test_relationship_type_must_be_relationship(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Relationship(type='xxx', **RELATIONSHIP_KWARGS) assert excinfo.value.cls == stix2.Relationship @@ -64,7 +64,7 @@ def test_relationship_type_must_be_relationship(): def test_relationship_id_must_start_with_relationship(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Relationship(id='my-prefix--', **RELATIONSHIP_KWARGS) assert excinfo.value.cls == stix2.Relationship diff --git a/stix2/test/test_report.py b/stix2/test/test_report.py index 64fe326..1783255 100644 --- a/stix2/test/test_report.py +++ b/stix2/test/test_report.py @@ -63,7 +63,7 @@ def test_report_example_objects_in_object_refs(): def test_report_example_objects_in_object_refs_with_bad_id(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Report( id="report--84e4d88f-44ea-4bcd-bbf3-b2c1c320bcb3", created_by_ref="identity--a463ffb3-1bd9-4d94-b02d-74e4f1658283", diff --git a/stix2/test/test_sighting.py b/stix2/test/test_sighting.py index 45d1e4c..fb1d941 100644 --- a/stix2/test/test_sighting.py +++ b/stix2/test/test_sighting.py @@ -48,7 +48,7 @@ def test_sighting_all_required_fields(): def test_sighting_bad_where_sighted_refs(): now = dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc) - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Sighting( type='sighting', id=SIGHTING_ID, @@ -65,7 +65,7 @@ def test_sighting_bad_where_sighted_refs(): def test_sighting_type_must_be_sightings(): - with pytest.raises(stix2.exceptions.STIXValueError) as excinfo: + with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo: stix2.Sighting(type='xxx', **SIGHTING_KWARGS) assert excinfo.value.cls == stix2.Sighting