コード例 #1
0
ファイル: test_fieldtype.py プロジェクト: zz38/mETL
    def test_field_type_convert_to_datetime( self ):

        fs = DateTimeFieldType()

        with self.assertRaises( FieldTypeError ):
            fs.getValue( BooleanFieldType().getValue( True ) )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( FloatFieldType().getValue( 4.32112 ) )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( IntegerFieldType().getValue( 5 ) )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( StringFieldType().getValue('test') )

        with self.assertRaises( FieldTypeError ):
            fs.getValue( TextFieldType().getValue('test') )

        self.assertEqual( fs.getValue( DateFieldType().getValue('2013-04-04 16:06:58.929515') ), datetime.datetime( 2013, 4, 4 ) )
        self.assertEqual( fs.getValue( DateTimeFieldType().getValue( datetime.datetime( 2013, 4, 4, 16, 06, 58, 929515 ) ) ), datetime.datetime( 2013, 4, 4, 16, 06, 58, 929515 ) )
        self.assertEqual( fs.getValue( StringFieldType().getValue('2013-04-04 16:06:58.929515') ), datetime.datetime( 2013, 4, 4, 16, 06, 58, 929515 ) )
        self.assertEqual( fs.getValue( TextFieldType().getValue('2013-04-04 16:06:58.929515') ), datetime.datetime( 2013, 4, 4, 16, 06, 58, 929515 ) )
        self.assertIsNone( fs.getValue( None ) )
コード例 #2
0
ファイル: test_fieldtype.py プロジェクト: zz38/mETL
    def test_datetime_field_type( self ):

        ft = DateTimeFieldType()

        current_timestamp = datetime.datetime.now()

        with self.assertRaises( FieldTypeError ):
            ft.getValue( 'invalid' )

        with self.assertRaises( FieldTypeError ):
            ft.getValue( 321312312 )

        with self.assertRaises( FieldTypeError ):
            ft.getValue( '2013-02-31 11:32:33' )

        self.assertEqual( ft.getValue('2013-02-03 11:32:33'), datetime.datetime( 2013, 2, 3, 11, 32, 33 ) )
        self.assertEqual( ft.getValue('2013.02.03 11:32:33'), datetime.datetime( 2013, 2, 3, 11, 32, 33 ) )
        self.assertEqual( ft.getValue('2013/02/03 11:32:33'), datetime.datetime( 2013, 2, 3, 11, 32, 33 ) )
        self.assertEqual( ft.getValue('02/03/2013 11:32:33'), datetime.datetime( 2013, 2, 3, 11, 32, 33 ) )
        self.assertEqual( ft.getValue( current_timestamp ), current_timestamp )
        self.assertEqual( ft.getValue('2013-04-04 16:06:58.929515'), datetime.datetime( 2013, 4, 4, 16, 06, 58, 929515 ) )
        self.assertIsNone( ft.getValue( None ) )