jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1306101?usp=email )
Change subject: [bugfix] Re-enable -ignorefile option with interwiki.py script ......................................................................
[bugfix] Re-enable -ignorefile option with interwiki.py script
interwiki -ignorefile option is broken since 3.0.20200508 because the ignore container InterwikiBotConfig.ignore is a list but not a set like the skip container used by -skipfile option.
- use extend method instead of update to add pages from TextIOPageGenerator with -ignorefile option - add a minimal interwikibot test case to test this issue
Bug: T430444 Change-Id: Iafab4f32e37770df2521af3e0a6145a727b276a0 --- M scripts/interwiki.py M tests/__init__.py A tests/interwikibot_tests.py 3 files changed, 59 insertions(+), 1 deletion(-)
Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
diff --git a/scripts/interwiki.py b/scripts/interwiki.py index a5a6955..2708bc9 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -555,7 +555,7 @@ for p in value.split(',')] elif arg == 'ignorefile': ignore_page_gen = pagegenerators.TextIOPageGenerator(value) - self.ignore.update(ignore_page_gen) + self.ignore.extend(ignore_page_gen) elif arg == 'showpage': self.showtextlink += self.showtextlinkadd elif arg == 'graph': diff --git a/tests/__init__.py b/tests/__init__.py index 4b0aa69..7c1fb7d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -154,6 +154,7 @@ 'generate_family_file', 'generate_user_files', 'harvest_template', + 'interwikibot', 'interwikidata', 'make_dist', 'noreferences', diff --git a/tests/interwikibot_tests.py b/tests/interwikibot_tests.py new file mode 100755 index 0000000..0a463e1 --- /dev/null +++ b/tests/interwikibot_tests.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# +# (C) Pywikibot team, 2026 +# +# Distributed under the terms of the MIT license. +# +"""Tests for scripts/interwiki.py.""" +from __future__ import annotations + +import unittest +from contextlib import suppress + +import pywikibot +from scripts import interwiki +from tests.aspects import DrySite, PatchingTestCase + + +class TestIwConfig(PatchingTestCase): + + """Tests for InterwikiBotConfig.""" + + family = 'wikipedia' + code = 'test' + dry = True + + @PatchingTestCase.patched(pywikibot, 'Site') + def Site(self, *args, **kwargs): # noqa: N802 + """Own DrySite creator.""" + code = self.site.code + fam = self.site.family + self.assertEqual(args, ()) + self.assertEqual(kwargs, {}) + site = DrySite(code, fam, None) + return site + + def test_ignore_option(self): + """Test -ignore and -ignorefile options.""" + iwc = interwiki.InterwikiBotConfig() + self.assertIsInstance(iwc.ignore, list) + self.assertIsEmpty(iwc.ignore) + iwc.readOptions('-ignorefile:tests/data/pagelist-lines.txt') + self.assertLength(iwc.ignore, 5) + iwc.readOptions('-ignore:Foo,Bar,Baz') + self.assertLength(iwc.ignore, 8) + + def test_skipfile_option(self): + """Test -skipfile options.""" + iwc = interwiki.InterwikiBotConfig() + self.assertIsInstance(iwc.skip, set) + self.assertIsEmpty(iwc.skip) + iwc.readOptions('-skipfile:tests/data/pagelist-lines.txt') + self.assertLength(iwc.skip, 5) + + +if __name__ == '__main__': + with suppress(SystemExit): + unittest.main()
pywikibot-commits@lists.wikimedia.org