def test_format_selection(self):
     "Test format 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'),
             ('test', 'test'),
             (False, ''),
             (None, ''),
             ('', ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
         self.assertEqual(
             format_value(field_with_empty, value), result,
             msg="format_value(%r, %r)" % (field_with_empty, value))
 def test_format_numeric_factor(self):
     "Test format numeric with factor"
     field = {
         'type': 'numeric',
         'factor': '5',
         }
     self.assertEqual(format_value(field, Decimal('0.2')), '1')
 def test_format_float_factor(self):
     "Test format float with factor"
     field = {
         'type': 'float',
         'factor': '100',
         }
     self.assertEqual(format_value(field, 0.42), '42')
 def test_format_integer_factor(self):
     "Test format integer with factor"
     field = {
         'type': 'integer',
         'factor': '2',
         }
     self.assertEqual(format_value(field, 3), '6')
 def test_format_date(self):
     "Test format date"
     field = {
         'type': 'date',
         }
     for value, result in (
             (dt.date(2002, 12, 4), dt.date(2002, 12, 4).strftime('%x')),
             (False, ''),
             (None, ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
 def test_format_boolean(self):
     "Test format boolean"
     field = {
         'type': 'boolean',
         }
     for value, result in (
             (True, 'True'),
             (False, 'False'),
             (None, ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
 def test_format_timedelta(self):
     "Test format timedelta"
     field = {
         'type': 'timedelta',
         }
     for value, result in [
             (dt.timedelta(days=1, hours=2), '"1d 02:00"'),
             (dt.timedelta(), ''),
             (None, ''),
             ('', ''),
             ]:
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
 def test_format_time(self):
     "Test format time"
     field = {
         'type': 'time',
         'format': '"%H:%M:%S"',
         }
     for value, result in (
             (dt.time(12, 30, 0), '"12:30:00"'),
             (False, ''),
             (None, ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
 def test_format_integer(self):
     "Test format integer"
     field = {
         'type': 'integer',
         }
     for value, result in (
             (1, '1'),
             (1.5, '1'),
             (0, '0'),
             (0.0, '0'),
             (False, ''),
             (None, ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
 def test_format_numeric(self):
     "Test format numeric"
     field = {
         'type': 'numeric',
         }
     for value, result in (
             (Decimal(1), '1'),
             (Decimal('1.5'), '1.5'),
             (Decimal('1.50'), '1.5'),
             (Decimal('150.79'), '150.79'),
             (Decimal(0), '0'),
             (Decimal('0.0'), '0'),
             (False, ''),
             (None, ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
Ejemplo n.º 11
0
 def test_format_datetime(self):
     "Test format datetime"
     field = {
         'type': 'datetime',
         'format': '"%H:%M:%S"',
         }
     for value, result in (
             (dt.date(2002, 12, 4), dt.date(2002, 12, 4).strftime('%x')),
             (untimezoned_date(dt.datetime(2002, 12, 4)),
                 dt.date(2002, 12, 4).strftime('%x')),
             (untimezoned_date(dt.datetime(2002, 12, 4, 12, 30)),
                 dt.datetime(2002, 12, 4, 12, 30).strftime('"%x %H:%M:%S"')),
             (False, ''),
             (None, ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))
Ejemplo n.º 12
0
 def test_format_float(self):
     "Test format float"
     field = {
         'type': 'float',
         }
     for value, result in (
             (1, '1'),
             (1.5, '1.5'),
             (1.50, '1.5'),
             (150.79, '150.79'),
             (0, '0'),
             (0.0, '0'),
             (False, ''),
             (None, ''),
             ):
         self.assertEqual(
             format_value(field, value), result,
             msg="format_value(%r, %r)" % (field, value))