jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693849 )
Change subject: Append a newline to context before question
......................................................................
Append a newline to context before question
Without it, the context output glued with the options.
See T283488 ("* [[Mark Twain]] (1835−1910Option (<number> [1-19]").
Change-Id: Ibcf9146a1dc6dc3723cc977af8c189e95eb774e2
---
M pywikibot/userinterfaces/terminal_interface_base.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index ceace54..c4abe8b 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -401,7 +401,7 @@
for option in options:
if isinstance(option, OutputOption) \
and option.before_question:
- self.stream_output(option.out)
+ self.stream_output(option.out + '\n')
output = Option.formatted(question, options, default)
if force:
self.stream_output(output + '\n')
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693849
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ibcf9146a1dc6dc3723cc977af8c189e95eb774e2
Gerrit-Change-Number: 693849
Gerrit-PatchSet: 1
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693649 )
Change subject: [doc] Update documentation
......................................................................
[doc] Update documentation
* mediawiki --> MediaWiki
* Update redirected URLs
Change-Id: Ifc0fbd3f147cf1bcb6abd8c0f70126ea464b7f24
---
M pywikibot/data/api.py
M pywikibot/diff.py
M scripts/archivebot.py
M tests/date_tests.py
4 files changed, 4 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 733ef13..4974223 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2283,7 +2283,7 @@
* list=alldeletedrevisions
More info:
- https://lists.wikimedia.org/pipermail/mediawiki-api-announce/2018-August/00…
+ https://lists.wikimedia.org/hyperkitty/list/mediawiki-api-announce@lists.wi…
"""
if self.site.mw_version < '1.32':
return
diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 13eea46..366b268 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -584,7 +584,7 @@
Site.compare() returns HTML that is useful for displaying on a page.
Here we use BeautifulSoup to get the un-HTML-ify the context of changes.
Finally we present the added and deleted contexts.
- @param compare_string: HTML string from mediawiki API
+ @param compare_string: HTML string from MediaWiki API
@return: deleted and added list of contexts
"""
from bs4 import BeautifulSoup
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 7de2476..f3c2370 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -73,7 +73,7 @@
of the year. So up to three days are still counted as the year before.
See also:
- - http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
+ - https://webspace.science.uu.nl/~gent0113/calendar/isocalendar.htm
- https://docs.python.org/3.4/library/datetime.html#datetime.date.isocalendar
Options (may be omitted):
diff --git a/tests/date_tests.py b/tests/date_tests.py
index 3facf6d..d76989f 100644
--- a/tests/date_tests.py
+++ b/tests/date_tests.py
@@ -66,7 +66,7 @@
net = True
def test_month_name_formats(self):
- """Test MonthName format for codes retrieved via mediawiki message."""
+ """Test MonthName format for codes retrieved via MediaWiki message."""
formatname = 'MonthName'
for code in date.formats['Cat_BirthsAD']:
convert = date.formats[formatname][code]
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693649
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ifc0fbd3f147cf1bcb6abd8c0f70126ea464b7f24
Gerrit-Change-Number: 693649
Gerrit-PatchSet: 3
Gerrit-Owner: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693512 )
Change subject: [cleanup] Disallow non-numeric i18n count
......................................................................
[cleanup] Disallow non-numeric i18n count
When 'num' was a string representation of a number rather than an int we issued
a deprecation warning. Time to enforce it.
Change-Id: Ie7b491674a44ca9f8b42942441d0c49af2b5ba29
---
M pywikibot/i18n.py
1 file changed, 2 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 5399c85..5eaf720 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -38,7 +38,6 @@
ModuleDeprecationWrapper,
deprecated,
deprecated_args,
- issue_deprecation_warning,
)
@@ -441,12 +440,8 @@
variants = match.group(2)
num = parameters[selector]
if not isinstance(num, int):
- issue_deprecation_warning(
- 'type {} for value {} ({})'
- .format(type(num), selector, num),
- 'an int', 1,
- warning_class=FutureWarning, since='20151009')
- num = int(num)
+ raise ValueError("'{}' must be a number, not a {} ({})"
+ .format(selector, num, type(num).__name__))
plural_entries = []
specific_entries = {}
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693512
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie7b491674a44ca9f8b42942441d0c49af2b5ba29
Gerrit-Change-Number: 693512
Gerrit-PatchSet: 2
Gerrit-Owner: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: Isaacandy <isaac(a)iznd.xyz>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693509 )
Change subject: [cleanup] Remove deprecated twntranslate method
......................................................................
[cleanup] Remove deprecated twntranslate method
This method was deprecated about six years ago. Also cleaning up a couple bits
of code that were commented as being for it.
Change-Id: I0b31aaeff0f175ca2ed6f6200b61ba47c3f1879d
---
M pywikibot/i18n.py
M tests/i18n_tests.py
2 files changed, 4 insertions(+), 213 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 5399c85..4554f3a7 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -28,7 +28,6 @@
from contextlib import suppress
from textwrap import fill
from typing import Optional, Union
-from warnings import warn
import pywikibot
from pywikibot import __url__, config
@@ -36,7 +35,6 @@
from pywikibot.plural import plural_rule
from pywikibot.tools import (
ModuleDeprecationWrapper,
- deprecated,
deprecated_args,
issue_deprecation_warning,
)
@@ -710,21 +708,9 @@
'See {}/i18n'
.format(_messages_package_name, twtitle, __url__))
- source_needed = False
- # If a site is given instead of a lang, use its language
- if hasattr(source, 'lang'):
- lang = source.lang
- # check whether we need the language code back
- elif isinstance(source, list):
- # For backwards compatibility still support lists, when twntranslate
- # was not deprecated and needed a way to get the used language code
- # back.
- warn('The source argument should not be a list but either a BaseSite '
- 'or a str/unicode.', DeprecationWarning, 2)
- lang = source.pop()
- source_needed = True
- else:
- lang = source
+ # if source is a site then use its lang attribute, otherwise it's a str
+
+ lang = getattr(source, 'lang', source)
# There are two possible failure modes: the translation dict might not have
# the language altogether, or a specific key could be untranslated. Both
@@ -743,9 +729,6 @@
'outdated submodule. See {}/i18n'
.format('English' if 'en' in langs else "'{}'".format(lang),
twtitle, __url__)))
- # send the language code back via the given mutable list parameter
- if source_needed:
- source.append(alt)
if '{{PLURAL:' in trans:
# _extract_plural supports in theory non-mappings, but they are
@@ -754,16 +737,6 @@
raise TypeError('parameters must be a mapping.')
trans = _extract_plural(alt, trans, parameters)
- # this is only the case when called in twntranslate, and that didn't apply
- # parameters when it wasn't a dict
- if isinstance(parameters, _PluralMappingAlias):
- # This is called due to the old twntranslate function which ignored
- # KeyError. Instead only_plural should be used.
- if isinstance(parameters.source, dict):
- with suppress(KeyError):
- trans %= parameters.source
- parameters = None
-
if parameters is not None and not isinstance(parameters, Mapping):
raise ValueError('parameters should be a mapping, not {}'
.format(type(parameters).__name__))
@@ -773,16 +746,6 @@
return trans
-@deprecated('twtranslate', since='20151009', future_warning=True)
-@deprecated_args(code='source')
-def twntranslate(source, twtitle: str,
- parameters: Optional[Mapping] = None) -> Optional[str]:
- """DEPRECATED: Get translated string for the key."""
- if parameters is not None:
- parameters = _PluralMappingAlias(parameters)
- return twtranslate(source, twtitle, parameters)
-
-
@deprecated_args(code='source')
def twhas_key(source, twtitle: str) -> bool:
"""
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 2c9bc72..b80d6fb 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -7,10 +7,9 @@
from contextlib import suppress
import pywikibot
-from pywikibot import bot, config, i18n, plural
+from pywikibot import bot, config, i18n
from pywikibot.exceptions import TranslationError
from tests.aspects import (
- AutoDeprecationTestCase,
DefaultSiteTestCase,
PwbTestCase,
TestCase,
@@ -296,177 +295,6 @@
i18n.twtranslate('en', 'test-no-english')
-class TestTWNTranslate(TWNTestCaseBase, AutoDeprecationTestCase):
-
- """Test {{PLURAL:}} support."""
-
- net = False
- message_package = 'tests.i18n'
-
- def testNumber(self):
- """Use a number."""
- self.assertEqual(
- i18n.twntranslate('de', 'test-plural', 0) % {'num': 0},
- 'Bot: Ändere 0 Seiten.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-plural', 1) % {'num': 1},
- 'Bot: Ändere 1 Seite.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-plural', 2) % {'num': 2},
- 'Bot: Ändere 2 Seiten.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-plural', 3) % {'num': 3},
- 'Bot: Ändere 3 Seiten.')
- self.assertEqual(
- i18n.twntranslate('en', 'test-plural', 0) % {'num': 'no'},
- 'Bot: Changing no pages.')
- self.assertEqual(
- i18n.twntranslate('en', 'test-plural', 1) % {'num': 'one'},
- 'Bot: Changing one page.')
- self.assertEqual(
- i18n.twntranslate('en', 'test-plural', 2) % {'num': 'two'},
- 'Bot: Changing two pages.')
- self.assertEqual(
- i18n.twntranslate('en', 'test-plural', 3) % {'num': 'three'},
- 'Bot: Changing three pages.')
-
- def testString(self):
- """Use a string."""
- self.assertEqual(
- i18n.twntranslate('en', 'test-plural', '1') % {'num': 'one'},
- 'Bot: Changing one page.')
-
- def testDict(self):
- """Use a dictionary."""
- self.assertEqual(
- i18n.twntranslate('en', 'test-plural', {'num': 2}),
- 'Bot: Changing 2 pages.')
-
- def testExtended(self):
- """Use additional format strings."""
- self.assertEqual(
- i18n.twntranslate('fr', 'test-plural',
- {'num': 1, 'descr': 'seulement'}),
- 'Robot: Changer seulement une page.')
-
- def testExtendedOutside(self):
- """Use additional format strings also outside."""
- self.assertEqual(
- i18n.twntranslate('fr', 'test-plural', 1) % {'descr': 'seulement'},
- 'Robot: Changer seulement une page.')
-
- def testMultiple(self):
- """Test using multiple plural entries."""
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals', 1)
- % {'action': 'Ändere', 'line': 'eine'},
- 'Bot: Ändere eine Zeile von einer Seite.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals', 2)
- % {'action': 'Ändere', 'line': 'zwei'},
- 'Bot: Ändere zwei Zeilen von mehreren Seiten.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals', 3)
- % {'action': 'Ändere', 'line': 'drei'},
- 'Bot: Ändere drei Zeilen von mehreren Seiten.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals', (1, 2, 2))
- % {'action': 'Ändere', 'line': 'eine'},
- 'Bot: Ändere eine Zeile von mehreren Seiten.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals', [3, 1, 1])
- % {'action': 'Ändere', 'line': 'drei'},
- 'Bot: Ändere drei Zeilen von einer Seite.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals', ['3', 1, 1])
- % {'action': 'Ändere', 'line': 'drei'},
- 'Bot: Ändere drei Zeilen von einer Seite.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals', '321')
- % {'action': 'Ändere', 'line': 'dreihunderteinundzwanzig'},
- 'Bot: Ändere dreihunderteinundzwanzig Zeilen von mehreren Seiten.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals',
- {'action': 'Ändere', 'line': 1, 'page': 1}),
- 'Bot: Ändere 1 Zeile von einer Seite.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals',
- {'action': 'Ändere', 'line': 1, 'page': 2}),
- 'Bot: Ändere 1 Zeile von mehreren Seiten.')
- self.assertEqual(
- i18n.twntranslate('de', 'test-multiple-plurals',
- {'action': 'Ändere', 'line': '11', 'page': 2}),
- 'Bot: Ändere 11 Zeilen von mehreren Seiten.')
-
- def testMultipleWrongParameterLength(self):
- """Test wrong parameter length."""
- err_msg = 'Length of parameter does not match PLURAL occurrences'
- with self.assertRaisesRegex(ValueError, err_msg):
- i18n.twntranslate('de', 'test-multiple-plurals', (1, 2))
-
- with self.assertRaisesRegex(ValueError, err_msg):
- i18n.twntranslate('de', 'test-multiple-plurals', ['321'])
-
- def testMultipleNonNumbers(self):
- """Test error handling for multiple non-numbers."""
- with self.assertRaisesRegex(
- ValueError, r"invalid literal for int\(\) with base 10: 'drei'"
- ):
- i18n.twntranslate('de', 'test-multiple-plurals', ['drei', '1', 1])
- with self.assertRaisesRegex(
- ValueError, r"invalid literal for int\(\) with base 10: 'elf'"
- ):
- i18n.twntranslate('de', 'test-multiple-plurals',
- {'action': 'Ändere', 'line': 'elf', 'page': 2})
-
- def testAllParametersExist(self):
- """Test that all parameters are required when using a dict."""
- # all parameters must be inside twntranslate
- self.assertEqual(i18n.twntranslate('de', 'test-multiple-plurals',
- {'line': 1, 'page': 1}),
- 'Bot: %(action)s %(line)s Zeile von einer Seite.')
-
- def test_fallback_lang(self):
- """
- Test that twntranslate uses the translation's language.
-
- twntranslate calls _twtranslate which might return the translation for
- a different language and then the plural rules from that language need
- to be applied.
- """
- # co has fr as altlang but has no plural rules defined (otherwise this
- # test might not catch problems) so it's using the plural variant for 0
- # although French uses the plural variant for numbers > 1 (so not 0)
- assert 'co' not in plural.plural_rules
- assert plural.plural_rules['fr']['plural'](0) is False
- self.assertEqual(
- i18n.twntranslate('co', 'test-plural',
- {'num': 0, 'descr': 'seulement'}),
- 'Robot: Changer seulement une page.')
- self.assertEqual(
- i18n.twntranslate('co', 'test-plural',
- {'num': 1, 'descr': 'seulement'}),
- 'Robot: Changer seulement une page.')
-
-
-class ScriptMessagesTestCase(TWNTestCaseBase, AutoDeprecationTestCase):
-
- """Real messages test."""
-
- net = False
- message_package = 'scripts.i18n'
-
- def test_basic(self):
- """Verify that real messages are able to be loaded."""
- self.assertEqual(i18n.twntranslate('en', 'pywikibot-enter-new-text'),
- 'Please enter the new text:')
-
- def test_missing(self):
- """Test a missing message from a real message bundle."""
- with self.assertRaises(TranslationError):
- i18n.twntranslate('en', 'pywikibot-missing-key')
-
-
class InputTestCase(TWNTestCaseBase, UserInterfaceLangTestCase, PwbTestCase):
"""Test i18n.input."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693509
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I0b31aaeff0f175ca2ed6f6200b61ba47c3f1879d
Gerrit-Change-Number: 693509
Gerrit-PatchSet: 2
Gerrit-Owner: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693539 )
Change subject: Revert "[cleanup] Require archivebot durations to have a time unit"
......................................................................
Revert "[cleanup] Require archivebot durations to have a time unit"
This reverts commit 5bc89c24e0c8dfe57831a6c36e8843c752784439.
Reason for revert: This is too early.
May come at earliest with 6.3 as the FutureWarning's announcement was in 6.1
Change-Id: Ibe4feec28388950e03be722fe4ccaab0228a1c82
---
M scripts/archivebot.py
M tests/archivebot_tests.py
2 files changed, 15 insertions(+), 17 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index f81be2e..7de2476 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -116,6 +116,7 @@
findmarker,
to_local_digits,
)
+from pywikibot.tools import issue_deprecation_warning
ShouldArchive = Tuple[str, str]
@@ -241,19 +242,15 @@
@return: key and duration extracted form the string
"""
- if len(string) < 2:
- raise MalformedConfigError('Time period should be a numeric value '
- 'followed by its qualifier')
-
- key, duration = string[-1], string[:-1]
-
- if key not in MW_KEYS:
- raise MalformedConfigError('Time period qualifier is unrecognized: {}'
- .format(string))
- if not duration.isdigit():
- raise MalformedConfigError("Time period's duration should be "
- 'numeric: {}'.format(string))
-
+ if string.isdigit():
+ key = 's'
+ duration = string
+ issue_deprecation_warning('Time period without qualifier',
+ string + key, 1, FutureWarning,
+ since='20161009')
+ else:
+ key = string[-1]
+ duration = string[:-1]
return key, duration
diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py
index e3a3828..9bf1e36 100644
--- a/tests/archivebot_tests.py
+++ b/tests/archivebot_tests.py
@@ -12,6 +12,7 @@
import pywikibot.page
from pywikibot.exceptions import Error
from pywikibot.textlib import TimeStripper
+from pywikibot.tools import suppress_warnings
from scripts import archivebot
from tests.aspects import TestCase
@@ -96,12 +97,12 @@
def test_checkstr(self):
"""Test for extracting key and duration from shorthand notation."""
self.assertEqual(archivebot.checkstr('400s'), ('s', '400'))
+ with suppress_warnings('Time period without qualifier', UserWarning):
+ self.assertEqual(archivebot.checkstr('3000'), ('s', '3000'))
self.assertEqual(archivebot.checkstr('7d'), ('d', '7'))
self.assertEqual(archivebot.checkstr('3y'), ('y', '3'))
-
- for invalid_value in ('', '3000', '4000@'):
- with self.assertRaises(archivebot.MalformedConfigError):
- archivebot.checkstr(invalid_value)
+ # Should pass, because the key is verified in str2time
+ self.assertEqual(archivebot.checkstr('4000@'), ('@', '4000'))
def test_str2size(self):
"""Test for parsing the shorthand notation of sizes."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693539
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ibe4feec28388950e03be722fe4ccaab0228a1c82
Gerrit-Change-Number: 693539
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693584 )
Change subject: [cleanup] Require archivebot durations to have a time unit
......................................................................
[cleanup] Require archivebot durations to have a time unit
Our archivebot's checkstr() should verify that our time value is valid.
Dropping the deprecated behavior of treating numeric values as seconds, and
adding basic input validation.
Change-Id: I997c6e82a9890a9526f26c0e8b5474a216b97579
---
M scripts/archivebot.py
M tests/archivebot_tests.py
2 files changed, 17 insertions(+), 15 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 7de2476..f81be2e 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -116,7 +116,6 @@
findmarker,
to_local_digits,
)
-from pywikibot.tools import issue_deprecation_warning
ShouldArchive = Tuple[str, str]
@@ -242,15 +241,19 @@
@return: key and duration extracted form the string
"""
- if string.isdigit():
- key = 's'
- duration = string
- issue_deprecation_warning('Time period without qualifier',
- string + key, 1, FutureWarning,
- since='20161009')
- else:
- key = string[-1]
- duration = string[:-1]
+ if len(string) < 2:
+ raise MalformedConfigError('Time period should be a numeric value '
+ 'followed by its qualifier')
+
+ key, duration = string[-1], string[:-1]
+
+ if key not in MW_KEYS:
+ raise MalformedConfigError('Time period qualifier is unrecognized: {}'
+ .format(string))
+ if not duration.isdigit():
+ raise MalformedConfigError("Time period's duration should be "
+ 'numeric: {}'.format(string))
+
return key, duration
diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py
index 9bf1e36..e3a3828 100644
--- a/tests/archivebot_tests.py
+++ b/tests/archivebot_tests.py
@@ -12,7 +12,6 @@
import pywikibot.page
from pywikibot.exceptions import Error
from pywikibot.textlib import TimeStripper
-from pywikibot.tools import suppress_warnings
from scripts import archivebot
from tests.aspects import TestCase
@@ -97,12 +96,12 @@
def test_checkstr(self):
"""Test for extracting key and duration from shorthand notation."""
self.assertEqual(archivebot.checkstr('400s'), ('s', '400'))
- with suppress_warnings('Time period without qualifier', UserWarning):
- self.assertEqual(archivebot.checkstr('3000'), ('s', '3000'))
self.assertEqual(archivebot.checkstr('7d'), ('d', '7'))
self.assertEqual(archivebot.checkstr('3y'), ('y', '3'))
- # Should pass, because the key is verified in str2time
- self.assertEqual(archivebot.checkstr('4000@'), ('@', '4000'))
+
+ for invalid_value in ('', '3000', '4000@'):
+ with self.assertRaises(archivebot.MalformedConfigError):
+ archivebot.checkstr(invalid_value)
def test_str2size(self):
"""Test for parsing the shorthand notation of sizes."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693584
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I997c6e82a9890a9526f26c0e8b5474a216b97579
Gerrit-Change-Number: 693584
Gerrit-PatchSet: 1
Gerrit-Owner: Damian <atagar1(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged