|
|
@@ -23,13 +23,9 @@ |
|
|
|
from __future__ import unicode_literals |
|
|
|
from sys import getdefaultencoding |
|
|
|
from types import GeneratorType |
|
|
|
import unittest |
|
|
|
|
|
|
|
try: |
|
|
|
import unittest2 as unittest |
|
|
|
except ImportError: |
|
|
|
import unittest |
|
|
|
|
|
|
|
from mwparserfromhell.compat import bytes, py3k, py32, range, str |
|
|
|
from mwparserfromhell.compat import bytes, py3k, range, str |
|
|
|
from mwparserfromhell.string_mixin import StringMixIn |
|
|
|
|
|
|
|
class _FakeString(StringMixIn): |
|
|
@@ -54,9 +50,7 @@ class TestStringMixIn(unittest.TestCase): |
|
|
|
"rsplit", "rstrip", "split", "splitlines", "startswith", "strip", |
|
|
|
"swapcase", "title", "translate", "upper", "zfill"] |
|
|
|
if py3k: |
|
|
|
if not py32: |
|
|
|
methods.append("casefold") |
|
|
|
methods.extend(["format_map", "isidentifier", "isprintable", |
|
|
|
methods.extend(["casefold", "format_map", "isidentifier", "isprintable", |
|
|
|
"maketrans"]) |
|
|
|
else: |
|
|
|
methods.append("decode") |
|
|
@@ -90,33 +84,33 @@ class TestStringMixIn(unittest.TestCase): |
|
|
|
str4 = "this is a fake string" |
|
|
|
str5 = "fake string, this is" |
|
|
|
|
|
|
|
self.assertFalse(str1 > str2) |
|
|
|
self.assertTrue(str1 >= str2) |
|
|
|
self.assertTrue(str1 == str2) |
|
|
|
self.assertFalse(str1 != str2) |
|
|
|
self.assertFalse(str1 < str2) |
|
|
|
self.assertTrue(str1 <= str2) |
|
|
|
|
|
|
|
self.assertTrue(str1 > str3) |
|
|
|
self.assertTrue(str1 >= str3) |
|
|
|
self.assertFalse(str1 == str3) |
|
|
|
self.assertTrue(str1 != str3) |
|
|
|
self.assertFalse(str1 < str3) |
|
|
|
self.assertFalse(str1 <= str3) |
|
|
|
|
|
|
|
self.assertFalse(str1 > str4) |
|
|
|
self.assertTrue(str1 >= str4) |
|
|
|
self.assertTrue(str1 == str4) |
|
|
|
self.assertFalse(str1 != str4) |
|
|
|
self.assertFalse(str1 < str4) |
|
|
|
self.assertTrue(str1 <= str4) |
|
|
|
|
|
|
|
self.assertFalse(str5 > str1) |
|
|
|
self.assertFalse(str5 >= str1) |
|
|
|
self.assertFalse(str5 == str1) |
|
|
|
self.assertTrue(str5 != str1) |
|
|
|
self.assertTrue(str5 < str1) |
|
|
|
self.assertTrue(str5 <= str1) |
|
|
|
self.assertLessEqual(str1, str2) |
|
|
|
self.assertGreaterEqual(str1, str2) |
|
|
|
self.assertEqual(str1, str2) |
|
|
|
self.assertEqual(str1, str2) |
|
|
|
self.assertGreaterEqual(str1, str2) |
|
|
|
self.assertLessEqual(str1, str2) |
|
|
|
|
|
|
|
self.assertGreater(str1, str3) |
|
|
|
self.assertGreaterEqual(str1, str3) |
|
|
|
self.assertNotEqual(str1, str3) |
|
|
|
self.assertNotEqual(str1, str3) |
|
|
|
self.assertGreaterEqual(str1, str3) |
|
|
|
self.assertGreater(str1, str3) |
|
|
|
|
|
|
|
self.assertLessEqual(str1, str4) |
|
|
|
self.assertGreaterEqual(str1, str4) |
|
|
|
self.assertEqual(str1, str4) |
|
|
|
self.assertEqual(str1, str4) |
|
|
|
self.assertGreaterEqual(str1, str4) |
|
|
|
self.assertLessEqual(str1, str4) |
|
|
|
|
|
|
|
self.assertLessEqual(str5, str1) |
|
|
|
self.assertLess(str5, str1) |
|
|
|
self.assertNotEqual(str5, str1) |
|
|
|
self.assertNotEqual(str5, str1) |
|
|
|
self.assertLess(str5, str1) |
|
|
|
self.assertLessEqual(str5, str1) |
|
|
|
|
|
|
|
def test_other_magics(self): |
|
|
|
"""test other magically implemented features, like len() and iter()""" |
|
|
@@ -161,13 +155,13 @@ class TestStringMixIn(unittest.TestCase): |
|
|
|
self.assertRaises(IndexError, lambda: str1[11]) |
|
|
|
self.assertRaises(IndexError, lambda: str2[0]) |
|
|
|
|
|
|
|
self.assertTrue("k" in str1) |
|
|
|
self.assertTrue("fake" in str1) |
|
|
|
self.assertTrue("str" in str1) |
|
|
|
self.assertTrue("" in str1) |
|
|
|
self.assertTrue("" in str2) |
|
|
|
self.assertFalse("real" in str1) |
|
|
|
self.assertFalse("s" in str2) |
|
|
|
self.assertIn("k", str1) |
|
|
|
self.assertIn("fake", str1) |
|
|
|
self.assertIn("str", str1) |
|
|
|
self.assertIn("", str1) |
|
|
|
self.assertIn("", str2) |
|
|
|
self.assertNotIn("real", str1) |
|
|
|
self.assertNotIn("s", str2) |
|
|
|
|
|
|
|
def test_other_methods(self): |
|
|
|
"""test the remaining non-magic methods of StringMixIn""" |
|
|
@@ -329,7 +323,7 @@ class TestStringMixIn(unittest.TestCase): |
|
|
|
self.assertEqual("", str15.lower()) |
|
|
|
self.assertEqual("foobar", str16.lower()) |
|
|
|
self.assertEqual("ß", str22.lower()) |
|
|
|
if py3k and not py32: |
|
|
|
if py3k: |
|
|
|
self.assertEqual("", str15.casefold()) |
|
|
|
self.assertEqual("foobar", str16.casefold()) |
|
|
|
self.assertEqual("ss", str22.casefold()) |
|
|
@@ -378,7 +372,7 @@ class TestStringMixIn(unittest.TestCase): |
|
|
|
self.assertEqual(actual, str25.rsplit(None, 3)) |
|
|
|
actual = [" this is a sentence with", "", "whitespace", ""] |
|
|
|
self.assertEqual(actual, str25.rsplit(" ", 3)) |
|
|
|
if py3k and not py32: |
|
|
|
if py3k: |
|
|
|
actual = [" this is a", "sentence", "with", "whitespace"] |
|
|
|
self.assertEqual(actual, str25.rsplit(maxsplit=3)) |
|
|
|
|
|
|
@@ -396,7 +390,7 @@ class TestStringMixIn(unittest.TestCase): |
|
|
|
self.assertEqual(actual, str25.split(None, 3)) |
|
|
|
actual = ["", "", "", "this is a sentence with whitespace "] |
|
|
|
self.assertEqual(actual, str25.split(" ", 3)) |
|
|
|
if py3k and not py32: |
|
|
|
if py3k: |
|
|
|
actual = ["this", "is", "a", "sentence with whitespace "] |
|
|
|
self.assertEqual(actual, str25.split(maxsplit=3)) |
|
|
|
|
|
|
|