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 = [
|
||||
'pytz',
|
||||
'six',
|
||||
]
|
||||
|
||||
setup(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
import uuid
|
||||
import sys
|
||||
from six import PY2
|
||||
|
||||
|
||||
class Property(object):
|
||||
|
@ -93,6 +93,7 @@ class ListProperty(Property):
|
|||
except ValueError:
|
||||
raise
|
||||
|
||||
# STIX spec forbids empty lists
|
||||
if len(list_) < 1:
|
||||
raise ValueError("must not be empty.")
|
||||
|
||||
|
@ -109,16 +110,21 @@ class ListProperty(Property):
|
|||
return list_
|
||||
|
||||
def clean(self, value):
|
||||
try:
|
||||
iter(value)
|
||||
except TypeError:
|
||||
raise ValueError("must be an iterable.")
|
||||
|
||||
try:
|
||||
return [self.contained(**x) if type(x) is dict else self.contained(x) for x in value]
|
||||
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):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
if sys.version_info[0] == 2:
|
||||
if PY2:
|
||||
self.string_type = unicode
|
||||
else:
|
||||
self.string_type = str
|
||||
|
|
|
@ -90,27 +90,39 @@ def test_id_property():
|
|||
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()
|
||||
|
||||
assert bool_prop.validate(True) 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
|
||||
assert bool_prop.validate('true') 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
|
||||
assert bool_prop.validate('T') is not None
|
||||
assert bool_prop.validate('F') is not None
|
||||
assert bool_prop.validate('t') is not None
|
||||
assert bool_prop.validate('f') is not None
|
||||
assert bool_prop.validate(1) is not None
|
||||
assert bool_prop.validate(0) is not None
|
||||
for invalid in ('abc', ['false'], {'true': 'true'}, 2, -1):
|
||||
print(invalid)
|
||||
with pytest.raises(ValueError):
|
||||
bool_prop.validate(invalid)
|
||||
assert bool_prop.validate(value) is not None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
'abc',
|
||||
['false'],
|
||||
{'true': 'true'},
|
||||
2,
|
||||
-1,
|
||||
])
|
||||
def test_boolean_property_invalid(value):
|
||||
bool_prop = BooleanProperty()
|
||||
with pytest.raises(ValueError):
|
||||
bool_prop.validate(value)
|
||||
|
||||
|
||||
def test_reference_property():
|
||||
|
|
Loading…
Reference in New Issue