def test_convert_selection(self):
     "Test convert selection"
     field = {
         'type': 'selection',
         'selection': [
             ('male', 'Male'),
             ('female', 'Female'),
             ],
         }
     field_with_empty = field.copy()
     field_with_empty['selection'] = (field_with_empty['selection']
         + [('', '')])
     for value, result in (
             ('Male', 'male'),
             ('male', 'male'),
             ('test', 'test'),
             (None, None),
             ('', ''),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
         self.assertEqual(
             convert_value(field_with_empty, value), result,
             msg="convert_value(%r, %r)" % (field_with_empty, value))
 def test_convert_numeric_factor(self):
     "Test convert numeric with factor"
     field = {
         'type': 'numeric',
         'factor': '5',
         }
     self.assertEqual(convert_value(field, '1'), Decimal('0.2'))
 def test_convert_integer_factor(self):
     "Test convert integer with factor"
     field = {
         'type': 'integer',
         'factor': '2',
         }
     self.assertEqual(convert_value(field, '6'), 3)
 def test_convert_float_factor(self):
     "Test convert float with factor"
     field = {
         'type': 'float',
         'factor': '100',
         }
     self.assertEqual(convert_value(field, '42'), 0.42)
 def test_convert_timedelta(self):
     "Test convert timedelta"
     field = {
         'type': 'timedelta',
         }
     for value, result in [
             ('1d 2:00', dt.timedelta(days=1, hours=2)),
             ('foo', dt.timedelta()),
             (None, None),
             ]:
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
 def test_convert_date(self):
     "Test convert date"
     field = {
         'type': 'date',
         }
     for value, result in (
             ('12/04/2002', dt.date(2002, 12, 4)),
             ('test', None),
             (None, None),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
 def test_convert_time(self):
     "Test convert time"
     field = {
         'type': 'time',
         'format': '"%H:%M:%S"',
         }
     for value, result in (
             ('12:30:00', dt.time(12, 30, 0)),
             ('test', None),
             (None, None),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
 def test_convert_float(self):
     "Test convert float"
     field = {
         'type': 'float',
         }
     for value, result in (
             ('1', 1.0),
             ('1.5', 1.5),
             ('', None),
             ('test', None),
             (None, None),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
 def test_convert_numeric(self):
     "Test convert numeric"
     field = {
         'type': 'numeric',
         }
     for value, result in (
             ('1', Decimal(1)),
             ('1.5', Decimal('1.5')),
             ('', None),
             ('test', None),
             (None, None),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
 def test_convert_integer(self):
     "Test convert integer"
     field = {
         'type': 'integer',
         }
     for value, result in (
             ('1', 1),
             ('1.5', 1),
             ('', None),
             ('test', None),
             (None, None),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
 def test_convert_boolean(self):
     "Test convert boolean"
     field = {
         'type': 'boolean',
         }
     for value, result in (
             ('Y', True),
             ('yes', True),
             ('t', True),
             ('1', True),
             ('N', False),
             ('False', False),
             ('no', False),
             ('0', False),
             (None, None),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))
 def test_convert_datetime(self):
     "Test convert datetime"
     field = {
         'type': 'datetime',
         'format': '"%H:%M:%S"',
         }
     for value, result in (
             ('12/04/2002', untimezoned_date(dt.datetime(2002, 12, 4))),
             ('12/04/2002 12:30:00', untimezoned_date(
                     dt.datetime(2002, 12, 4, 12, 30))),
             ('02/03/04', untimezoned_date(dt.datetime(2004, 2, 3))),
             ('02/03/04 05:06:07', untimezoned_date(
                     dt.datetime(2004, 2, 3, 5, 6, 7))),
             ('test', None),
             (None, None),
             ):
         self.assertEqual(
             convert_value(field, value), result,
             msg="convert_value(%r, %r)" % (field, value))