summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGerhard Weis <gerhard.weis@gmx.com>2012-05-04 20:03:17 +1000
committerGerhard Weis <gerhard.weis@gmx.com>2012-05-04 20:03:17 +1000
commitf050a3d293a5bb9826df4955be7ba56a37333727 (patch)
tree1ded699a0484f7062c820f00ef08d4b3e286da8c /src
parenteae0aef7c6f9bb4804a81b468b83b57f4e5ba87a (diff)
downloadisodate-f050a3d293a5bb9826df4955be7ba56a37333727.tar.gz
make unit tests compatible with pre python 2.7 unit test module
Diffstat (limited to 'src')
-rw-r--r--src/isodate/tests/test_strf.py77
1 files changed, 36 insertions, 41 deletions
diff --git a/src/isodate/tests/test_strf.py b/src/isodate/tests/test_strf.py
index dc10c73..7d9ba4b 100644
--- a/src/isodate/tests/test_strf.py
+++ b/src/isodate/tests/test_strf.py
@@ -35,26 +35,6 @@ from isodate import LOCAL
from isodate import DT_EXT_COMPLETE
from isodate import tzinfo
-# dict to store orig values
-ORIG = {}
-
-
-# local time zone mock function
-def localtime_mock(secs):
- """
- mock time.localtime so that it always returns a time_struct with tm_idst=1
- """
- tt = ORIG['localtime'](secs)
- # befor 2000 everything is dst, after 2000 no dst.
- if tt.tm_year < 2000:
- dst = 1
- else:
- dst = 0
- tt = (tt.tm_year, tt.tm_mon, tt.tm_mday,
- tt.tm_hour, tt.tm_min, tt.tm_sec,
- tt.tm_wday, tt.tm_yday, dst)
- return time.struct_time(tt)
-
TEST_CASES = ((datetime(2012, 12, 25, 13, 30, 0, 0, LOCAL), DT_EXT_COMPLETE,
"2012-12-25T13:30:00+10:00"),
@@ -77,6 +57,42 @@ def create_testcase(dt, format, expectation):
A test case template to test ISO date formatting.
'''
+ # local time zone mock function
+ def localtime_mock(self, secs):
+ """
+ mock time.localtime so that it always returns a time_struct with tm_idst=1
+ """
+ tt = self.ORIG['localtime'](secs)
+ # befor 2000 everything is dst, after 2000 no dst.
+ if tt.tm_year < 2000:
+ dst = 1
+ else:
+ dst = 0
+ tt = (tt.tm_year, tt.tm_mon, tt.tm_mday,
+ tt.tm_hour, tt.tm_min, tt.tm_sec,
+ tt.tm_wday, tt.tm_yday, dst)
+ return time.struct_time(tt)
+
+ def setUp(self):
+ self.ORIG = {}
+ self.ORIG['STDOFFSET'] = tzinfo.STDOFFSET
+ self.ORIG['DSTOFFSET'] = tzinfo.DSTOFFSET
+ self.ORIG['DSTDIFF'] = tzinfo.DSTDIFF
+ self.ORIG['localtime'] = time.localtime
+ # ovveride all saved values with fixtures.
+ # calculate LOCAL TZ offset, so that this test runs in every time zone
+ tzinfo.STDOFFSET = timedelta(seconds=36000) # assume we are in +10:00
+ tzinfo.DSTOFFSET = timedelta(seconds=39600) # assume DST = +11:00
+ tzinfo.DSTDIFF = tzinfo.DSTOFFSET - tzinfo.STDOFFSET
+ time.localtime = self.localtime_mock
+
+ def tearDown(self):
+ # restore test fixtures
+ tzinfo.STDOFFSET = self.ORIG['STDOFFSET']
+ tzinfo.DSTOFFSET = self.ORIG['DSTOFFSET']
+ tzinfo.DSTDIFF = self.ORIG['DSTDIFF']
+ time.localtime = self.ORIG['localtime']
+
def test_format(self):
'''
Take date object and create ISO string from it.
@@ -92,27 +108,6 @@ def create_testcase(dt, format, expectation):
return unittest.TestLoader().loadTestsFromTestCase(TestDate)
-def setUpModule():
- ORIG['STDOFFSET'] = tzinfo.STDOFFSET
- ORIG['DSTOFFSET'] = tzinfo.DSTOFFSET
- ORIG['DSTDIFF'] = tzinfo.DSTDIFF
- ORIG['localtime'] = time.localtime
- # ovveride all saved values with fixtures.
- # calculate LOCAL TZ offset, so that this test runs in every time zone
- tzinfo.STDOFFSET = timedelta(seconds=36000) # assume we are in +10:00
- tzinfo.DSTOFFSET = timedelta(seconds=39600) # assume DST = +11:00
- tzinfo.DSTDIFF = tzinfo.DSTOFFSET - tzinfo.STDOFFSET
- time.localtime = localtime_mock
-
-
-def tearDownModule():
- # restore test fixtures
- tzinfo.STDOFFSET = ORIG['STDOFFSET']
- tzinfo.DSTOFFSET = ORIG['DSTOFFSET']
- tzinfo.DSTDIFF = ORIG['DSTDIFF']
- time.localtime = ORIG['localtime']
-
-
def test_suite():
'''
Construct a TestSuite instance for all test cases.