Fix failed tests. API for utcoffset changed and strings are more robust.

In Python 2.7 the API for time.utcoffset() changed.

We do more automatic conversions of strings so need to loosen the tests
a bit.
This commit is contained in:
Rob Crittenden
2011-01-24 10:43:59 -05:00
parent 6e7729726f
commit 96469fbc88
2 changed files with 8 additions and 7 deletions

View File

@@ -275,7 +275,7 @@ class TestTimeParser(unittest.TestCase):
time = ipautil.parse_generalized_time(timestr) time = ipautil.parse_generalized_time(timestr)
self.assertEqual(0, time.tzinfo.houroffset) self.assertEqual(0, time.tzinfo.houroffset)
self.assertEqual(0, time.tzinfo.minoffset) self.assertEqual(0, time.tzinfo.minoffset)
offset = time.tzinfo.utcoffset() offset = time.tzinfo.utcoffset(time.tzinfo.dst())
self.assertEqual(0, offset.seconds) self.assertEqual(0, offset.seconds)
timestr = "20051213141205+0500" timestr = "20051213141205+0500"
@@ -283,7 +283,7 @@ class TestTimeParser(unittest.TestCase):
time = ipautil.parse_generalized_time(timestr) time = ipautil.parse_generalized_time(timestr)
self.assertEqual(5, time.tzinfo.houroffset) self.assertEqual(5, time.tzinfo.houroffset)
self.assertEqual(0, time.tzinfo.minoffset) self.assertEqual(0, time.tzinfo.minoffset)
offset = time.tzinfo.utcoffset() offset = time.tzinfo.utcoffset(time.tzinfo.dst())
self.assertEqual(5 * 60 * 60, offset.seconds) self.assertEqual(5 * 60 * 60, offset.seconds)
timestr = "20051213141205-0500" timestr = "20051213141205-0500"
@@ -293,7 +293,7 @@ class TestTimeParser(unittest.TestCase):
self.assertEqual(0, time.tzinfo.minoffset) self.assertEqual(0, time.tzinfo.minoffset)
# NOTE - the offset is always positive - it's minutes # NOTE - the offset is always positive - it's minutes
# _east_ of UTC # _east_ of UTC
offset = time.tzinfo.utcoffset() offset = time.tzinfo.utcoffset(time.tzinfo.dst())
self.assertEqual((24 - 5) * 60 * 60, offset.seconds) self.assertEqual((24 - 5) * 60 * 60, offset.seconds)
timestr = "20051213141205-0930" timestr = "20051213141205-0930"
@@ -301,7 +301,7 @@ class TestTimeParser(unittest.TestCase):
time = ipautil.parse_generalized_time(timestr) time = ipautil.parse_generalized_time(timestr)
self.assertEqual(-9, time.tzinfo.houroffset) self.assertEqual(-9, time.tzinfo.houroffset)
self.assertEqual(-30, time.tzinfo.minoffset) self.assertEqual(-30, time.tzinfo.minoffset)
offset = time.tzinfo.utcoffset() offset = time.tzinfo.utcoffset(time.tzinfo.dst())
self.assertEqual(((24 - 9) * 60 * 60) - (30 * 60), offset.seconds) self.assertEqual(((24 - 9) * 60 * 60) - (30 * 60), offset.seconds)

View File

@@ -33,6 +33,7 @@ from ipalib import parameters, request, errors, config
from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR, NULLS from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR, NULLS
from ipalib.errors import ValidationError from ipalib.errors import ValidationError
from ipalib import _ from ipalib import _
from xmlrpclib import MAXINT
class test_DefaultFrom(ClassChecker): class test_DefaultFrom(ClassChecker):
""" """
@@ -921,7 +922,7 @@ class test_Str(ClassChecker):
mthd = o._convert_scalar mthd = o._convert_scalar
for value in (u'Hello', 42, 1.2, unicode_str): for value in (u'Hello', 42, 1.2, unicode_str):
assert mthd(value) == unicode(value) assert mthd(value) == unicode(value)
bad = [True, 'Hello', dict(one=1), utf8_bytes] bad = [True, dict(one=1)]
for value in bad: for value in bad:
e = raises(errors.ConversionError, mthd, value) e = raises(errors.ConversionError, mthd, value)
assert e.name == 'my_str' assert e.name == 'my_str'
@@ -1164,7 +1165,7 @@ class test_Int(ClassChecker):
assert o.type is int assert o.type is int
assert isinstance(o, parameters.Int) assert isinstance(o, parameters.Int)
assert o.minvalue is None assert o.minvalue is None
assert o.maxvalue is None assert o.maxvalue == int(MAXINT)
# Test when min > max: # Test when min > max:
e = raises(ValueError, self.cls, 'my_number', minvalue=22, maxvalue=15) e = raises(ValueError, self.cls, 'my_number', minvalue=22, maxvalue=15)
@@ -1233,7 +1234,7 @@ class test_Int(ClassChecker):
""" """
o = self.cls('my_number') o = self.cls('my_number')
# Assure invalid inputs raise error # Assure invalid inputs raise error
for bad in ['hello', u'hello', True, None, '10', u'', u'.']: for bad in ['hello', u'hello', True, None, u'', u'.']:
e = raises(errors.ConversionError, o._convert_scalar, bad) e = raises(errors.ConversionError, o._convert_scalar, bad)
assert e.name == 'my_number' assert e.name == 'my_number'
assert e.index is None assert e.index is None