Skip to content

Commit ef05715

Browse files
committed
fixing bug I introduce in convert_time, added coverage tests for change sets recently created
1 parent a572a72 commit ef05715

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pymysql/converters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,14 @@ def convert_time(connection, field, obj):
183183
to be treated as time-of-day and not a time offset, then you can
184184
use set this function as the converter for FIELD_TYPE.TIME.
185185
"""
186-
from math import modf
187186
try:
188187
microseconds = 0
189188
if "." in obj:
190189
(obj, tail) = obj.split('.')
191190
microseconds = int(tail)
192191
hours, minutes, seconds = obj.split(':')
193-
return datetime.time(hour=int(hour), minute=int(minute),
194-
second=int(second), microsecond=microseconds)
192+
return datetime.time(hour=int(hours), minute=int(minutes),
193+
second=int(seconds), microsecond=microseconds)
195194
except ValueError:
196195
return None
197196

pymysql/tests/test_basic.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ def test_big_blob(self):
9292
self.assertEqual(data.encode(conn.charset), c.fetchone()[0])
9393
finally:
9494
c.execute("drop table test_big_blob")
95+
96+
def test_untyped(self):
97+
""" test conversion of null, empty string """
98+
conn = self.connections[0]
99+
c = conn.cursor()
100+
c.execute("select null,''")
101+
self.assertEqual((None,u''), c.fetchone())
102+
c.execute("select '',null")
103+
self.assertEqual((u'',None), c.fetchone())
104+
105+
def test_datetime(self):
106+
""" test conversion of null, empty string """
107+
conn = self.connections[0]
108+
c = conn.cursor()
109+
c.execute("select time('12:30'), time('23:12:59'), time('23:12:59.05100')")
110+
self.assertEqual((datetime.timedelta(0, 45000),
111+
datetime.timedelta(0, 83579),
112+
datetime.timedelta(0, 83579, 51000)),
113+
c.fetchone())
114+
95115

96116
class TestCursor(base.PyMySQLTestCase):
97117
# this test case does not work quite right yet, however,

0 commit comments

Comments
 (0)