jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] Require archivebot durations to have a time unit

This reverts commit 4a350673c4aec0fefb1029f47698f7819430a35c.

Change-Id: I3dfa60dfa66022cdb1f573605d495078407703e1
---
M scripts/archivebot.py
M tests/archivebot_tests.py
2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index f3c2370..03353a8 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 change 697061. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3dfa60dfa66022cdb1f573605d495078407703e1
Gerrit-Change-Number: 697061
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Damian <atagar1@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged