From 6e4151aeebba03c112e6062c253c135d77364688 Mon Sep 17 00:00:00 2001 From: Rich Piazza Date: Thu, 19 Mar 2020 16:49:46 -0400 Subject: [PATCH] flaky --- stix2/base.py | 12 ++++++++---- stix2/core.py | 2 +- stix2/custom.py | 4 +++- stix2/test/v21/test_custom.py | 7 +++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/stix2/base.py b/stix2/base.py index eabff70..8bffa3a 100644 --- a/stix2/base.py +++ b/stix2/base.py @@ -16,9 +16,11 @@ from .exceptions import ( MissingPropertiesError, MutuallyExclusivePropertiesError, ) from .markings.utils import validate -from .utils import NOW, find_property_index, format_datetime, get_timestamp +from .utils import ( + NOW, PREFIX_21_REGEX, find_property_index, format_datetime, get_timestamp, +) from .utils import new_version as _new_version -from .utils import revoke as _revoke, PREFIX_21_REGEX +from .utils import revoke as _revoke try: from collections.abc import Mapping @@ -172,8 +174,10 @@ class _STIXBase(Mapping): if self.get_class_version() == "v21": for prop_name, prop_value in custom_props.items(): if not re.match(PREFIX_21_REGEX, prop_name): - raise InvalidValueError(self.__class__, prop_name, - reason="Property name '%s' must begin with an alpha character." % prop_name) + raise InvalidValueError( + self.__class__, prop_name, + reason="Property name '%s' must begin with an alpha character." % prop_name, + ) # Remove any keyword arguments whose value is None or [] (i.e. empty list) setting_kwargs = {} diff --git a/stix2/core.py b/stix2/core.py index 2c388f7..bd2b524 100644 --- a/stix2/core.py +++ b/stix2/core.py @@ -10,7 +10,7 @@ import stix2 from .base import _Observable, _STIXBase from .exceptions import ParseError from .markings import _MarkingsMixin -from .utils import _get_dict, TYPE_REGEX, PREFIX_21_REGEX, TYPE_21_REGEX +from .utils import PREFIX_21_REGEX, TYPE_21_REGEX, TYPE_REGEX, _get_dict STIX2_OBJ_MAPS = {} diff --git a/stix2/custom.py b/stix2/custom.py index 8a08f0e..bd2fe1d 100644 --- a/stix2/custom.py +++ b/stix2/custom.py @@ -8,7 +8,9 @@ from .core import ( STIXDomainObject, _register_marking, _register_object, _register_observable, _register_observable_extension, ) -from .utils import get_class_hierarchy_names, TYPE_21_REGEX, TYPE_REGEX, PREFIX_21_REGEX +from .utils import ( + PREFIX_21_REGEX, TYPE_21_REGEX, TYPE_REGEX, get_class_hierarchy_names, +) def _custom_object_builder(cls, type, properties, version): diff --git a/stix2/test/v21/test_custom.py b/stix2/test/v21/test_custom.py index c81d914..168c7fe 100644 --- a/stix2/test/v21/test_custom.py +++ b/stix2/test/v21/test_custom.py @@ -182,6 +182,7 @@ def test_custom_properties_dict_in_bundled_object(): # Custom properties in SCOs + def test_custom_property_in_observed_data(): artifact = stix2.v21.File( allow_custom=True, @@ -275,6 +276,7 @@ def test_identity_custom_property_revoke(): # Custom markings + def test_identity_custom_property_edit_markings(): marking_obj = stix2.v21.MarkingDefinition( id=MARKING_DEFINITION_ID, @@ -368,6 +370,7 @@ def test_custom_marking_invalid_type_name(): # Custom Objects + @stix2.v21.CustomObject( 'x-new-type', [ ('property1', stix2.properties.StringProperty(required=True)), @@ -499,6 +502,7 @@ def test_parse_unregistered_custom_object_type_w_allow_custom(): # Custom SCOs + @stix2.v21.CustomObservable( 'x-new-observable', [ ('property1', stix2.properties.StringProperty(required=True)), @@ -846,6 +850,7 @@ def test_custom_observable_object_no_id_contrib_props(): # Custom Extensions + @stix2.v21.CustomExtension( stix2.v21.DomainName, 'x-new-ext', [ ('property1', stix2.properties.StringProperty(required=True)), @@ -994,7 +999,6 @@ def test_custom_extension_invalid_type_name(): assert "Invalid extension type name '7x-new-ext':" in str(excinfo.value) - def test_custom_extension_no_properties(): with pytest.raises(ValueError): @stix2.v21.CustomExtension(stix2.v21.DomainName, 'x-new2-ext', None) @@ -1055,7 +1059,6 @@ def test_invalid_custom_property_in_extension(): assert "must begin with an alpha character." in str(excinfo.value) - def test_parse_observable_with_custom_extension(): input_str = """{ "type": "domain-name",