Clean up code/comments
parent
bab8d187c9
commit
dd382520d6
1
setup.py
1
setup.py
|
@ -3,6 +3,7 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
install_requires = [
|
install_requires = [
|
||||||
'pytz',
|
'pytz',
|
||||||
|
'six',
|
||||||
]
|
]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import re
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
import sys
|
from six import PY2
|
||||||
|
|
||||||
|
|
||||||
class Property(object):
|
class Property(object):
|
||||||
|
@ -93,6 +93,7 @@ class ListProperty(Property):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
# STIX spec forbids empty lists
|
||||||
if len(list_) < 1:
|
if len(list_) < 1:
|
||||||
raise ValueError("must not be empty.")
|
raise ValueError("must not be empty.")
|
||||||
|
|
||||||
|
@ -109,16 +110,21 @@ class ListProperty(Property):
|
||||||
return list_
|
return list_
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
|
try:
|
||||||
|
iter(value)
|
||||||
|
except TypeError:
|
||||||
|
raise ValueError("must be an iterable.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return [self.contained(**x) if type(x) is dict else self.contained(x) for x in value]
|
return [self.contained(**x) if type(x) is dict else self.contained(x) for x in value]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise ValueError("must be an iterable over a type whose constructor creates an object from the value.")
|
raise ValueError("the type of objects in the list must have a constructor that creates an object from the value.")
|
||||||
|
|
||||||
|
|
||||||
class StringProperty(Property):
|
class StringProperty(Property):
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if sys.version_info[0] == 2:
|
if PY2:
|
||||||
self.string_type = unicode
|
self.string_type = unicode
|
||||||
else:
|
else:
|
||||||
self.string_type = str
|
self.string_type = str
|
||||||
|
|
|
@ -90,27 +90,39 @@ def test_id_property():
|
||||||
assert idprop.validate(idprop.default())
|
assert idprop.validate(idprop.default())
|
||||||
|
|
||||||
|
|
||||||
def test_boolean_property():
|
@pytest.mark.parametrize("value", [
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
'True',
|
||||||
|
'False',
|
||||||
|
'true',
|
||||||
|
'false',
|
||||||
|
'TRUE',
|
||||||
|
'FALSE',
|
||||||
|
'T',
|
||||||
|
'F',
|
||||||
|
't',
|
||||||
|
'f',
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
])
|
||||||
|
def test_boolean_property_valid(value):
|
||||||
bool_prop = BooleanProperty()
|
bool_prop = BooleanProperty()
|
||||||
|
|
||||||
assert bool_prop.validate(True) is not None
|
assert bool_prop.validate(value) is not None
|
||||||
assert bool_prop.validate(False) is not None
|
|
||||||
assert bool_prop.validate('True') is not None
|
|
||||||
assert bool_prop.validate('False') is not None
|
@pytest.mark.parametrize("value", [
|
||||||
assert bool_prop.validate('true') is not None
|
'abc',
|
||||||
assert bool_prop.validate('false') is not None
|
['false'],
|
||||||
assert bool_prop.validate('TRUE') is not None
|
{'true': 'true'},
|
||||||
assert bool_prop.validate('FALSE') is not None
|
2,
|
||||||
assert bool_prop.validate('T') is not None
|
-1,
|
||||||
assert bool_prop.validate('F') is not None
|
])
|
||||||
assert bool_prop.validate('t') is not None
|
def test_boolean_property_invalid(value):
|
||||||
assert bool_prop.validate('f') is not None
|
bool_prop = BooleanProperty()
|
||||||
assert bool_prop.validate(1) is not None
|
with pytest.raises(ValueError):
|
||||||
assert bool_prop.validate(0) is not None
|
bool_prop.validate(value)
|
||||||
for invalid in ('abc', ['false'], {'true': 'true'}, 2, -1):
|
|
||||||
print(invalid)
|
|
||||||
with pytest.raises(ValueError):
|
|
||||||
bool_prop.validate(invalid)
|
|
||||||
|
|
||||||
|
|
||||||
def test_reference_property():
|
def test_reference_property():
|
||||||
|
|
Loading…
Reference in New Issue