-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_talk_generator.py
137 lines (119 loc) · 6.25 KB
/
test_talk_generator.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
132
133
134
135
136
137
from extract import extract_talks, TRANSLATION_RE, extract_spacetime_coordinates
from hamcrest import assert_that, equal_to, contains_exactly, empty
from datetime import timedelta, time
import re
def test_translation_re():
result = re.match(TRANSLATION_RE, '')
assert_that(result, equal_to(None))
result = re.match(TRANSLATION_RE, '→ ')
assert_that(result, equal_to(None))
result = re.match(TRANSLATION_RE, '→ f: blah')
assert_that(result, equal_to(None))
result = re.match(TRANSLATION_RE, '→ french: blah')
assert_that(result, equal_to(None))
result = re.match(TRANSLATION_RE, '→ fr: blah')
assert_that(result, not equal_to(None))
assert_that(result.group('lang'), equal_to('fr'))
result = re.match(TRANSLATION_RE, '→ en: blah')
assert_that(result, not equal_to(None))
assert_that(result.group('lang'), equal_to('en'))
result = re.match(TRANSLATION_RE, '→ ru: blah')
assert_that(result, not equal_to(None))
assert_that(result.group('lang'), equal_to('ru'))
def test_talk_moved():
test_content = ['### #1 ',
'**MOVED TO 16:00**',
'']
talks = list(extract_talks(test_content, "none"))
assert_that(talks, empty())
def test_talk_no_translation():
test_content = ['### #1 ',
'[de] **10:45** +00:15, [r3s - Monheim/Rhein](https://meet.ffmuc.net/rc3r3sc3lingolowlatency) ',
'**R3S Opening** (Lightning Talk) ',
'heyhej ',
'Fahrplan: https://pretalx.c3voc.de/rc3-2021-r3s/talk/QED93K/ ',
'Slides (if available): https://speakers.c3lingo.org/talks/ea266d48-e185-5dbe-90dd-801a8fbe6ecc/ ',
'']
talks = list(extract_talks(test_content, "none"))
assert_that(len(talks), equal_to(1))
talk = talks[0]
assert_that(talk.title, equal_to('R3S Opening'))
assert_that(talk.speaker, equal_to('heyhej'))
assert_that(talk.fahrplan_url, equal_to('https://pretalx.c3voc.de/rc3-2021-r3s/talk/QED93K/'))
assert_that(talk.date, equal_to(0))
assert_that(talk.time, equal_to(time.fromisoformat('10:45')))
assert_that(talk.place, equal_to('r3s - Monheim/Rhein'))
def test_talk_with_day():
test_content = ['# Translations for rc3-2021 · Day 1',
'### #1 ',
'[de] **10:45** +00:15, [r3s - Monheim/Rhein](https://meet.ffmuc.net/rc3r3sc3lingolowlatency) ',
'**R3S Opening** (Lightning Talk) ',
'heyhej ',
'Fahrplan: https://pretalx.c3voc.de/rc3-2021-r3s/talk/QED93K/ ',
'Slides (if available): https://speakers.c3lingo.org/talks/ea266d48-e185-5dbe-90dd-801a8fbe6ecc/ ',
'']
talks = list(extract_talks(test_content, "none"))
assert_that(len(talks), equal_to(1))
talk = talks[0]
assert_that(talk.title, equal_to('R3S Opening'))
assert_that(talk.speaker, equal_to('heyhej'))
assert_that(talk.fahrplan_url, equal_to('https://pretalx.c3voc.de/rc3-2021-r3s/talk/QED93K/'))
assert_that(talk.date, equal_to(1))
assert_that(talk.time, equal_to(time.fromisoformat('10:45')))
assert_that(talk.place, equal_to('r3s - Monheim/Rhein'))
def test_talk_translations():
test_content = ['### #1 ',
'[de] **10:45** +00:15, [r3s - Monheim/Rhein](https://meet.ffmuc.net/rc3r3sc3lingolowlatency) ',
'**R3S Opening** (Lightning Talk) ',
'heyhej ',
'Fahrplan: https://pretalx.c3voc.de/rc3-2021-r3s/talk/QED93K/ ',
'Slides (if available): https://speakers.c3lingo.org/talks/ea266d48-e185-5dbe-90dd-801a8fbe6ecc/ ',
'→ en: one',
'→ ru: three, four',
'']
talks = list(extract_talks(test_content, "none"))
assert_that(len(talks), equal_to(1))
talk = talks[0]
assert_that(len(talk.translations), equal_to(2))
print(talk.translations)
assert_that(talk.translations, contains_exactly('en', 'ru'))
assert_that(talk.translators, contains_exactly('one', 'three', 'four'))
def test_talk_translation_with_glossary():
test_content = ['### #1 ',
'[de] **10:45** +00:15, [r3s - Monheim/Rhein](https://meet.ffmuc.net/rc3r3sc3lingolowlatency) ',
'**R3S Opening** (Lightning Talk) ',
'heyhej ',
'Fahrplan: https://pretalx.c3voc.de/rc3-2021-r3s/talk/QED93K/ ',
'Slides (if available): https://speakers.c3lingo.org/talks/ea266d48-e185-5dbe-90dd-801a8fbe6ecc/ ',
'Glossary',
'→ en: one',
'→ ru: three, four',
'']
talks = list(extract_talks(test_content, "none"))
assert_that(len(talks), equal_to(1))
talk = talks[0]
assert_that(len(talk.translations), equal_to(2))
print(talk.translations)
assert_that(talk.translations, contains_exactly('en', 'ru'))
assert_that(talk.translators, contains_exactly('one', 'three', 'four'))
def test_talk_no_translator():
test_content = ['### #1 ',
'[de] **10:45** +00:15, [r3s - Monheim/Rhein](https://meet.ffmuc.net/rc3r3sc3lingolowlatency) ',
'**R3S Opening** (Lightning Talk) ',
'heyhej ',
'Fahrplan: https://pretalx.c3voc.de/rc3-2021-r3s/talk/QED93K/ ',
'Slides (if available): https://speakers.c3lingo.org/talks/ea266d48-e185-5dbe-90dd-801a8fbe6ecc/ ',
'→ en:',
'→ fr: ',
'']
talks = list(extract_talks(test_content, "none"))
assert_that(len(talks), equal_to(1))
talk = talks[0]
assert_that(talk.translations, empty())
assert_that(talk.translators, empty())
def test_extract_spacetime_coordinates():
the_language, the_time, the_duration, the_place = extract_spacetime_coordinates('[de] **10:45** +00:15, [r3s - Monheim/Rhein](https://meet.ffmuc.net/rc3r3sc3lingolowlatency) ')
assert_that(the_language, equal_to('de'))
assert_that(the_time, equal_to(time(hour=10, minute=45)))
assert_that(the_duration, equal_to(timedelta(hours=0, minutes=15)))
assert_that(the_place, equal_to('r3s - Monheim/Rhein'))