Added the six module to test int/long support
This commit is contained in:
parent
fed58f3920
commit
66b233eaea
@ -8,6 +8,8 @@ import uuid
|
|||||||
import warnings
|
import warnings
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dateutil
|
import dateutil
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -260,14 +262,14 @@ class FloatField(BaseField):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
if isinstance(value, (int, long)):
|
if isinstance(value, six.integer_types):
|
||||||
try:
|
try:
|
||||||
value = float(value)
|
value = float(value)
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
self.error('The value is too large to be converted to float')
|
self.error('The value is too large to be converted to float')
|
||||||
|
|
||||||
if not isinstance(value, float):
|
if not isinstance(value, float):
|
||||||
self.error('FloatField only accepts float, int and long values')
|
self.error('FloatField only accepts float and integer values')
|
||||||
|
|
||||||
if self.min_value is not None and value < self.min_value:
|
if self.min_value is not None and value < self.min_value:
|
||||||
self.error('Float value is too small')
|
self.error('Float value is too small')
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
pymongo>=2.7.1
|
|
||||||
nose
|
nose
|
||||||
|
pymongo>=2.7.1
|
||||||
|
six==1.10.0
|
||||||
|
2
setup.py
2
setup.py
@ -78,7 +78,7 @@ setup(name='mongoengine',
|
|||||||
long_description=LONG_DESCRIPTION,
|
long_description=LONG_DESCRIPTION,
|
||||||
platforms=['any'],
|
platforms=['any'],
|
||||||
classifiers=CLASSIFIERS,
|
classifiers=CLASSIFIERS,
|
||||||
install_requires=['pymongo>=2.7.1'],
|
install_requires=['pymongo>=2.7.1', 'six'],
|
||||||
test_suite='nose.collector',
|
test_suite='nose.collector',
|
||||||
**extra_opts
|
**extra_opts
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import six
|
||||||
from nose.plugins.skip import SkipTest
|
from nose.plugins.skip import SkipTest
|
||||||
|
|
||||||
sys.path[0:0] = [""]
|
sys.path[0:0] = [""]
|
||||||
@ -420,8 +422,9 @@ class FieldTest(unittest.TestCase):
|
|||||||
|
|
||||||
big_person = BigPerson()
|
big_person = BigPerson()
|
||||||
|
|
||||||
big_person.height = 1L
|
for value, value_type in enumerate(six.integer_types):
|
||||||
big_person.validate()
|
big_person.height = value_type(value)
|
||||||
|
big_person.validate()
|
||||||
|
|
||||||
big_person.height = 2 ** 500
|
big_person.height = 2 ** 500
|
||||||
big_person.validate()
|
big_person.validate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user