Example #1
0
 def test_decimal_to_datetime(self):
     expected = 1356093296.12
     dexpected = decimal.Decimal(str(expected))  # Python 2.6 wants str()
     expected_datetime = datetime.datetime.utcfromtimestamp(expected)
     actual_datetime = utils.decimal_to_dt(dexpected)
     # Python 3 have rounding issue on this, so use float
     self.assertAlmostEqual(utils.dt_to_decimal(expected_datetime),
                            utils.dt_to_decimal(actual_datetime),
                            places=5)
Example #2
0
 def test_decimal_to_datetime(self):
     expected = 1356093296.12
     dexpected = decimal.Decimal(str(expected))  # Python 2.6 wants str()
     expected_datetime = datetime.datetime.utcfromtimestamp(expected)
     actual_datetime = utils.decimal_to_dt(dexpected)
     # Python 3 have rounding issue on this, so use float
     self.assertAlmostEqual(utils.dt_to_decimal(expected_datetime),
                            utils.dt_to_decimal(actual_datetime),
                            places=5)
Example #3
0
 def test_datetime_to_decimal(self):
     expected = 1356093296.12
     utc_datetime = datetime.datetime.utcfromtimestamp(expected)
     actual = utils.dt_to_decimal(utc_datetime)
     self.assertAlmostEqual(expected, float(actual), places=5)
Example #4
0
 def process_bind_param(value, dialect):
     if value is None:
         return value
     elif dialect.name == 'mysql':
         return utils.dt_to_decimal(value)
     return value
Example #5
0
 def test_datetime_to_decimal(self):
     expected = 1356093296.12
     utc_datetime = datetime.datetime.utcfromtimestamp(expected)
     actual = utils.dt_to_decimal(utc_datetime)
     self.assertAlmostEqual(expected, float(actual), places=5)
Example #6
0
 def test_process_result_value_datetime_mysql(self):
     dec_value = utils.dt_to_decimal(self._date)
     result = self._type.process_result_value(dec_value,
                                              self._mysql_dialect)
     self.assertEqual(self._date, result)
Example #7
0
 def test_process_bind_param_store_decimal_mysql(self):
     expected = utils.dt_to_decimal(self._date)
     result = self._type.process_bind_param(self._date, self._mysql_dialect)
     self.assertEqual(expected, result)
Example #8
0
 def test_process_result_value_datetime_mysql(self):
     dec_value = utils.dt_to_decimal(self._date)
     result = self._type.process_result_value(dec_value,
                                              self._mysql_dialect)
     self.assertEqual(self._date, result)
Example #9
0
 def test_process_bind_param_store_decimal_mysql(self):
     expected = utils.dt_to_decimal(self._date)
     result = self._type.process_bind_param(self._date, self._mysql_dialect)
     self.assertEqual(expected, result)
Example #10
0
 def process_bind_param(value, dialect):
     if value is None:
         return value
     elif dialect.name == 'mysql':
         return utils.dt_to_decimal(value)
     return value