Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions tests/time_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


class InitTimeTestCase(TestCase):

def test_direct(self):
d = Time(2014, 4, 18, 17, 50, 21)

Expand Down Expand Up @@ -100,7 +101,8 @@ def test_str_tz(self):
assert_equal(t.second, 21)

def test_str_specify_tz(self):
t = Time.from_str("2014-04-18T17:50:21.036391", tz='America/Los_Angeles')
t = Time.from_str(
"2014-04-18T17:50:21.036391", tz='America/Los_Angeles')

assert_equal(t.year, 2014)
assert_equal(t.month, 4)
Expand All @@ -111,6 +113,7 @@ def test_str_specify_tz(self):


class ConvertTimeTestCase(TestCase):

@setup
def create_time(self):
self.t = Time(2014, 4, 18, 17, 50, 21, 36391)
Expand All @@ -119,14 +122,16 @@ def test_str(self):
assert_equal(self.t.to_str(), "2014-04-18T17:50:21.036391+00:00")

def test_str_tz(self):
assert_equal(self.t.to_str(tz='America/Los_Angeles'), "2014-04-18T10:50:21.036391-07:00")
assert_equal(
self.t.to_str(tz='America/Los_Angeles'), "2014-04-18T10:50:21.036391-07:00")

def test_str_local(self):
# We don't really konw
assert self.t.to_str(local=True)

def test_str_format(self):
assert_equal(self.t.to_str(format="%m/%d/%Y %H:%M"), "04/18/2014 17:50")
assert_equal(
self.t.to_str(format="%m/%d/%Y %H:%M"), "04/18/2014 17:50")

def test_timestamp(self):
assert_equal(self.t.to_timestamp(), 1397872221.036391)
Expand Down Expand Up @@ -168,6 +173,7 @@ def test_human(self):


class ArithmeticTimeTest(TestCase):

def test_time_add(self):
t1 = Time(2014, 4, 18, 17, 50, 21)
ti = TimeInterval(2.22)
Expand All @@ -188,6 +194,7 @@ def test_time_sub(self):


class InitTimeIntervalTest(TestCase):

def test_seconds(self):
i = TimeInterval(21)

Expand Down Expand Up @@ -222,6 +229,7 @@ def test_microsecond_overflow(self):


class ConvertTimeIntervalTest(TestCase):

def test_int(self):
i = TimeInterval(4)
assert_equal(int(i), 4)
Expand All @@ -240,6 +248,7 @@ def test_str(self):


class ArithmeticTimeIntervalTest(TestCase):

def test_add(self):
i1 = TimeInterval(1)
i2 = TimeInterval(1)
Expand Down Expand Up @@ -328,6 +337,7 @@ def test_cmp(self):


class TimeSpanTest(TestCase):

def test_iter(self):
t1 = Time.now()
t2 = Time.now() + 30
Expand All @@ -350,9 +360,10 @@ def test_get(self):


class TimeIteratorTest(TestCase):

def test(self):
start_t = Time.now()
end_t = start_t + 5*60
end_t = start_t + 5 * 60

times = list(TimeIterator(TimeSpan(start_t, end_t), TimeInterval(60)))
assert_equal(len(times), 6)
Expand All @@ -361,11 +372,13 @@ def test(self):


class TimeSpanIteratorTest(TestCase):

def test(self):
start_t = Time.now()
end_t = start_t + 5*60
end_t = start_t + 5 * 60

times = list(TimeSpanIterator(TimeSpan(start_t, end_t), TimeInterval(60)))
times = list(
TimeSpanIterator(TimeSpan(start_t, end_t), TimeInterval(60)))
assert_equal(len(times), 5)
assert_equal(times[0].start, start_t)
assert_equal(times[-1].end, end_t)