Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Fix Pendulum Import Errors #370

Open
wants to merge 3 commits into
base: 0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions orator/connectors/mysql_connector.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# -*- coding: utf-8 -*-

import re
from pendulum import Pendulum, Date
import re, pendulum

try:
import MySQLdb as mysql

# Fix for understanding Pendulum object
import MySQLdb.converters

MySQLdb.converters.conversions[Pendulum] = MySQLdb.converters.DateTime2literal
MySQLdb.converters.conversions[Date] = MySQLdb.converters.Thing2Literal
MySQLdb.converters.conversions[pendulum] = MySQLdb.converters.DateTime2literal
MySQLdb.converters.conversions[pendulum.Date] = MySQLdb.converters.Thing2Literal

from MySQLdb.cursors import DictCursor as cursor_class

Expand Down
6 changes: 3 additions & 3 deletions orator/connectors/sqlite_connector.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-

from pendulum import Pendulum, Date
import pendulum

try:
import sqlite3

from sqlite3 import register_adapter

register_adapter(Pendulum, lambda val: val.isoformat(" "))
register_adapter(Date, lambda val: val.isoformat())
register_adapter(pendulum, lambda val: val.isoformat(" "))
register_adapter(pendulum.Date, lambda val: val.isoformat())
except ImportError:
sqlite3 = None

Expand Down
14 changes: 7 additions & 7 deletions tests/orm/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import hashlib
import time
import datetime
from pendulum import Pendulum
import pendulum
from flexmock import flexmock, flexmock_teardown
from .. import OratorTestCase, mock
from ..utils import MockModel, MockQueryBuilder, MockConnection, MockProcessor
Expand Down Expand Up @@ -348,17 +348,17 @@ def test_timestamps_are_returned_as_objects(self):
{"created_at": "2015-03-24", "updated_at": "2015-03-24"}
)

self.assertIsInstance(model.created_at, Pendulum)
self.assertIsInstance(model.updated_at, Pendulum)
self.assertIsInstance(model.created_at, pendulum)
self.assertIsInstance(model.updated_at, pendulum)

def test_timestamps_are_returned_as_objects_from_timestamps_and_datetime(self):
model = Model()
model.set_raw_attributes(
{"created_at": datetime.datetime.utcnow(), "updated_at": time.time()}
)

self.assertIsInstance(model.created_at, Pendulum)
self.assertIsInstance(model.updated_at, Pendulum)
self.assertIsInstance(model.created_at, pendulum)
self.assertIsInstance(model.updated_at, pendulum)

def test_timestamps_are_returned_as_objects_on_create(self):
model = Model()
Expand All @@ -371,8 +371,8 @@ def test_timestamps_are_returned_as_objects_on_create(self):

instance = model.new_instance(timestamps)

self.assertIsInstance(instance.created_at, Pendulum)
self.assertIsInstance(instance.updated_at, Pendulum)
self.assertIsInstance(instance.created_at, pendulum)
self.assertIsInstance(instance.updated_at, pendulum)

model.reguard()

Expand Down