-
-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathtest_construct.py
More file actions
71 lines (53 loc) · 2.17 KB
/
test_construct.py
File metadata and controls
71 lines (53 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
from datetime import timedelta
from pendulum import Interval
from pendulum.interval import AbsoluteInterval
from .. import AbstractTestCase
class ConstructTest(AbstractTestCase):
def test_defaults(self):
pi = Interval()
self.assertIsInstanceOfInterval(pi)
self.assertInterval(pi, 0, 0, 0, 0, 0)
def test_weeks(self):
pi = Interval(days=365)
self.assertInterval(pi, 52)
pi = Interval(days=13)
self.assertInterval(pi, 1)
def test_days(self):
pi = Interval(days=6)
self.assertInterval(pi, 0, 6, 0, 0, 0)
pi = Interval(days=16)
self.assertInterval(pi, 2, 2, 0, 0, 0)
def test_hours(self):
pi = Interval(seconds=3600 * 3)
self.assertInterval(pi, 0, 0, 3, 0, 0)
def test_minutes(self):
pi = Interval(seconds=60 * 3)
self.assertInterval(pi, 0, 0, 0, 3, 0)
pi = Interval(seconds=60 * 3 + 12)
self.assertInterval(pi, 0, 0, 0, 3, 12)
def test_all(self):
pi = Interval(days=1177, seconds=7284, microseconds=1000000)
self.assertInterval(pi, 168, 1, 2, 1, 25)
self.assertEqual(1177, pi.days)
self.assertEqual(7285, pi.seconds)
def test_instance(self):
pi = Interval.instance(timedelta(days=1177, seconds=7284, microseconds=1000000))
self.assertInterval(pi, 168, 1, 2, 1, 25)
def test_absolute_interval(self):
pi = AbsoluteInterval(days=-1177, seconds=-7284, microseconds=-1000001)
self.assertInterval(pi, 168, 1, 2, 1, 25)
self.assertEqual(1, pi.microseconds)
self.assertTrue(pi.invert)
def test_invert(self):
pi = Interval(days=1177, seconds=7284, microseconds=1000000)
self.assertFalse(pi.invert)
pi = Interval(days=-1177, seconds=-7284, microseconds=-1000000)
self.assertTrue(pi.invert)
def test_as_timedelta(self):
pi = Interval(seconds=3456.123456)
self.assertInterval(pi, 0, 0, 0, 57, 36, 123456)
delta = pi.as_timedelta()
self.assertIsInstance(delta, timedelta)
self.assertEqual(3456.123456, delta.total_seconds())
self.assertEqual(3456, delta.seconds)