jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] logentry tests: Also test other versions
......................................................................
[IMPROV] logentry tests: Also test other versions
Currently it only tests on the German Wikipedia but future API changes might
break it so testing it on the test Wikipedia might help find them sooner. It
also tests on an older wiki now which uses the old format.
Change-Id: Ibd8201087639043f9f4903729a0d69ecf4b1106c
---
M tests/aspects.py
M tests/logentry_tests.py
2 files changed, 40 insertions(+), 9 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py
index f96d9f0..73c89ca 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -641,6 +641,7 @@
def wrapped_method(self):
sitedata = self.sites[key]
+ self.site_key = key
self.family = sitedata['family']
self.code = sitedata['code']
self.site = sitedata['site']
diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py
index 5c750e5..f6a1611 100644
--- a/tests/logentry_tests.py
+++ b/tests/logentry_tests.py
@@ -14,6 +14,7 @@
import pywikibot
from pywikibot.logentries import LogEntryFactory
+from pywikibot.tools import MediaWikiVersion
from tests.aspects import (
unittest, MetaTestCaseClass, TestCase, DeprecationTestCase
@@ -26,13 +27,38 @@
class TestLogentriesBase(TestCase):
- """Base class for log entry tests."""
+ """
+ Base class for log entry tests.
- family = 'wikipedia'
- code = 'de'
+ It uses the German Wikipedia for a current representation of the log entries
+ and the test Wikipedia for the future representation. It also tests on a
+ wiki with MW 1.19 or older to check that it can still read the older format.
+ It currently uses lyricwiki which as of this commit uses 1.19.24.
+ """
+
+ sites = {
+ 'tewp': {
+ 'family': 'wikipedia',
+ 'code': 'test'
+ },
+ 'dewp': {
+ 'family': 'wikipedia',
+ 'code': 'de'
+ },
+ 'old': {
+ 'family': 'lyricwiki',
+ 'code': 'en'
+ }
+ }
def _get_logentry(self, logtype):
"""Retrieve a single log entry."""
+ if self.site_key == 'old':
+ # This is an assertion as the tests don't make sense with newer
+ # MW versions and otherwise it might not be visible that the test
+ # isn't run on an older wiki.
+ self.assertLess(MediaWikiVersion(self.site.version()),
+ MediaWikiVersion('1.20'))
return next(iter(self.site.logevents(logtype=logtype, total=1)))
@@ -44,10 +70,14 @@
"""Create the new class."""
def test_method(logtype):
- def test_logevent(self):
+ def test_logevent(self, key):
"""Test a single logtype entry."""
logentry = self._get_logentry(logtype)
self.assertEqual(logtype, logentry._expectedType)
+ if key == 'old':
+ self.assertNotIn('params', logentry.data)
+ else:
+ self.assertNotIn(logentry.type(), logentry.data)
self.assertIsInstance(logentry.action(), unicode)
self.assertIsInstance(logentry.comment(), unicode)
self.assertIsInstance(logentry.logid(), int)
@@ -83,7 +113,7 @@
"""Test LogEntry properties specific to their action."""
- def test_BlockEntry(self):
+ def test_BlockEntry(self, key):
"""Test BlockEntry methods."""
logentry = self._get_logentry('block')
if logentry.action() == 'block':
@@ -92,13 +122,13 @@
self.assertIsInstance(logentry.expiry(), pywikibot.Timestamp)
self.assertIsInstance(logentry.duration(), datetime.timedelta)
- def test_RightsEntry(self):
+ def test_RightsEntry(self, key):
"""Test RightsEntry methods."""
logentry = self._get_logentry('rights')
self.assertIsInstance(logentry.oldgroups, list)
self.assertIsInstance(logentry.newgroups, list)
- def test_MoveEntry(self):
+ def test_MoveEntry(self, key):
"""Test MoveEntry methods."""
logentry = self._get_logentry('move')
self.assertIsInstance(logentry.target_ns, pywikibot.site.Namespace)
@@ -108,7 +138,7 @@
self.assertIsInstance(logentry.target_page, pywikibot.Page)
self.assertIsInstance(logentry.suppressedredirect(), bool)
- def test_PatrolEntry(self):
+ def test_PatrolEntry(self, key):
"""Test PatrolEntry methods."""
logentry = self._get_logentry('patrol')
self.assertIsInstance(logentry.current_id, int)
@@ -120,7 +150,7 @@
"""Test cases for deprecated logentry methods."""
- def test_MoveEntry(self):
+ def test_MoveEntry(self, key):
"""Test deprecated MoveEntry methods."""
logentry = self._get_logentry('move')
self.assertIsInstance(logentry.new_ns(), int)
--
To view, visit https://gerrit.wikimedia.org/r/215005
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibd8201087639043f9f4903729a0d69ecf4b1106c
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: standardize basic.py
......................................................................
standardize basic.py
* inherits from the Bot class
* does not override .run()
* uses .userPut() instead of the custom .save()
* -dry enables pywikibot.config.simulate
Change-Id: I3820cb381b3529a9ca894f71064ab1d161e95773
---
M pywikibot/bot.py
M scripts/basic.py
2 files changed, 32 insertions(+), 67 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index b6a5f7b..ddd866e 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1108,6 +1108,9 @@
* 'show_diff' - show changes between oldtext and newtext (enabled)
* 'ignore_save_related_errors' - report and ignore (disabled)
* 'ignore_server_errors' - report and ignore (disabled)
+
+ @return: whether the page was saved successfully
+ @rtype: bool
"""
if oldtext == newtext:
pywikibot.output(u'No changes were needed on %s'
@@ -1125,7 +1128,7 @@
pywikibot.output(u'Edit summary: %s' % kwargs['summary'])
page.text = newtext
- self._save_page(page, page.save, **kwargs)
+ return self._save_page(page, page.save, **kwargs)
def _save_page(self, page, func, *args, **kwargs):
"""
@@ -1141,6 +1144,8 @@
@kwarg ignore_save_related_errors: if True, errors related to
page save will be reported and ignored (default: False)
@kwtype ignore_save_related_errors: bool
+ @return: whether the page was saved successfully
+ @rtype: bool
"""
if not self.user_confirm('Do you want to accept these changes?'):
return
@@ -1177,6 +1182,9 @@
raise
pywikibot.error(u'Server Error while processing %s: %s'
% (page.title(), e))
+ else:
+ return True
+ return False
def quit(self):
"""Cleanup and quit processing."""
diff --git a/scripts/basic.py b/scripts/basic.py
index 23dac2b..192d85f 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -16,7 +16,7 @@
"""
#
-# (C) Pywikibot team, 2006-2014
+# (C) Pywikibot team, 2006-2015
#
# Distributed under the terms of the MIT license.
#
@@ -26,8 +26,9 @@
#
import pywikibot
-from pywikibot import pagegenerators
-from pywikibot import i18n
+from pywikibot import i18n, pagegenerators, Bot
+
+from pywikibot.tools import issue_deprecation_warning
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -36,7 +37,7 @@
}
-class BasicBot:
+class BasicBot(Bot):
"""An incomplete sample bot."""
@@ -44,29 +45,26 @@
# The file containing these messages should have the same name as the caller
# script (i.e. basic.py in this case)
- def __init__(self, generator, dry):
+ def __init__(self, generator, dry=False, **kwargs):
"""
Constructor.
- Parameters:
- @param generator: The page generator that determines on which pages
- to work.
- @type generator: generator.
- @param dry: If True, doesn't do any real changes, but only shows
- what would have been changed.
- @type dry: boolean.
+ @param generator: the page generator that determines on which pages
+ to work
+ @type generator: generator
+ @param dry: if True, doesn't do any real changes, but only shows
+ what would have been changed
+ @type dry: bool
"""
+ if dry:
+ issue_deprecation_warning('dry argument', 'pywikibot.config.simulate', 1)
+ pywikibot.config.simulate = True
+ super(BasicBot, self).__init__(**kwargs)
self.generator = generator
- self.dry = dry
# Set the edit summary message
site = pywikibot.Site()
self.summary = i18n.twtranslate(site, 'basic-changing')
-
- def run(self):
- """Process each page from the generator."""
- for page in self.generator:
- self.treat(page)
def treat(self, page):
"""Load the given page, does some changes, and saves it."""
@@ -82,13 +80,13 @@
# Example: This puts the text 'Test' at the beginning of the page.
text = 'Test ' + text
- if not self.save(text, page, self.summary):
+ if not self.userPut(page, page.text, text, summary=self.summary,
+ ignore_save_related_errors=True):
pywikibot.output(u'Page %s not saved.' % page.title(asLink=True))
def load(self, page):
"""Load the text of the given page."""
try:
- # Load the page
text = page.get()
except pywikibot.NoPage:
pywikibot.output(u"Page %s does not exist; skipping."
@@ -99,42 +97,6 @@
else:
return text
return None
-
- def save(self, text, page, comment=None, minorEdit=True,
- botflag=True):
- """Update the given page with new text."""
- # only save if something was changed
- if text != page.get():
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
- # show what was changed
- pywikibot.showDiff(page.get(), text)
- pywikibot.output(u'Comment: %s' % comment)
- if not self.dry:
- if pywikibot.input_yn(
- u'Do you want to accept these changes?',
- default=False, automatic_quit=False):
- try:
- page.text = text
- # Save the page
- page.save(summary=comment or self.comment,
- minor=minorEdit, botflag=botflag)
- except pywikibot.LockedPage:
- pywikibot.output(u"Page %s is locked; skipping."
- % page.title(asLink=True))
- except pywikibot.EditConflict:
- pywikibot.output(
- u'Skipping %s because of edit conflict'
- % (page.title()))
- except pywikibot.SpamfilterError as error:
- pywikibot.output(
- u'Cannot change %s because of spam blacklist entry %s'
- % (page.title(), error.url))
- else:
- return True
- return False
def main(*args):
@@ -153,26 +115,21 @@
# that are also used by other scripts and that determine on which pages
# to work on.
genFactory = pagegenerators.GeneratorFactory()
- # The generator gives the pages that should be worked upon.
- gen = None
- # If dry is True, doesn't do any real changes, but only show
- # what would have been changed.
- dry = False
# Parse command line arguments
for arg in local_args:
- if arg.startswith("-dry"):
- dry = True
+ if arg == '-dry':
+ issue_deprecation_warning('-dry option', '-simulate', 1)
+ pywikibot.config.simulate = True
else:
genFactory.handleArg(arg)
- if not gen:
- gen = genFactory.getCombinedGenerator()
+ gen = genFactory.getCombinedGenerator()
if gen:
# The preloading generator is responsible for downloading multiple
# pages from the wiki simultaneously.
gen = pagegenerators.PreloadingGenerator(gen)
- bot = BasicBot(gen, dry)
+ bot = BasicBot(gen)
bot.run()
else:
pywikibot.showHelp()
--
To view, visit https://gerrit.wikimedia.org/r/181717
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3820cb381b3529a9ca894f71064ab1d161e95773
Gerrit-PatchSet: 14
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Allow relative links to be handled in Link constructor
......................................................................
Allow relative links to be handled in Link constructor
This patch allows a BasePage object to be passed in lieu of a Site
to the Link constructor. In this case, the link text will be handled
relative to the passed Page. This will allow for subpage links to be
parsed when relative links are used on the page. A new test, test_relative,
has been added to tests/link_tests.py to test this change.
Bug: T57113
Change-Id: Idd6366e82216c130b5143c9356245ff840af41ed
---
M pywikibot/page.py
M tests/link_tests.py
2 files changed, 29 insertions(+), 5 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 90efda1..16a69d0 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4461,17 +4461,23 @@
@type text: unicode
@param source: the Site on which the link was found (not necessarily
the site to which the link refers)
- @type source: Site
+ @type source: Site or BasePage
@param defaultNamespace: a namespace to use if the link does not
contain one (defaults to 0)
@type defaultNamespace: int
"""
- assert source is None or isinstance(source, pywikibot.site.BaseSite), \
- "source parameter should be a Site object"
+ source_is_page = isinstance(source, BasePage)
+
+ assert source is None or source_is_page or isinstance(source, pywikibot.site.BaseSite), \
+ "source parameter should be either a Site or Page object"
+
+ if source_is_page:
+ self._source = source.site
+ else:
+ self._source = source or pywikibot.Site()
self._text = text
- self._source = source or pywikibot.Site()
self._defaultns = defaultNamespace
# preprocess text (these changes aren't site-dependent)
@@ -4514,6 +4520,9 @@
t = t.replace(u"\u200e", u"").replace(u"\u200f", u"")
self._text = t
+ if source_is_page:
+ self._text = source.title(withSection=False) + self._text
+
def __repr__(self):
"""Return a more complete string representation."""
return "pywikibot.page.Link(%r, %r)" % (self.title, self.site)
diff --git a/tests/link_tests.py b/tests/link_tests.py
index 83020ff..29d216f 100644
--- a/tests/link_tests.py
+++ b/tests/link_tests.py
@@ -11,7 +11,7 @@
import pywikibot
from pywikibot import config2 as config
-from pywikibot.page import Link
+from pywikibot.page import Link, Page
from pywikibot.exceptions import Error, InvalidTitle
from tests.aspects import (
unittest,
@@ -108,6 +108,21 @@
self.assertRaises(InvalidTitle, Link('Category: ', self.get_site()).parse)
self.assertRaises(InvalidTitle, Link('Category: #bar', self.get_site()).parse)
+ def test_relative(self):
+ """Test that relative links are handled properly."""
+ # Subpage
+ p = Page(self.get_site(), 'Foo')
+ l = Link('/bar', p)
+ self.assertEquals(l.title, 'Foo/bar')
+ self.assertEquals(l.site, self.get_site())
+ # Subpage of Page with section
+ p = Page(self.get_site(), 'Foo#Baz')
+ l = Link('/bar', p)
+ self.assertEquals(l.title, 'Foo/bar')
+ self.assertEquals(l.site, self.get_site())
+ # Non-subpage link text beginning with slash
+ l = Link('/bar', self.get_site())
+ self.assertEquals(l.title, '/bar')
# ---- The first set of tests are explicit links, starting with a ':'.
--
To view, visit https://gerrit.wikimedia.org/r/213816
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idd6366e82216c130b5143c9356245ff840af41ed
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 <happy5214(a)gmail.com>
Gerrit-Reviewer: Happy5214 <happy5214(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] tests: Document usage of write env vars
......................................................................
[IMPROV] tests: Document usage of write env vars
Instead of being specific to Travis make clear that also failure tests are
disabled be default and only enabled on Travis (except for the 'wikimedia'
user). It also documents that both variables work independently so that failure
tests aren't done when normal tests are enabled.
Change-Id: I47561267cb905fcf84fd986ef9dd15a85cf20b10
---
M tests/README.rst
1 file changed, 7 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/README.rst b/tests/README.rst
index 3080680..8ef0b6b 100644
--- a/tests/README.rst
+++ b/tests/README.rst
@@ -138,8 +138,8 @@
and **should** fail. If there is a bug in pywikibot or MediaWiki, these
tests **may** actually perform a write operation.
-These 'edit failure' tests are disabled by default for the 'wikimedia' builds,
-but are enabled by default on builds by any other github account.
+These 'edit failure' tests are disabled by default. On Travis they are enabled
+by default on builds by any other github account except 'wikimedia'.
To disable 'edit failure' tests, set PYWIKIBOT2_TEST_WRITE_FAIL=0
@@ -148,10 +148,14 @@
should always only write to 'test' wikis.
These 'write' tests are disabled by default, and currently can not be
-run on travis or appveyor as they require interaction using a terminal.
+run on travis or appveyor as they require interaction using a terminal. Also
+enabling them won't enable 'edit failure' tests.
To enable 'write' tests, set PYWIKIBOT2_TEST_WRITE=1
+Enabling only 'edit failure' tests or 'write' tests won't enable the other tests
+automatically.
+
Contributing tests
==================
--
To view, visit https://gerrit.wikimedia.org/r/215332
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I47561267cb905fcf84fd986ef9dd15a85cf20b10
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>