def test_invalid_date_format_is_caught(self):
        row = {"date": date(0201, 9, 9)}
        with self.assertRaises(Exception) as error:
            encode_if_str(row, "date", True)

        self.assertEqual(error.exception.message,
                         u'0129-09-09 has an invalid date format')

        row = {"date": date(2001, 9, 9)}
        date_str = encode_if_str(row, "date", True)
        self.assertEqual(date_str, '2001-09-09')
Exemple #2
0
    def test_encode_if_str(self):
        row = {"date": date(1899, 9, 9)}
        date_str = encode_if_str(row, "date", True)
        self.assertEqual(date_str, '1899-09-09')

        row = {"date": date(2001, 9, 9)}
        date_str = encode_if_str(row, "date", True)
        self.assertEqual(date_str, '2001-09-09')

        row = {"datetime": datetime(1899, 9, 9)}
        date_str = encode_if_str(row, "datetime", True)
        self.assertEqual(date_str, '1899-09-09T00:00:00')

        row = {"datetime": datetime(2001, 9, 9)}
        date_str = encode_if_str(row, "datetime", True)
        self.assertEqual(date_str, '2001-09-09T00:00:00')
Exemple #3
0
    def test_encode_if_str(self):
        row = {"date": date(1899, 9, 9)}
        date_str = encode_if_str(row, "date", True)
        self.assertEqual(date_str, '1899-09-09')

        row = {"date": date(2001, 9, 9)}
        date_str = encode_if_str(row, "date", True)
        self.assertEqual(date_str, '2001-09-09')

        row = {"datetime": datetime(1899, 9, 9)}
        date_str = encode_if_str(row, "datetime", True)
        self.assertEqual(date_str, '1899-09-09T00:00:00')

        row = {"datetime": datetime(2001, 9, 9)}
        date_str = encode_if_str(row, "datetime", True)
        self.assertEqual(date_str, '2001-09-09T00:00:00')
Exemple #4
0
    def test_encode_if_str(self):
        row = {"date": date(1899, 9, 9)}
        date_str = encode_if_str(row, "date", True)
        self.assertEqual(date_str, '1899-09-09')

        row = {"date": date(2001, 9, 9)}
        date_str = encode_if_str(row, "date", True)
        self.assertEqual(date_str, '2001-09-09')

        row = {"datetime": datetime(1899, 9, 9)}
        date_str = encode_if_str(row, "datetime", True)
        self.assertEqual(date_str, '1899-09-09T00:00:00')

        row = {"datetime": datetime(2001, 9, 9)}
        date_str = encode_if_str(row, "datetime", True)
        self.assertEqual(date_str, '2001-09-09T00:00:00')

        row = {"integer_value": 1}
        integer_value = encode_if_str(row, "integer_value", sav_writer=True)
        self.assertEqual(integer_value, '1')

        integer_value = encode_if_str(row, "integer_value")
        self.assertEqual(integer_value, 1)