-
-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathtest_construct.py
More file actions
54 lines (34 loc) · 1.25 KB
/
test_construct.py
File metadata and controls
54 lines (34 loc) · 1.25 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
# -*- coding: utf-8 -*-
from datetime import time
from pendulum import Time, timezone
from .. import AbstractTestCase
class ConstructTest(AbstractTestCase):
def test_init(self):
t = Time(12, 34, 56, 123456)
self.assertIsInstanceOfTime(t)
self.assertTime(t, 12, 34, 56, 123456)
def test_init_with_missing_values(self):
t = Time(12, 34, 56)
self.assertTime(t, 12, 34, 56, 0)
t = Time(12, 34)
self.assertTime(t, 12, 34, 0, 0)
t = Time(12)
self.assertTime(t, 12, 0, 0, 0)
def test_instance(self):
native = time(12, 34, 56, 123456)
t = Time.instance(native)
self.assertIsInstanceOfTime(t)
self.assertTime(t, 12, 34, 56, 123456)
def test_instance_aware(self):
tz = timezone('Europe/Paris')
native = time(12, 34, 56, 123456, tzinfo=tz)
self.assertEqual('Europe/Paris', Time.instance(native).tzinfo.name)
def test_now(self):
t = Time.now()
self.assertIsInstanceOfTime(t)
def test_now_microseconds(self):
with Time.test(Time(1, 2, 3, 123456)):
t = Time.now()
self.assertTime(t, 1, 2, 3, 123456)
t = Time.now(False)
self.assertTime(t, 1, 2, 3, 0)