Source code for tests.patrolbot_tests

#!/usr/bin/env python3
"""Tests for the patrol script."""
# (C) Pywikibot team, 2015-2023
# Distributed under the terms of the MIT license.
from __future__ import annotations

from contextlib import suppress

from scripts.patrol import PatrolBot
from tests.aspects import DefaultDrySiteTestCase, unittest

This is some text above the entries:

== Header ==
* [[User:Test 1]]: [[Page 1]], [[Page 2]]
* [[User:Test_2]]: [[Page 2]], [[Page 4]], [[Page 6]]

== Others ==
* [[User:Prefixed]]: [[Special:PrefixIndex/Page 1]],
                     [[Special:PREFIXINDEX/Page 2]]

== More test 1 ==
* [[User:Test_1]]: [[Page 3]]

[docs] class TestPatrolBot(DefaultDrySiteTestCase): """Test the PatrolBot class."""
[docs] def setUp(self): """Create a bot dummy instance.""" super().setUp() = PatrolBot(
[docs] def test_parse_page_tuples(self): """Test parsing the page tuples from a dummy text.""" tuples = for gen_user in (1, 2): user = f'Test {gen_user}' self.assertIn(user, tuples) self.assertEqual(tuples[user], {f'Page {i * gen_user}' for i in range(1, 4)}) self.assertIn('Prefixed', tuples) self.assertEqual(tuples['Prefixed'], {'Page 1', 'Page 2'}) self.assertEqual('[[link]]'), {})
[docs] def test_in_list(self): """Test the method which returns whether a page is in the set.""" # Return True if there is an exact match self.assertTrue({'Foo', 'Foobar'}, 'Foo')) self.assertTrue({'Foo', 'Foobar'}, 'Foobar')) self.assertFalse({'Foo', 'Foobar'}, 'Bar')) # Return True if an entry starts with the title if there is no # exact match self.assertTrue({'Foo', 'Foobar'}, 'Foob')) self.assertTrue({'Foo', 'Foobar'}, 'Foobarz')) self.assertTrue({'Foo', 'Foobar', 'Bar'}, 'Barz')) self.assertFalse({'Foobar', 'Bar'}, 'Foo')) # '' returns True if there is no exact match self.assertTrue({''}, 'Foo')) self.assertTrue({'', 'Foobar'}, 'Foo')) self.assertTrue({'', 'Foo'}, 'Foo'))
if __name__ == '__main__': with suppress(SystemExit): unittest.main()