John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/203515

Change subject: Expand testReprUnicode to validate the result
......................................................................

Expand testReprUnicode to validate the result

The repr(Page) test was very simple, only checking the type returned.
This expanded set of tests passes if applied before 1e54a7d6
so that any fix to Page.__repr__ after 1e54a7d6 can behave the same
as before unicode_literals.

Change-Id: I5e0ce794d38c047fef2c72c50664830175fbc64a
---
M tests/page_tests.py
1 file changed, 39 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/15/203515/1

diff --git a/tests/page_tests.py b/tests/page_tests.py
index d170cab..e01235d 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -14,7 +14,7 @@
 import pywikibot.page
 
 from tests.aspects import unittest, TestCase, DefaultSiteTestCase
-from tests.utils import allowed_failure
+from tests.utils import allowed_failure, expected_failure_if
 
 if sys.version_info[0] > 2:
     basestring = (str, )
@@ -492,16 +492,6 @@
         mainpage_unpickled = pickle.loads(mainpage_str)
         self.assertEqual(mainpage, mainpage_unpickled)
 
-    def testRepr(self):
-        mainpage = self.get_mainpage()
-        s = repr(mainpage)
-        self.assertIsInstance(s, str)
-
-    def testReprUnicode(self):
-        page = pywikibot.Page(self.get_site(), u'Ō')
-        s = repr(page)
-        self.assertIsInstance(s, str)
-
     def test_redirect(self):
         """Test that the redirect option is set correctly."""
         site = self.get_site()
@@ -522,6 +512,44 @@
         self.assertTrue(page_copy.isRedirectPage())
 
 
+class TestPageRepr(DefaultSiteTestCase):
+
+    """Test Page representation."""
+
+    cached = True
+
+    def test_mainpage_type(self):
+        u"""Test the return type of repr(Page(<main page>)) is str."""
+        mainpage = self.get_mainpage()
+        self.assertIsInstance(repr(mainpage), str)
+
+    def test_unicode_type(self):
+        """Test the return type of repr(Page(u'\u014c')) is str."""
+        page = pywikibot.Page(self.get_site(), u'Ō')
+        self.assertIsInstance(repr(page), str)
+
+    @expected_failure_if(sys.version_info[0] > 2)
+    def test_unicode_value(self):
+        """Test repr(Page(u'\u014c')) is represented simply as utf8."""
+        page = pywikibot.Page(self.get_site(), u'Ō')
+        self.assertEqual(repr(page), b'Page(\xc5\x8c)')
+
+    @unittest.skipIf(sys.version_info[0] > 2, 'Python 2 specific test')
+    def test_unicode_percent_r_failure(self):
+        """Test u'{x!r}'.format(Page(u'\u014c')) raises exception on Python 
2."""
+        # This raises an exception on Python 2, but passes on Python 3
+        page = pywikibot.Page(self.get_site(), u'Ō')
+        self.assertRaisesRegex(UnicodeDecodeError, '', unicode.format, 
u'{0!r}', page)
+
+    @unittest.skipIf(sys.version_info[0] < 3, 'Python 3+ specific test')
+    def test_unicode_value_py3(self):
+        """Test to capture actual Python 3 result pre unicode_literals."""
+        page = pywikibot.Page(self.get_site(), u'Ō')
+        self.assertEqual(repr(page), "Page(b'\\xc5\\x8c')")
+        self.assertEqual(u'%r' % page, "Page(b'\\xc5\\x8c')")
+        self.assertEqual(u'{0!r}'.format(page), "Page(b'\\xc5\\x8c')")
+
+
 class TestPageBotMayEdit(TestCase):
 
     """Test Page.botMayEdit() method."""

-- 
To view, visit https://gerrit.wikimedia.org/r/203515
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e0ce794d38c047fef2c72c50664830175fbc64a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jay...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to