diff --git a/mwparserfromhell/string_mixin.py b/mwparserfromhell/string_mixin.py index ac47251..6490051 100644 --- a/mwparserfromhell/string_mixin.py +++ b/mwparserfromhell/string_mixin.py @@ -179,9 +179,10 @@ class StringMixIn(object): def isalpha(self): return self.__unicode__().isalpha() - @inheritdoc - def isdecimal(self): - return self.__unicode__().isdecimal() + if py3k: + @inheritdoc + def isdecimal(self): + return self.__unicode__().isdecimal() @inheritdoc def isdigit(self): diff --git a/tests/test_string_mixin.py b/tests/test_string_mixin.py index 74da9ff..4e4fa68 100644 --- a/tests/test_string_mixin.py +++ b/tests/test_string_mixin.py @@ -174,7 +174,11 @@ class TestStringMixIn(unittest.TestCase): if not py3k: self.assertEquals(fstr, fstr.decode()) - self.assertEquals("πŒ²πŒΏπ„", '\\U00010332\\U0001033f\\U00010344'.decode("unicode_escape")) + actual = '\\U00010332\\U0001033f\\U00010344' + self.assertEquals("πŒ²πŒΏπ„", actual.decode("unicode_escape")) + self.assertEquals("𐌲", '\\U00010332'.decode("unicode_escape")) + self.assertRaises(UnicodeError, "fo".decode, "punycode") + self.assertEquals("", "fo".decode("punycode", "ignore")) self.assertEquals(b"fake string", fstr.encode()) self.assertEquals(b"\xF0\x90\x8C\xB2\xF0\x90\x8C\xBF\xF0\x90\x8D\x84", @@ -187,8 +191,40 @@ class TestStringMixIn(unittest.TestCase): self.assertTrue(fstr.endswith("ing")) self.assertFalse(fstr.endswith("ingh")) + self.assertEquals("fake string", fstr) + self.assertEquals(" foobar", "\tfoobar".expandtabs()) + self.assertEquals(" foobar", "\tfoobar".expandtabs(4)) + + self.assertEquals(3, fstr.find("e")) + self.assertEquals(-1, fstr.find("z")) + self.assertEquals(7, fstr.find("r", 7)) + self.assertEquals(-1, fstr.find("r", 8)) + self.assertEquals(7, fstr.find("r", 5, 9)) + self.assertEquals(-1, fstr.find("r", 5, 7)) + + self.assertEquals("fake string", fstr.format()) + self.assertEquals("foobarbaz", "foo{0}baz".format("bar")) + self.assertEquals("foobarbaz", "foo{abc}baz".format(abc="bar")) + self.assertEquals("foobarbazbuzz", + "foo{0}{abc}buzz".format("bar", abc="baz")) + self.assertRaises(IndexError, "{0}{1}".format, "abc") + + self.assertEquals(3, fstr.index("e")) + self.assertRaises(ValueError, fstr.index, "z") + self.assertEquals(7, fstr.index("r", 7)) + self.assertRaises(ValueError, fstr.index, "r", 8) + self.assertEquals(7, fstr.index("r", 5, 9)) + self.assertRaises(ValueError, fstr.index, "r", 5, 7) + + self.assertTrue("foobar".isalnum()) + self.assertTrue("foobar123".isalnum()) + self.assertFalse("foo bar".isalnum()) + + self.assertTrue("foobar".isalpha()) + self.assertFalse("foobar123".isalpha()) + self.assertFalse("foo bar".isalpha()) + methods = [ - "expandtabs", "find", "format", "index", "isalnum", "isalpha", "isdecimal", "isdigit", "islower", "isnumeric", "isspace", "istitle", "isupper", "join", "ljust", "lstrip", "partition", "replace", "rfind", "rindex", "rjust", "rpartition", "rsplit",