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."""
pywikibot-commits@lists.wikimedia.org