Skip to content

Commit f9cc9f8

Browse files
committed
Mock localtime with gmtime for epoch tests
1 parent 1670adf commit f9cc9f8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tests/test_MySQLdb_times.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import mock
12
import unittest
3+
from time import gmtime
24
from datetime import time, date, datetime, timedelta
35

46
from MySQLdb import times
@@ -59,16 +61,19 @@ def test_timedelta_or_none(self):
5961

6062

6163
class TestTicks(unittest.TestCase):
62-
def test_date_from_ticks(self):
64+
@mock.patch('MySQLdb.times.localtime', side_effect=gmtime)
65+
def test_date_from_ticks(self, mock):
6366
assert times.DateFromTicks(0) == date(1970, 1, 1)
6467
assert times.DateFromTicks(1430000000) == date(2015, 4, 25)
6568

66-
def test_time_from_ticks(self):
69+
@mock.patch('MySQLdb.times.localtime', side_effect=gmtime)
70+
def test_time_from_ticks(self, mock):
6771
assert times.TimeFromTicks(0) == time(0, 0, 0)
6872
assert times.TimeFromTicks(1431100000) == time(15, 46, 40)
6973
assert times.TimeFromTicks(1431100000.123) == time(15, 46, 40)
7074

71-
def test_timestamp_from_ticks(self):
75+
@mock.patch('MySQLdb.times.localtime', side_effect=gmtime)
76+
def test_timestamp_from_ticks(self, mock):
7277
assert times.TimestampFromTicks(0) == datetime(1970, 1, 1, 0, 0, 0)
7378
assert times.TimestampFromTicks(1430000000) == datetime(2015, 4, 25, 22, 13, 20)
7479
assert times.TimestampFromTicks(1430000000.123) == datetime(2015, 4, 25, 22, 13, 20)

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ envlist = py26, py27, pypy, py33, py34
55
commands =
66
py.test --cov {envsitepackagesdir}/MySQLdb
77
deps =
8+
mock
89
coverage==3.7.1
910
pytest
1011
pytest-cov

0 commit comments

Comments
 (0)