/
test_timestamps.py
131 lines (96 loc) · 4.43 KB
/
test_timestamps.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from datetime import datetime
import unittest
import pytz
from fbchat_archive_parser.time import (parse_timestamp,
UnexpectedTimeFormatError,
AmbiguousTimeZoneError)
class TestTimestamps(unittest.TestCase):
def setUp(self):
self.expected_datetime = datetime(2016, 12, 4, 20, 54).replace(tzinfo=pytz.UTC)
def run_timestamp_test(self, timestamp_raw):
timestamp = parse_timestamp(timestamp_raw, use_utc=True, hints={})
self.assertEqual(self.expected_datetime, timestamp)
def test_english_us_12(self):
timestamp_raw = "Sunday, December 4, 2016 at 1:54pm PDT"
self.run_timestamp_test(timestamp_raw)
def test_english_us_24(self):
timestamp_raw = "Sunday, December 4, 2016 at 13:54 PDT"
self.run_timestamp_test(timestamp_raw)
def test_english_uk_24(self):
timestamp_raw = "Sunday, 4 December 2016 at 13:54 PDT"
self.run_timestamp_test(timestamp_raw)
def test_french_france(self):
timestamp_raw = "dimanche 4 décembre 2016, 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_german(self):
timestamp_raw = "Sonntag, 4. Dezember 2016 um 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_norwegian_bokmal(self):
timestamp_raw = "4. desember 2016 kl. 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_spanish_gernal(self):
timestamp_raw = "domingo, 4 de diciembre de 2016 a las 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_italian(self):
timestamp_raw = "Domenica 4 dicembre 2016 alle ore 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_hungarian(self):
timestamp_raw = "2016. december 4., 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_swedish(self):
timestamp_raw = "den 4 december 2016 kl. 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_dutch(self):
timestamp_raw = "zondag 4 december 2016 om 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_danish(self):
timestamp_raw = "4. december 2016 kl. 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_romanian(self):
timestamp_raw = "4 decembrie 2016 la 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_slovenian(self):
timestamp_raw = "4. december 2016 ob 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_czech(self):
timestamp_raw = "4. prosinec 2016 v 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_slovak(self):
timestamp_raw = "4. december 2016, 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_portuguese_brazil(self):
timestamp_raw = "4 de dezembro de 2016 às 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_portuguese_portugal(self):
timestamp_raw = "Domingo, 4 de Dezembro de 2016 às 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_polish(self):
timestamp_raw = "4 grudzień 2016 o 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_croatian(self):
timestamp_raw = "4. prosinca 2016 u 13:54 PDT UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_serbian_cyrillic(self):
timestamp_raw = "4. децембар 2016. у 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_bad_timestamp(self):
timestamp_raw = "not a real timestamp"
with self.assertRaises(UnexpectedTimeFormatError):
self.run_timestamp_test(timestamp_raw)
def test_ambiguous_timestamp(self):
timestamp_raw = "Sunday, December 4, 2016 at 1:54pm CDT"
with self.assertRaises(AmbiguousTimeZoneError):
self.run_timestamp_test(timestamp_raw)
def test_russian(self):
timestamp_raw = "4 декабря 2016 г. в 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_lithuanian(self):
timestamp_raw = "2016 m. gruodis 4 d., 13:54 UTC-07"
self.run_timestamp_test(timestamp_raw)
def test_leet_speak(self):
timestamp_raw = "5uNd4Y, d3c3mb3r 4, 2016 @ 1:54pm PDT"
self.run_timestamp_test(timestamp_raw)
if __name__ == '__main__':
unittest.main()