-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
71 lines (57 loc) · 2.64 KB
/
tests.py
File metadata and controls
71 lines (57 loc) · 2.64 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
from datetime import datetime, date, time
import unittest
import pytz
from djavedt import (
now, PastMonth, past_x_months, years_old, str_to_tz_dt, time_str_to_time)
class NowTests(unittest.TestCase):
def test_now(self):
def use_django_now():
# Early in the morning UTC time January 2nd.
return pytz.timezone('UTC').localize(datetime(2020, 1, 2, 1, 0, 0, 0))
new_york_tz = pytz.timezone('America/New_York')
self.assertEqual(
# Late in the evening NY time January 1st
new_york_tz.localize(datetime(2020, 1, 1, 20, 0, 0, 0)),
now(use_django_now=use_django_now, tz_str='America/New_York'))
class Past12MonthsTests(unittest.TestCase):
def test_past_x_months(self):
expected = [
PastMonth(year=2019, month=8, months_ago=0),
PastMonth(year=2019, month=7, months_ago=1),
PastMonth(year=2019, month=6, months_ago=2),
PastMonth(year=2019, month=5, months_ago=3),
PastMonth(year=2019, month=4, months_ago=4),
PastMonth(year=2019, month=3, months_ago=5),
PastMonth(year=2019, month=2, months_ago=6),
PastMonth(year=2019, month=1, months_ago=7),
PastMonth(year=2018, month=12, months_ago=8),
PastMonth(year=2018, month=11, months_ago=9),
PastMonth(year=2018, month=10, months_ago=10),
PastMonth(year=2018, month=9, months_ago=11)]
got = list(past_x_months(12, nnow=str_to_tz_dt('2019-08-28 14:46')))
self.assertEqual(expected, got)
class YearsOldTests(unittest.TestCase):
def test_years_old(self):
self.assertEqual(None, years_old(None))
self.assertEqual(0, years_old(
date(2018, 1, 1), nnow=str_to_tz_dt('2018-01-01')))
self.assertEqual(0, years_old(
date(2018, 1, 1), nnow=str_to_tz_dt('2018-01-02')))
self.assertEqual(0, years_old(
date(2018, 12, 2), nnow=str_to_tz_dt('2019-12-01')))
self.assertEqual(1, years_old(
date(2018, 12, 2), nnow=str_to_tz_dt('2019-12-02')))
self.assertEqual(1, years_old(
date(2018, 12, 2), nnow=str_to_tz_dt('2020-12-01')))
class TimeStrToTimeTests(unittest.TestCase):
def test_time_str_to_time(self):
self.assertEqual(time(0, 0), time_str_to_time('00:00'))
self.assertEqual(time(0, 0), time_str_to_time('12:00 AM'))
self.assertEqual(time(11, 59), time_str_to_time('11:59'))
self.assertEqual(time(11, 59), time_str_to_time('11:59 AM'))
self.assertEqual(time(12, 0), time_str_to_time('12:00'))
self.assertEqual(time(12, 0), time_str_to_time('12:00 PM'))
self.assertEqual(time(23, 59), time_str_to_time('11:59 PM'))
self.assertEqual(None, time_str_to_time(None))
if __name__ == '__main__':
unittest.main()