jenkins-bot has submitted this change and it was merged.
Change subject: port xmlreader_tests from compat
......................................................................
port xmlreader_tests from compat
Change-Id: I8d8a51b58c1754c168e04d15b289ce61481dc221
---
A tests/data/article-pear.xml
A tests/data/article-pyrus.xml
A tests/xmlreader_tests.py
3 files changed, 268 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/data/article-pear.xml b/tests/data/article-pear.xml
new file mode 100644
index 0000000..0203a26
--- /dev/null
+++ b/tests/data/article-pear.xml
@@ -0,0 +1,109 @@
+<mediawiki
xmlns="http://www.mediawiki.org/xml/export-0.3/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/
http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3"
xml:lang="en">
+ <siteinfo>
+ <sitename>Wikipedia</sitename>
+ <base>http://en.wikipedia.org/wiki/Main_Page</base>
+ <generator>MediaWiki 1.15alpha</generator>
+ <case>first-letter</case>
+ <namespaces>
+ <namespace key="-2">Media</namespace>
+ <namespace key="-1">Special</namespace>
+ <namespace key="0" />
+ <namespace key="1">Talk</namespace>
+ <namespace key="2">User</namespace>
+ <namespace key="3">User talk</namespace>
+ <namespace key="4">Wikipedia</namespace>
+ <namespace key="5">Wikipedia talk</namespace>
+ <namespace key="6">File</namespace>
+ <namespace key="7">File talk</namespace>
+ <namespace key="8">MediaWiki</namespace>
+ <namespace key="9">MediaWiki talk</namespace>
+ <namespace key="10">Template</namespace>
+ <namespace key="11">Template talk</namespace>
+ <namespace key="12">Help</namespace>
+ <namespace key="13">Help talk</namespace>
+ <namespace key="14">Category</namespace>
+ <namespace key="15">Category talk</namespace>
+ <namespace key="100">Portal</namespace>
+ <namespace key="101">Portal talk</namespace>
+ </namespaces>
+ </siteinfo>
+ <page>
+ <title>Pear</title>
+ <id>24278</id>
+ <revision>
+ <id>185185</id>
+ <timestamp>2002-02-25T15:43:11Z</timestamp>
+ <contributor>
+ <ip>Conversion script</ip>
+ </contributor>
+ <minor/>
+ <comment>Automated conversion</comment>
+ <text xml:space="preserve">Pears are [[tree]]s of the [[genus]]
<em>Pyrus</em> and the edible [[fruit]] of that tree.
+The pear is an important fruit in temperate regions. Like the [[apple]], the pear fruit
is a [[pome]]. There are thousands of domesticated pear varieties.
+
+There are many species of pears. The most important for fruit production are
<em>Pyrus communis</em> (European pear or simply pear) and
<em>Pyrus pyrifolia</em> (Asian pear or apple pear). Other
species are used as rootstocks for European and Asian pears and as ornamental trees.
+
+Unlike most fruits, European pears do not ripen on the tree. They must be picked and,
sometimes, subjected to cold, before they will become sweet and soft. They store well in
their mature but unripe state if kept cold. Asian pears are sweet on the tree and are
eaten crisp.
+
+Pears are consumed fresh, canned, and as juice. Fermented pear juice is called
[[perry]].
+</text>
+ </revision>
+ <revision>
+ <id>185241</id>
+ <timestamp>2002-08-31T02:16:06Z</timestamp>
+ <contributor>
+ <username>Quercusrobur</username>
+ <id>3741</id>
+ </contributor>
+ <text xml:space="preserve">Pears are [[tree]]s of the [[genus]]
<em>Pyrus</em> and the edible [[fruit]] of that tree.
+The pear is an important fruit in temperate regions. Like the [[apple]], the pear fruit
is a [[pome]]. There are thousands of domesticated pear varieties.
+
+There are many species of pears. The most important for fruit production are
<em>Pyrus communis</em> (European pear or simply pear) and
<em>Pyrus pyrifolia</em> (Asian pear or apple pear). Other
species are used as rootstocks for European and Asian pears and as ornamental trees.
+
+Unlike most fruits, European pears do not ripen on the tree. They must be picked and,
sometimes, subjected to cold, before they will become sweet and soft. They store well in
their mature but unripe state if kept cold. Asian pears are sweet on the tree and are
eaten crisp.
+
+Pears are consumed fresh, canned, and as juice. Fermented pear juice is called
[[perry]].
+
+[[propagating apples and other fruit trees]]</text>
+ </revision>
+ <revision>
+ <id>185408</id>
+ <timestamp>2002-08-31T03:27:15Z</timestamp>
+ <contributor>
+ <username>Mav</username>
+ <id>62</id>
+ </contributor>
+ <minor/>
+ <text xml:space="preserve">Pears are [[tree]]s of the [[genus]]
<em>Pyrus</em> and the edible [[fruit]] of that tree.
+The pear is an important fruit in temperate regions. Like the [[apple]], the pear fruit
is a [[pome]]. There are thousands of domesticated pear varieties.
+
+There are many species of pears. The most important for fruit production are
<em>Pyrus communis</em> (European pear or simply pear) and
<em>Pyrus pyrifolia</em> (Asian pear or apple pear). Other
species are used as rootstocks for European and Asian pears and as ornamental trees.
+
+Unlike most fruits, European pears do not ripen on the tree. They must be picked and,
sometimes, subjected to cold, before they will become sweet and soft. They store well in
their mature but unripe state if kept cold. Asian pears are sweet on the tree and are
eaten crisp.
+
+Pears are consumed fresh, canned, and as juice. Fermented pear juice is called
[[perry]].
+
+[[Fruit tree propogation]]</text>
+ </revision>
+ <revision>
+ <id>188924</id>
+ <timestamp>2002-08-31T05:53:10Z</timestamp>
+ <contributor>
+ <username>PierreAbbat</username>
+ <id>1123</id>
+ </contributor>
+ <minor/>
+ <comment>sp</comment>
+ <text xml:space="preserve">Pears are [[tree]]s of the [[genus]]
<em>Pyrus</em> and the edible [[fruit]] of that tree.
+The pear is an important fruit in temperate regions. Like the [[apple]], the pear fruit
is a [[pome]]. There are thousands of domesticated pear varieties.
+
+There are many species of pears. The most important for fruit production are
<em>Pyrus communis</em> (European pear or simply pear) and
<em>Pyrus pyrifolia</em> (Asian pear or apple pear). Other
species are used as rootstocks for European and Asian pears and as ornamental trees.
+
+Unlike most fruits, European pears do not ripen on the tree. They must be picked and,
sometimes, subjected to cold, before they will become sweet and soft. They store well in
their mature but unripe state if kept cold. Asian pears are sweet on the tree and are
eaten crisp.
+
+Pears are consumed fresh, canned, and as juice. Fermented pear juice is called
[[perry]].
+
+[[Fruit tree propagation]]</text>
+ </revision>
+ </page>
+</mediawiki>
diff --git a/tests/data/article-pyrus.xml b/tests/data/article-pyrus.xml
new file mode 100644
index 0000000..dfa82d3
--- /dev/null
+++ b/tests/data/article-pyrus.xml
@@ -0,0 +1,101 @@
+<mediawiki
xmlns="http://www.mediawiki.org/xml/export-0.3/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/
http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3"
xml:lang="en">
+ <siteinfo>
+ <sitename>Wikipedia</sitename>
+ <base>http://en.wikipedia.org/wiki/Main_Page</base>
+ <generator>MediaWiki 1.16alpha-wmf</generator>
+ <case>first-letter</case>
+ <namespaces>
+ <namespace key="-2">Media</namespace>
+ <namespace key="-1">Special</namespace>
+ <namespace key="0" />
+ <namespace key="1">Talk</namespace>
+ <namespace key="2">User</namespace>
+ <namespace key="3">User talk</namespace>
+ <namespace key="4">Wikipedia</namespace>
+ <namespace key="5">Wikipedia talk</namespace>
+ <namespace key="6">File</namespace>
+ <namespace key="7">File talk</namespace>
+ <namespace key="8">MediaWiki</namespace>
+ <namespace key="9">MediaWiki talk</namespace>
+ <namespace key="10">Template</namespace>
+ <namespace key="11">Template talk</namespace>
+ <namespace key="12">Help</namespace>
+ <namespace key="13">Help talk</namespace>
+ <namespace key="14">Category</namespace>
+ <namespace key="15">Category talk</namespace>
+ <namespace key="100">Portal</namespace>
+ <namespace key="101">Portal talk</namespace>
+ </namespaces>
+ </siteinfo>
+ <page>
+ <title>Pyrus</title>
+ <id>9261472</id>
+ <redirect />
+ <revision>
+ <id>104997415</id>
+ <timestamp>2007-02-02T02:39:52Z</timestamp>
+ <contributor>
+ <username>Melburnian</username>
+ <id>555187</id>
+ </contributor>
+ <comment>moved [[Pyrus]] to [[Pyrus (brand)]]: all links to
''Pyrus'' are related to the pear tree or fruit</comment>
+ <text xml:space="preserve">#REDIRECT [[Pyrus
(brand)]]</text>
+ </revision>
+ <revision>
+ <id>104997738</id>
+ <timestamp>2007-02-02T02:41:24Z</timestamp>
+ <contributor>
+ <username>Melburnian</username>
+ <id>555187</id>
+ </contributor>
+ <comment>all links to ''Pyrus'' are related to the pear tree
or fruit</comment>
+ <text xml:space="preserve">#REDIRECT [[Pear]]</text>
+ </revision>
+ <revision>
+ <id>189729426</id>
+ <timestamp>2008-02-07T14:06:10Z</timestamp>
+ <contributor>
+ <username>Jkokemueller</username>
+ <id>6303952</id>
+ </contributor>
+ <comment>Added disambiguation</comment>
+ <text xml:space="preserve">'''Pyrus''' may
refer to:
+
+* [[Pear]], trees of the genus ''Pyrus'' and the fruit of that tree,
edible in some species
+* [[Main//Pyrus DMS]], a [[Document Management System]]</text>
+ </revision>
+ <revision>
+ <id>190346463</id>
+ <timestamp>2008-02-10T07:21:12Z</timestamp>
+ <contributor>
+ <username>IceCreamAntisocial</username>
+ <id>346507</id>
+ </contributor>
+ <minor/>
+ <comment>rv</comment>
+ <text xml:space="preserve">#REDIRECT [[Pear]]</text>
+ </revision>
+ <revision>
+ <id>238138507</id>
+ <timestamp>2008-09-13T12:57:33Z</timestamp>
+ <contributor>
+ <username>Cottonapple4</username>
+ <id>7707615</id>
+ </contributor>
+ <comment>[[WP:AES|←]] Redirected page to [[Pear]]</comment>
+ <text xml:space="preserve">#REDIRECT [[Pear]]
+[[Category:Maloideae]]</text>
+ </revision>
+ <revision>
+ <id>238392911</id>
+ <timestamp>2008-09-14T17:08:56Z</timestamp>
+ <contributor>
+ <username>Rkitko</username>
+ <id>536375</id>
+ </contributor>
+ <minor/>
+ <comment>Reverted edits by
[[Special:Contributions/Cottonapple4|Cottonapple4]] ([[User talk:Cottonapple4|talk]]) to
last version by IceCreamAntisocial</comment>
+ <text xml:space="preserve">#REDIRECT [[Pear]]</text>
+ </revision>
+ </page>
+</mediawiki>
diff --git a/tests/xmlreader_tests.py b/tests/xmlreader_tests.py
new file mode 100644
index 0000000..1c26591
--- /dev/null
+++ b/tests/xmlreader_tests.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+"""
+Tests for xmlreader module.
+"""
+#
+# (C) Pywikibot team, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+
+
+import os.path
+from pywikibot import xmlreader
+from tests.utils import unittest
+
+
+class XmlReaderTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.path = os.path.dirname(os.path.abspath(__file__))
+
+ def test_XmlDumpAllRevs(self):
+ pages = [r for r in
+ xmlreader.XmlDump(os.path.join(self.path, 'data',
+ "article-pear.xml"),
+ allrevisions=True).parse()]
+ self.assertEquals(4, len(pages))
+ self.assertEquals(u"Automated conversion", pages[0].comment)
+ self.assertEquals(u"Pear", pages[0].title)
+ self.assertEquals(u"24278", pages[0].id)
+ self.assertTrue(pages[0].text.startswith('Pears are [[tree]]s of'))
+ self.assertEquals(u"Quercusrobur", pages[1].username)
+ self.assertEquals(u"Pear", pages[0].title)
+
+ def test_XmlDumpFirstRev(self):
+ pages = [r for r in
+ xmlreader.XmlDump(os.path.join(self.path, 'data',
+ "article-pear.xml")).parse()]
+ self.assertEquals(1, len(pages))
+ self.assertEquals(u"Automated conversion", pages[0].comment)
+ self.assertEquals(u"Pear", pages[0].title)
+ self.assertEquals(u"24278", pages[0].id)
+ self.assertTrue(pages[0].text.startswith('Pears are [[tree]]s of'))
+ self.assertTrue(not pages[0].isredirect)
+
+ def test_XmlDumpRedirect(self):
+ pages = [r for r in
+ xmlreader.XmlDump(os.path.join(self.path, 'data',
+ "article-pyrus.xml")).parse()]
+ self.assertTrue(pages[0].isredirect)
+
+
+if __name__ == '__main__':
+ try:
+ unittest.main()
+ except SystemExit:
+ pass
--
To view, visit
https://gerrit.wikimedia.org/r/137677
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8d8a51b58c1754c168e04d15b289ce61481dc221
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>