Merge pull request #172 from oasis-open/171-make-constant

Fix make_constant when value is already a constant
stix2.0
Greg Back 2018-04-26 10:39:05 -05:00 committed by GitHub
commit 784893e178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -147,6 +147,9 @@ class ListConstant(_Constant):
def make_constant(value):
if isinstance(value, _Constant):
return value
try:
return parse_into_datetime(value)
except ValueError:

View File

@ -372,3 +372,9 @@ def test_invalid_startstop_qualifier():
stix2.StartStopQualifier(datetime.date(2016, 6, 1),
'foo')
assert 'is not a valid argument for a Start/Stop Qualifier' in str(excinfo)
def test_make_constant_already_a_constant():
str_const = stix2.StringConstant('Foo')
result = stix2.patterns.make_constant(str_const)
assert result is str_const