Ejemplo n.º 1
0
 def test_registry(self):
     with self.assert_raises(ValueError) as cm:
         SimpleConverterRegistry.register(bool, MyConverter)
     self.assert_true(str(cm.exception).startswith('For %s' % bool))
     with self.assert_raises(ValueError) as cm:
         SimpleConverterRegistry.register(MyNumberType, MyInvalidConverter)
     self.assert_true(str(cm.exception).startswith('Converter class'))
Ejemplo n.º 2
0
 def test_registry(self):
     with self.assert_raises(ValueError) as cm:
         SimpleConverterRegistry.register(bool, MyConverter)
     self.assert_true(str(cm.exception).startswith('For %s' % bool))
     with self.assert_raises(ValueError) as cm:
         SimpleConverterRegistry.register(MyNumberType, MyInvalidConverter)
     self.assert_true(str(cm.exception).startswith('Converter class'))
Ejemplo n.º 3
0
 def test_bool_converter(self):
     self.assert_true(
         SimpleConverterRegistry.convert_from_representation('true', bool)
         is True)
     self.assert_true(
         SimpleConverterRegistry.convert_from_representation(None, bool)
         is None)
     self.assert_equal(
         SimpleConverterRegistry.convert_to_representation(True, bool),
         'true')
Ejemplo n.º 4
0
 def test_datetime_converter(self):
     utc = timezone('UTC')
     ldt = datetime.datetime(2012, 8, 29, 16, 20, 0, tzinfo=utc)
     ldt_rpr = rfc3339(ldt, use_system_timezone=False)
     self.assert_equal(
         SimpleConverterRegistry.convert_from_representation(
             ldt_rpr, datetime.datetime), ldt)
     self.assert_equal(
         SimpleConverterRegistry.convert_to_representation(
             ldt, datetime.datetime), ldt_rpr)
Ejemplo n.º 5
0
 def test_bool_converter(self):
     self.assert_true(
         SimpleConverterRegistry.convert_from_representation('true', bool)
         is True)
     self.assert_true(
         SimpleConverterRegistry.convert_from_representation(None, bool) is
         None)
     self.assert_equal(
         SimpleConverterRegistry.convert_to_representation(True, bool),
         'true')
Ejemplo n.º 6
0
 def test_datetime_converter(self):
     utc = timezone('UTC')
     ldt = datetime.datetime(2012, 8, 29, 16, 20, 0, tzinfo=utc)
     ldt_rpr = rfc3339(ldt, use_system_timezone=False)
     self.assert_equal(
         SimpleConverterRegistry.convert_from_representation(
                                                     ldt_rpr,
                                                     datetime.datetime),
         ldt)
     self.assert_equal(
         SimpleConverterRegistry.convert_to_representation(ldt,
                                                     datetime.datetime),
         ldt_rpr)