forked from wikimedia/pywikibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharvest_template_tests.py
executable file
·68 lines (57 loc) · 2.18 KB
/
harvest_template_tests.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
#!/usr/bin/env python3
"""Tests for scripts/harvest_template.py."""
#
# (C) Pywikibot team, 2022-2023
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
import unittest
from contextlib import suppress
from pywikibot import ItemPage, WbTime
from scripts.harvest_template import HarvestRobot
from tests.aspects import ScriptMainTestCase
class TestHarvestRobot(ScriptMainTestCase):
"""Test HarvestRobot."""
family = 'wikipedia'
code = 'cs'
def test_template_link_target(self):
"""Test template_link_target static method."""
tests = [
('Pes', 'Q144'),
('Imaginární číslo', 'Q9165172'),
('Sequana', 'Q472766'),
]
for link, item in tests:
with self.subTest(link=link, item=item):
dummy_item = ItemPage(self.site.data_repository(), 'Q1')
target = HarvestRobot.template_link_target(
dummy_item, self.site, link)
self.assertIsInstance(target, ItemPage)
self.assertEqual(target.title(), item)
def test_handle_time(self):
"""Test handle_time method."""
bot = HarvestRobot('Foo', {}, site=self.site)
day = WbTime(2022, 7, 18, precision=11, site=bot.repo)
tests = [
('Foo', None),
('2022', WbTime(2022, 0, 0, precision=9, site=bot.repo)),
('2022-07-18', day),
('18. červenec 2022', day),
('18. července [[2021|2022]]', None),
('[[18. červenec]] 2022', day),
('[[18. červenec|18. července]] [[2022]]', day),
('[[17. červenec|18. července]] [[2022]]', None),
('44 př. n. l.',
WbTime(-44, 0, 0, precision=9,
calendarmodel='http://www.wikidata.org/entity/Q1985786',
site=bot.repo)),
]
for text, time in tests:
with self.subTest(text=text, time=time):
gen = bot.handle_time(text, self.site)
out = next(gen, None)
self.assertEqual(time, out)
if __name__ == '__main__':
with suppress(SystemExit):
unittest.main()