jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
Clean up and fix ProofreadPage and tests

Bug: T260472
Change-Id: I992c1823889a6874b1294c2e716caadbd6763c39
---
M pywikibot/proofreadpage.py
M tests/basepage_tests.py
M tests/proofreadpage_tests.py
3 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index bf1858b..f05e09e 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -460,30 +460,30 @@
.format(title))

# Property force page text loading.
- if not (hasattr(self, '_text') or self.text):
+ text = self.text
+ if not text:
self._create_empty_page()
return

_title = self.title(as_link=True)

- open_queue = list(self.p_open.finditer(self._text))
- close_queue = list(self.p_close.finditer(self._text))
+ open_queue = list(self.p_open.finditer(text))
+ close_queue = list(self.p_close.finditer(text))
_assert_len(len(open_queue), len(close_queue), _title)

f_open, f_close = open_queue[0], close_queue[0]
- self._full_header = FullHeader(
- self._text[f_open.end():f_close.start()])
+ self._full_header = FullHeader(text[f_open.end():f_close.start()])

# check version of page format and in case recompute last match,
# in order not to include </div>.
if not self._full_header._has_div:
- close_queue = list(self.p_close_no_div.finditer(self._text))
+ close_queue = list(self.p_close_no_div.finditer(text))
_assert_len(len(open_queue), len(close_queue), _title)

l_open, l_close = open_queue[-1], close_queue[-1]
- self._footer = self._text[l_open.end():l_close.start()]
+ self._footer = text[l_open.end():l_close.start()]

- self._body = self._text[f_close.end():l_open.start()]
+ self._body = text[f_close.end():l_open.start()]

def _compose_page(self):
"""Compose Proofread Page text from header, body and footer."""
diff --git a/tests/basepage_tests.py b/tests/basepage_tests.py
index 98c1443..bd2460f 100644
--- a/tests/basepage_tests.py
+++ b/tests/basepage_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Tests for BasePage subclasses."""
#
-# (C) Pywikibot team, 2015-2019
+# (C) Pywikibot team, 2015-2020
#
# Distributed under the terms of the MIT license.
#
@@ -38,6 +38,7 @@
"""

cached = False
+ custom_text = 'foobar'

def setUp(self):
"""Set up test."""
@@ -55,7 +56,7 @@

# verify that initializing the page content
# does not discard the custom text
- custom_text = 'foobar'
+ custom_text = self.custom_text
page.text = custom_text

self.site.loadrevisions(page, total=1)
diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py
index 6db5658..a677a23 100644
--- a/tests/proofreadpage_tests.py
+++ b/tests/proofreadpage_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Tests for the proofreadpage module."""
#
-# (C) Pywikibot team, 2015-2019
+# (C) Pywikibot team, 2015-2020
#
# Distributed under the terms of the MIT license.
#
@@ -76,6 +76,14 @@
"""Test site.loadrevisions() with Page.text."""
self._test_page_text()

+ @property
+ def custom_text(self):
+ """Return a dummy text for testing."""
+ cls_pagetext, div = TestProofreadPageValidSite.class_pagetext_fmt[True]
+ return TestProofreadPageValidSite.fmt.format(
+ user=self.site.username(), class_pagetext=cls_pagetext,
+ references='<references/>', div_end=div)
+

class TestProofreadPageParseTitle(TestCase):

@@ -580,6 +588,14 @@
"""Test site.loadrevisions() with Page.text."""
self._test_page_text()

+ @property
+ def custom_text(self):
+ """Return a dummy text for testing."""
+ cls_pagetext, div = TestProofreadPageValidSite.class_pagetext_fmt[True]
+ return TestProofreadPageValidSite.fmt.format(
+ user=self.site.username(), class_pagetext=cls_pagetext,
+ references='<references/>', div_end=div)
+

@unittest.skip('T193637 and T114318')
class TestIndexPageMappings(BS4TestCase):

To view, visit change 622838. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I992c1823889a6874b1294c2e716caadbd6763c39
Gerrit-Change-Number: 622838
Gerrit-PatchSet: 3
Gerrit-Owner: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged