Refactored duplicated local dt variable to be a class variable.

This commit is contained in:
Donne Martin 2015-01-24 08:14:10 -05:00
parent 91f5a0d84b
commit 9215edb560

View File

@ -7,6 +7,8 @@ class TestDateUtil():
@classmethod
def setup_class(cls):
"""This method is run once for each class before any tests are run"""
cls.dt = datetime(cls.year, cls.month, cls.day,
cls.hour, cls.minute, cls.second)
@classmethod
def teardown_class(cls):
@ -24,22 +26,19 @@ class TestDateUtil():
hour = 7
minute = 28
second = 15
dt = None
def test_datetime(self):
dt = datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second)
assert_equal(dt.day, self.day)
assert_equal(dt.minute, self.minute)
assert_equal(dt.date(), date(self.year, self.month, self.day))
assert_equal(dt.time(), time(self.hour, self.minute, self.second))
assert_equal(self.dt.day, self.day)
assert_equal(self.dt.minute, self.minute)
assert_equal(self.dt.date(), date(self.year, self.month, self.day))
assert_equal(self.dt.time(), time(self.hour, self.minute, self.second))
def test_strftime(self):
"""Format the datetime string"""
dt = datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second)
assert_equal(dt.strftime('%m/%d/%Y %H:%M'), '01/20/2015 07:28')
assert_equal(self.dt.strftime('%m/%d/%Y %H:%M'), '01/20/2015 07:28')
def test_strptime(self):
"""Convert/parse string into datetime objects"""
dt = datetime(self.year, self.month, self.day)
assert_equal(datetime.strptime('20150120', '%Y%m%d'), dt)
d = datetime(self.year, self.month, self.day)
assert_equal(datetime.strptime('20150120', '%Y%m%d'), d)