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'))
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')
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)
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)