mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Refactored duplicated local dt variable to be a class variable.
This commit is contained in:
parent
91f5a0d84b
commit
9215edb560
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user