-
-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathtest_parser.py
More file actions
67 lines (41 loc) · 1.72 KB
/
test_parser.py
File metadata and controls
67 lines (41 loc) · 1.72 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
# -*- coding: utf-8 -*-
import pendulum
from .. import AbstractTestCase
class ParserTestCase(AbstractTestCase):
def test_parse(self):
text = '2016-10-16T12:34:56.123456+01:30'
dt = pendulum.parse(text)
self.assertIsInstanceOfPendulum(dt)
self.assertPendulum(dt, 2016, 10, 16, 12, 34, 56, 123456)
self.assertEqual(5400, dt.offset)
text = '2016-10-16'
dt = pendulum.parse(text)
self.assertIsInstanceOfPendulum(dt)
self.assertPendulum(dt, 2016, 10, 16, 0, 0, 0, 0)
self.assertEqual(0, dt.offset)
with self.wrap_with_test_now(pendulum.create(2015, 11, 12)):
text = '12:34:56.123456'
dt = pendulum.parse(text)
self.assertIsInstanceOfPendulum(dt)
self.assertPendulum(dt, 2015, 11, 12, 12, 34, 56, 123456)
self.assertEqual(0, dt.offset)
def test_parse_strict(self):
text = '2016-10-16T12:34:56.123456+01:30'
dt = pendulum.parse(text, strict=True)
self.assertIsInstanceOfPendulum(dt)
self.assertPendulum(dt, 2016, 10, 16, 12, 34, 56, 123456)
self.assertEqual(5400, dt.offset)
text = '2016-10-16'
dt = pendulum.parse(text, strict=True)
self.assertIsInstanceOfDate(dt)
self.assertDate(dt, 2016, 10, 16)
text = '12:34:56.123456'
dt = pendulum.parse(text, strict=True)
self.assertIsInstanceOfTime(dt)
self.assertTime(dt, 12, 34, 56, 123456)
def test_parse_now(self):
dt = pendulum.parse('now')
assert dt.timezone_name == 'America/Toronto'
mock_now = pendulum.yesterday()
with pendulum.test(mock_now):
assert pendulum.parse('now') == mock_now