Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f9cc9f8

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

File tree

Expand file treeCollapse file tree

2 files changed

+9
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-3
lines changed

‎tests/test_MySQLdb_times.py

Copy file name to clipboardExpand all lines: tests/test_MySQLdb_times.py
+8-3Lines changed: 8 additions & 3 deletions
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

Copy file name to clipboardExpand all lines: tox.ini
+1Lines changed: 1 addition & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.