Source code for tests.harvest_template_tests

#!/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


[docs] class TestHarvestRobot(ScriptMainTestCase): """Test HarvestRobot.""" family = 'wikipedia' code = 'cs'
[docs] 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()