def test_to_timestamps_epoch(self): self.assertEqual( utils.to_datetime("1425652440"), datetime.datetime(2015, 3, 6, 14, 34, tzinfo=iso8601.iso8601.UTC)) self.assertEqual( utils.to_datetime("1425652440.4"), datetime.datetime(2015, 3, 6, 14, 34, 0, 400000, tzinfo=iso8601.iso8601.UTC)) self.assertEqual( utils.to_datetime(1425652440), datetime.datetime(2015, 3, 6, 14, 34, tzinfo=iso8601.iso8601.UTC)) self.assertEqual( utils.to_datetime(utils.to_timestamp(1425652440.4)), datetime.datetime(2015, 3, 6, 14, 34, 0, 400000, tzinfo=iso8601.iso8601.UTC))
def test_to_timestamps_relative(self): with mock.patch('gnocchi.utils.utcnow') as utcnow: utcnow.return_value = datetime.datetime( 2015, 3, 6, 14, 34, tzinfo=iso8601.iso8601.UTC) self.assertEqual( utils.to_datetime("-10 minutes"), datetime.datetime(2015, 3, 6, 14, 24, tzinfo=iso8601.iso8601.UTC))
def schema_ext(value): try: return utils.to_datetime(value) except ValueError as e: raise voluptuous.Invalid(e)