Skip to content

Instantly share code, notes, and snippets.

@earwig
Created September 2, 2013 07:17
Show Gist options
  • Save earwig/6410005 to your computer and use it in GitHub Desktop.
Save earwig/6410005 to your computer and use it in GitHub Desktop.
diff --git a/mwparserfromhell/compat.py b/mwparserfromhell/compat.py
index a142128..1e713fd 100644
--- a/mwparserfromhell/compat.py
+++ b/mwparserfromhell/compat.py
@@ -10,8 +10,9 @@ types are meant to be imported directly from within the parser's modules.
import sys
-py3k = sys.version_info.major == 3
-py32 = py3k and sys.version_info.minor == 2
+py26 = sys.version_info[0] == 2 and sys.version_info[1] == 6
+py3k = sys.version_info[0] == 3
+py32 = py3k and sys.version_info[1] == 2
if py3k:
bytes = bytes
diff --git a/mwparserfromhell/parser/tokenizer.py b/mwparserfromhell/parser/tokenizer.py
index eb4c571..586798d 100644
--- a/mwparserfromhell/parser/tokenizer.py
+++ b/mwparserfromhell/parser/tokenizer.py
@@ -620,7 +620,10 @@ class Tokenizer(object):
self._emit_first(tokens.TagAttrStart(pad_first=buf["first"],
pad_before_eq=buf["before_eq"], pad_after_eq=buf["after_eq"]))
self._emit_all(self._pop())
- data.padding_buffer = {key: "" for key in data.padding_buffer}
+ temp = {}
+ for key in data.padding_buffer:
+ temp[key] = ""
+ data.padding_buffer = temp
def _handle_tag_space(self, data, text):
"""Handle whitespace (*text*) inside of an HTML open tag."""
diff --git a/mwparserfromhell/string_mixin.py b/mwparserfromhell/string_mixin.py
index c52d4ca..3fb57fd 100644
--- a/mwparserfromhell/string_mixin.py
+++ b/mwparserfromhell/string_mixin.py
@@ -27,7 +27,7 @@ interface for the ``unicode`` type (``str`` on py3k) in a dynamic manner.
from __future__ import unicode_literals
-from .compat import py3k, py32, str
+from .compat import py26, py3k, py32, str
__all__ = ["StringMixIn"]
@@ -138,29 +138,55 @@ class StringMixIn(object):
@inheritdoc
def count(self, sub, start=None, end=None):
+ if end is None:
+ if start is None:
+ return self.__unicode__().count(sub)
+ return self.__unicode__().count(sub, start)
return self.__unicode__().count(sub, start, end)
if not py3k:
+ if py26:
+ @inheritdoc
+ def decode(self, encoding=None, errors=None):
+ if errors is None:
+ if encoding is None:
+ return self.__unicode__().decode()
+ return self.__unicode__().decode(encoding)
+ return self.__unicode__().decode(encoding, errors)
+ else:
+ @inheritdoc
+ def decode(self, encoding=None, errors=None):
+ kwargs = {}
+ if encoding is not None:
+ kwargs["encoding"] = encoding
+ if errors is not None:
+ kwargs["errors"] = errors
+ return self.__unicode__().decode(**kwargs)
+
+ if py26:
@inheritdoc
- def decode(self, encoding=None, errors=None):
+ def encode(self, encoding=None, errors=None):
+ if errors is None:
+ if encoding is None:
+ return self.__unicode__().encode()
+ return self.__unicode__().encode(encoding)
+ return self.__unicode__().encode(encoding, errors)
+ else:
+ @inheritdoc
+ def encode(self, encoding=None, errors=None):
kwargs = {}
if encoding is not None:
kwargs["encoding"] = encoding
if errors is not None:
kwargs["errors"] = errors
- return self.__unicode__().decode(**kwargs)
-
- @inheritdoc
- def encode(self, encoding=None, errors=None):
- kwargs = {}
- if encoding is not None:
- kwargs["encoding"] = encoding
- if errors is not None:
- kwargs["errors"] = errors
- return self.__unicode__().encode(**kwargs)
+ return self.__unicode__().encode(**kwargs)
@inheritdoc
def endswith(self, prefix, start=None, end=None):
+ if end is None:
+ if start is None:
+ return self.__unicode__().endswith(prefix)
+ return self.__unicode__().endswith(prefix, start)
return self.__unicode__().endswith(prefix, start, end)
@inheritdoc
@@ -171,6 +197,10 @@ class StringMixIn(object):
@inheritdoc
def find(self, sub, start=None, end=None):
+ if end is None:
+ if start is None:
+ return self.__unicode__().find(sub)
+ return self.__unicode__().find(sub, start)
return self.__unicode__().find(sub, start, end)
@inheritdoc
@@ -184,6 +214,10 @@ class StringMixIn(object):
@inheritdoc
def index(self, sub, start=None, end=None):
+ if end is None:
+ if start is None:
+ return self.__unicode__().index(sub)
+ return self.__unicode__().index(sub, start)
return self.__unicode__().index(sub, start, end)
@inheritdoc
@@ -272,10 +306,18 @@ class StringMixIn(object):
@inheritdoc
def rfind(self, sub, start=None, end=None):
+ if end is None:
+ if start is None:
+ return self.__unicode__().rfind(sub)
+ return self.__unicode__().rfind(sub, start)
return self.__unicode__().rfind(sub, start, end)
@inheritdoc
def rindex(self, sub, start=None, end=None):
+ if end is None:
+ if start is None:
+ return self.__unicode__().rindex(sub)
+ return self.__unicode__().rindex(sub, start)
return self.__unicode__().rindex(sub, start, end)
@inheritdoc
@@ -336,6 +378,10 @@ class StringMixIn(object):
@inheritdoc
def startswith(self, prefix, start=None, end=None):
+ if end is None:
+ if start is None:
+ return self.__unicode__().startswith(prefix)
+ return self.__unicode__().startswith(prefix, start)
return self.__unicode__().startswith(prefix, start, end)
@inheritdoc
diff --git a/tests/_test_tree_equality.py b/tests/_test_tree_equality.py
index 3267b45..a487483 100644
--- a/tests/_test_tree_equality.py
+++ b/tests/_test_tree_equality.py
@@ -62,7 +62,7 @@ class TreeEqualityTestCase(TestCase):
}
for nodetype in registry:
if isinstance(expected, nodetype):
- self.assertIsInstance(actual, nodetype)
+ self.assertTrue(isinstance(actual, nodetype))
registry[nodetype](expected, actual)
def assertArgumentNodeEqual(self, expected, actual):
@@ -71,7 +71,7 @@ class TreeEqualityTestCase(TestCase):
if expected.default is not None:
self.assertWikicodeEqual(expected.default, actual.default)
else:
- self.assertIs(None, actual.default)
+ self.assertTrue(None is actual.default)
def assertCommentNodeEqual(self, expected, actual):
"""Assert that two Comment nodes have the same data."""
@@ -85,8 +85,8 @@ class TreeEqualityTestCase(TestCase):
def assertHTMLEntityNodeEqual(self, expected, actual):
"""Assert that two HTMLEntity nodes have the same data."""
self.assertEqual(expected.value, actual.value)
- self.assertIs(expected.named, actual.named)
- self.assertIs(expected.hexadecimal, actual.hexadecimal)
+ self.assertTrue(expected.named is actual.named)
+ self.assertTrue(expected.hexadecimal is actual.hexadecimal)
self.assertEqual(expected.hex_char, actual.hex_char)
def assertTagNodeEqual(self, expected, actual):
@@ -102,14 +102,14 @@ class TreeEqualityTestCase(TestCase):
self.assertWikicodeEqual(exp_attr.name, act_attr.name)
if exp_attr.value is not None:
self.assertWikicodeEqual(exp_attr.value, act_attr.value)
- self.assertIs(exp_attr.quoted, act_attr.quoted)
+ self.assertTrue(exp_attr.quoted is act_attr.quoted)
self.assertEqual(exp_attr.pad_first, act_attr.pad_first)
self.assertEqual(exp_attr.pad_before_eq, act_attr.pad_before_eq)
self.assertEqual(exp_attr.pad_after_eq, act_attr.pad_after_eq)
- self.assertIs(expected.wiki_markup, actual.wiki_markup)
- self.assertIs(expected.self_closing, actual.self_closing)
- self.assertIs(expected.invalid, actual.invalid)
- self.assertIs(expected.implicit, actual.implicit)
+ self.assertTrue(expected.wiki_markup is actual.wiki_markup)
+ self.assertTrue(expected.self_closing is actual.self_closing)
+ self.assertTrue(expected.invalid is actual.invalid)
+ self.assertTrue(expected.implicit is actual.implicit)
self.assertEqual(expected.padding, actual.padding)
self.assertWikicodeEqual(expected.closing_tag, actual.closing_tag)
@@ -123,7 +123,7 @@ class TreeEqualityTestCase(TestCase):
act_param = actual.params[i]
self.assertWikicodeEqual(exp_param.name, act_param.name)
self.assertWikicodeEqual(exp_param.value, act_param.value)
- self.assertIs(exp_param.showkey, act_param.showkey)
+ self.assertTrue(exp_param.showkey is act_param.showkey)
def assertTextNodeEqual(self, expected, actual):
"""Assert that two Text nodes have the same data."""
@@ -135,11 +135,11 @@ class TreeEqualityTestCase(TestCase):
if expected.text is not None:
self.assertWikicodeEqual(expected.text, actual.text)
else:
- self.assertIs(None, actual.text)
+ self.assertTrue(None is actual.text)
def assertWikicodeEqual(self, expected, actual):
"""Assert that two Wikicode objects have the same data."""
- self.assertIsInstance(actual, Wikicode)
+ self.assertTrue(isinstance(actual, Wikicode))
length = len(expected.nodes)
self.assertEqual(length, len(actual.nodes))
for i in range(length):
diff --git a/tests/test_argument.py b/tests/test_argument.py
index 8191804..47a1b8a 100644
--- a/tests/test_argument.py
+++ b/tests/test_argument.py
@@ -61,7 +61,7 @@ class TestArgument(TreeEqualityTestCase):
node2 = Argument(wraptext("foo"), wraptext("bar"))
for a in (True, False):
for b in (True, False):
- self.assertIs(None, node.__strip__(a, b))
+ self.assertTrue(None is node.__strip__(a, b))
self.assertEqual("bar", node2.__strip__(a, b))
def test_showtree(self):
@@ -84,8 +84,8 @@ class TestArgument(TreeEqualityTestCase):
name = wraptext("foobar")
node1 = Argument(name)
node2 = Argument(name, wraptext("baz"))
- self.assertIs(name, node1.name)
- self.assertIs(name, node2.name)
+ self.assertTrue(name is node1.name)
+ self.assertTrue(name is node2.name)
node1.name = "héhehé"
node2.name = "héhehé"
self.assertWikicodeEqual(wraptext("héhehé"), node1.name)
@@ -96,12 +96,12 @@ class TestArgument(TreeEqualityTestCase):
default = wraptext("baz")
node1 = Argument(wraptext("foobar"))
node2 = Argument(wraptext("foobar"), default)
- self.assertIs(None, node1.default)
- self.assertIs(default, node2.default)
+ self.assertTrue(None is node1.default)
+ self.assertTrue(default is node2.default)
node1.default = "buzz"
node2.default = None
self.assertWikicodeEqual(wraptext("buzz"), node1.default)
- self.assertIs(None, node2.default)
+ self.assertTrue(None is node2.default)
if __name__ == "__main__":
unittest.main(verbosity=2)
diff --git a/tests/test_attribute.py b/tests/test_attribute.py
index f34c670..85466a5 100644
--- a/tests/test_attribute.py
+++ b/tests/test_attribute.py
@@ -49,7 +49,7 @@ class TestAttribute(TreeEqualityTestCase):
"""test getter/setter for the name attribute"""
name = wraptext("id")
node = Attribute(name, wraptext("bar"))
- self.assertIs(name, node.name)
+ self.assertTrue(name is node.name)
node.name = "{{id}}"
self.assertWikicodeEqual(wrap([Template(wraptext("id"))]), node.name)
@@ -57,11 +57,11 @@ class TestAttribute(TreeEqualityTestCase):
"""test getter/setter for the value attribute"""
value = wraptext("foo")
node = Attribute(wraptext("id"), value)
- self.assertIs(value, node.value)
+ self.assertTrue(value is node.value)
node.value = "{{bar}}"
self.assertWikicodeEqual(wrap([Template(wraptext("bar"))]), node.value)
node.value = None
- self.assertIs(None, node.value)
+ self.assertTrue(None is node.value)
def test_quoted(self):
"""test getter/setter for the quoted attribute"""
diff --git a/tests/test_comment.py b/tests/test_comment.py
index 44225a2..f015d6a 100644
--- a/tests/test_comment.py
+++ b/tests/test_comment.py
@@ -48,7 +48,7 @@ class TestComment(TreeEqualityTestCase):
node = Comment("foobar")
for a in (True, False):
for b in (True, False):
- self.assertIs(None, node.__strip__(a, b))
+ self.assertTrue(None is node.__strip__(a, b))
def test_showtree(self):
"""test Comment.__showtree__()"""
diff --git a/tests/test_ctokenizer.py b/tests/test_ctokenizer.py
index 2374516..1054d15 100644
--- a/tests/test_ctokenizer.py
+++ b/tests/test_ctokenizer.py
@@ -30,19 +30,20 @@ except ImportError:
from ._test_tokenizer import TokenizerTestCase
[email protected](CTokenizer, "C tokenizer not available")
-class TestCTokenizer(TokenizerTestCase, unittest.TestCase):
- """Test cases for the C tokenizer."""
+# 2.6: no support for test skipping, so we'll just ignore it completely
+if CTokenizer:
+ class TestCTokenizer(TokenizerTestCase, unittest.TestCase):
+ """Test cases for the C tokenizer."""
- @classmethod
- def setUpClass(cls):
- cls.tokenizer = CTokenizer
+ # 2.6: not ideal; should be a classmethod
+ def setUp(self):
+ self.tokenizer = CTokenizer
- if not TokenizerTestCase.skip_others:
- def test_uses_c(self):
- """make sure the C tokenizer identifies as using a C extension"""
- self.assertTrue(CTokenizer.USES_C)
- self.assertTrue(CTokenizer().USES_C)
+ if not TokenizerTestCase.skip_others:
+ def test_uses_c(self):
+ """make sure the C tokenizer identifies as using a C extension"""
+ self.assertTrue(CTokenizer.USES_C)
+ self.assertTrue(CTokenizer().USES_C)
if __name__ == "__main__":
unittest.main(verbosity=2)
diff --git a/tests/test_external_link.py b/tests/test_external_link.py
index 13a82bf..858de30 100644
--- a/tests/test_external_link.py
+++ b/tests/test_external_link.py
@@ -94,8 +94,8 @@ class TestExternalLink(TreeEqualityTestCase):
url = wraptext("http://example.com/")
node1 = ExternalLink(url, brackets=False)
node2 = ExternalLink(url, wraptext("Example"))
- self.assertIs(url, node1.url)
- self.assertIs(url, node2.url)
+ self.assertTrue(url is node1.url)
+ self.assertTrue(url is node2.url)
node1.url = "mailto:héhehé@spam.com"
node2.url = "mailto:héhehé@spam.com"
self.assertWikicodeEqual(wraptext("mailto:héhehé@spam.com"), node1.url)
@@ -106,10 +106,10 @@ class TestExternalLink(TreeEqualityTestCase):
title = wraptext("Example!")
node1 = ExternalLink(wraptext("http://example.com/"), brackets=False)
node2 = ExternalLink(wraptext("http://example.com/"), title)
- self.assertIs(None, node1.title)
- self.assertIs(title, node2.title)
+ self.assertTrue(None is node1.title)
+ self.assertTrue(title is node2.title)
node2.title = None
- self.assertIs(None, node2.title)
+ self.assertTrue(None is node2.title)
node2.title = "My Website"
self.assertWikicodeEqual(wraptext("My Website"), node2.title)
diff --git a/tests/test_heading.py b/tests/test_heading.py
index 7a65872..a1c374e 100644
--- a/tests/test_heading.py
+++ b/tests/test_heading.py
@@ -72,7 +72,7 @@ class TestHeading(TreeEqualityTestCase):
"""test getter/setter for the title attribute"""
title = wraptext("foobar")
node = Heading(title, 3)
- self.assertIs(title, node.title)
+ self.assertTrue(title is node.title)
node.title = "héhehé"
self.assertWikicodeEqual(wraptext("héhehé"), node.title)
diff --git a/tests/test_parameter.py b/tests/test_parameter.py
index 4786e12..4bbbf16 100644
--- a/tests/test_parameter.py
+++ b/tests/test_parameter.py
@@ -45,8 +45,8 @@ class TestParameter(TreeEqualityTestCase):
name2 = wraptext("foobar")
node1 = Parameter(name1, wraptext("foobar"), showkey=False)
node2 = Parameter(name2, wraptext("baz"))
- self.assertIs(name1, node1.name)
- self.assertIs(name2, node2.name)
+ self.assertTrue(name1 is node1.name)
+ self.assertTrue(name2 is node2.name)
node1.name = "héhehé"
node2.name = "héhehé"
self.assertWikicodeEqual(wraptext("héhehé"), node1.name)
@@ -56,7 +56,7 @@ class TestParameter(TreeEqualityTestCase):
"""test getter/setter for the value attribute"""
value = wraptext("bar")
node = Parameter(wraptext("foo"), value)
- self.assertIs(value, node.value)
+ self.assertTrue(value is node.value)
node.value = "héhehé"
self.assertWikicodeEqual(wraptext("héhehé"), node.value)
diff --git a/tests/test_pytokenizer.py b/tests/test_pytokenizer.py
index 0211e7f..dcd48d6 100644
--- a/tests/test_pytokenizer.py
+++ b/tests/test_pytokenizer.py
@@ -30,9 +30,9 @@ from ._test_tokenizer import TokenizerTestCase
class TestPyTokenizer(TokenizerTestCase, unittest.TestCase):
"""Test cases for the Python tokenizer."""
- @classmethod
- def setUpClass(cls):
- cls.tokenizer = Tokenizer
+ # 2.6: not ideal; should be a classmethod
+ def setUp(self):
+ self.tokenizer = Tokenizer
if not TokenizerTestCase.skip_others:
def test_uses_c(self):
diff --git a/tests/test_string_mixin.py b/tests/test_string_mixin.py
index 5ee857c..ec1bd41 100644
--- a/tests/test_string_mixin.py
+++ b/tests/test_string_mixin.py
@@ -25,7 +25,7 @@ from sys import getdefaultencoding
from types import GeneratorType
import unittest
-from mwparserfromhell.compat import bytes, py3k, py32, str
+from mwparserfromhell.compat import bytes, py26, py3k, py32, str
from mwparserfromhell.string_mixin import StringMixIn
from .compat import range
@@ -73,12 +73,12 @@ class TestStringMixIn(unittest.TestCase):
else:
self.assertEqual(repr(fstr), b"u'fake string'")
- self.assertIsInstance(str(fstr), str)
- self.assertIsInstance(bytes(fstr), bytes)
+ self.assertTrue(isinstance(str(fstr), str))
+ self.assertTrue(isinstance(bytes(fstr), bytes))
if py3k:
- self.assertIsInstance(repr(fstr), str)
+ self.assertTrue(isinstance(repr(fstr), str))
else:
- self.assertIsInstance(repr(fstr), bytes)
+ self.assertTrue(isinstance(repr(fstr), bytes))
def test_comparisons(self):
"""make sure comparison operators work"""
@@ -139,8 +139,8 @@ class TestStringMixIn(unittest.TestCase):
gen1 = iter(str1)
gen2 = iter(str2)
- self.assertIsInstance(gen1, GeneratorType)
- self.assertIsInstance(gen2, GeneratorType)
+ self.assertTrue(isinstance(gen1, GeneratorType))
+ self.assertTrue(isinstance(gen2, GeneratorType))
out = []
for i in range(len(str1)):
@@ -202,15 +202,17 @@ class TestStringMixIn(unittest.TestCase):
self.assertEqual(actual, str3.encode())
self.assertRaises(UnicodeEncodeError, str3.encode, "ascii")
self.assertRaises(UnicodeEncodeError, str3.encode, "ascii", "strict")
- if getdefaultencoding() == "ascii":
- self.assertRaises(UnicodeEncodeError, str3.encode, errors="strict")
- elif getdefaultencoding() == "utf-8":
- self.assertEqual(actual, str3.encode(errors="strict"))
- self.assertEqual(b"", str3.encode("ascii", "ignore"))
- if getdefaultencoding() == "ascii":
- self.assertEqual(b"", str3.encode(errors="ignore"))
- elif getdefaultencoding() == "utf-8":
- self.assertEqual(actual, str3.encode(errors="ignore"))
+ # 2.6: can't pass keyword arguments to encode
+ if not py26:
+ if getdefaultencoding() == "ascii":
+ self.assertRaises(UnicodeEncodeError, str3.encode, errors="strict")
+ elif getdefaultencoding() == "utf-8":
+ self.assertEqual(actual, str3.encode(errors="strict"))
+ self.assertEqual(b"", str3.encode("ascii", "ignore"))
+ if getdefaultencoding() == "ascii":
+ self.assertEqual(b"", str3.encode(errors="ignore"))
+ elif getdefaultencoding() == "utf-8":
+ self.assertEqual(actual, str3.encode(errors="ignore"))
self.assertTrue(str1.endswith("ing"))
self.assertFalse(str1.endswith("ingh"))
diff --git a/tests/test_tag.py b/tests/test_tag.py
index 5ef92a5..cfe041d 100644
--- a/tests/test_tag.py
+++ b/tests/test_tag.py
@@ -134,8 +134,8 @@ class TestTag(TreeEqualityTestCase):
"""test getter/setter for the tag attribute"""
tag = wraptext("ref")
node = Tag(tag, wraptext("text"))
- self.assertIs(tag, node.tag)
- self.assertIs(tag, node.closing_tag)
+ self.assertTrue(tag is node.tag)
+ self.assertTrue(tag is node.closing_tag)
node.tag = "span"
self.assertWikicodeEqual(wraptext("span"), node.tag)
self.assertWikicodeEqual(wraptext("span"), node.closing_tag)
@@ -145,7 +145,7 @@ class TestTag(TreeEqualityTestCase):
"""test getter/setter for the contents attribute"""
contents = wraptext("text")
node = Tag(wraptext("ref"), contents)
- self.assertIs(contents, node.contents)
+ self.assertTrue(contents is node.contents)
node.contents = "text and a {{template}}"
parsed = wrap([Text("text and a "), Template(wraptext("template"))])
self.assertWikicodeEqual(parsed, node.contents)
@@ -157,12 +157,12 @@ class TestTag(TreeEqualityTestCase):
node1 = Tag(wraptext("ref"), wraptext("foo"))
node2 = Tag(wraptext("ref"), wraptext("foo"), attrs)
self.assertEqual([], node1.attributes)
- self.assertIs(attrs, node2.attributes)
+ self.assertTrue(attrs is node2.attributes)
def test_wiki_markup(self):
"""test getter/setter for the wiki_markup attribute"""
node = Tag(wraptext("i"), wraptext("italic text"))
- self.assertIs(None, node.wiki_markup)
+ self.assertTrue(None is node.wiki_markup)
node.wiki_markup = "''"
self.assertEqual("''", node.wiki_markup)
self.assertEqual("''italic text''", node)
@@ -219,7 +219,7 @@ class TestTag(TreeEqualityTestCase):
"""test getter/setter for the closing_tag attribute"""
tag = wraptext("ref")
node = Tag(tag, wraptext("foobar"))
- self.assertIs(tag, node.closing_tag)
+ self.assertTrue(tag is node.closing_tag)
node.closing_tag = "ref {{ignore me}}"
parsed = wrap([Text("ref "), Template(wraptext("ignore me"))])
self.assertWikicodeEqual(parsed, node.closing_tag)
@@ -251,22 +251,22 @@ class TestTag(TreeEqualityTestCase):
"""test Tag.get()"""
attrs = [agen("name", "foo")]
node = Tag(wraptext("ref"), wraptext("cite"), attrs)
- self.assertIs(attrs[0], node.get("name"))
- self.assertIs(attrs[0], node.get(" name "))
- self.assertIs(attrs[0], node.get(wraptext("name")))
+ self.assertTrue(attrs[0] is node.get("name"))
+ self.assertTrue(attrs[0] is node.get(" name "))
+ self.assertTrue(attrs[0] is node.get(wraptext("name")))
self.assertRaises(ValueError, node.get, "Name")
self.assertRaises(ValueError, node.get, "foo")
attrs = [agen("id", "foo"), agenp("class", "bar", " ", "\n", "\n"),
agen("foo", "bar"), agenpnv("foo", " ", " \n ", " \t")]
node2 = Tag(wraptext("div"), attrs=attrs, self_closing=True)
- self.assertIs(attrs[0], node2.get("id"))
- self.assertIs(attrs[1], node2.get("class"))
- self.assertIs(attrs[1], node2.get(
+ self.assertTrue(attrs[0] is node2.get("id"))
+ self.assertTrue(attrs[1] is node2.get("class"))
+ self.assertTrue(attrs[1] is node2.get(
attrs[1].pad_first + str(attrs[1].name) + attrs[1].pad_before_eq))
- self.assertIs(attrs[3], node2.get(attrs[3]))
- self.assertIs(attrs[3], node2.get(str(attrs[3])))
- self.assertIs(attrs[3], node2.get(" foo"))
+ self.assertTrue(attrs[3] is node2.get(attrs[3]))
+ self.assertTrue(attrs[3] is node2.get(str(attrs[3])))
+ self.assertTrue(attrs[3] is node2.get(" foo"))
self.assertRaises(ValueError, node2.get, "idclass")
self.assertRaises(ValueError, node2.get, "id class")
self.assertRaises(ValueError, node2.get, "id=foo")
diff --git a/tests/test_template.py b/tests/test_template.py
index 26a2e39..cd77bfd 100644
--- a/tests/test_template.py
+++ b/tests/test_template.py
@@ -100,8 +100,8 @@ class TestTemplate(TreeEqualityTestCase):
name = wraptext("foobar")
node1 = Template(name)
node2 = Template(name, [pgenh("1", "bar")])
- self.assertIs(name, node1.name)
- self.assertIs(name, node2.name)
+ self.assertTrue(name is node1.name)
+ self.assertTrue(name is node2.name)
node1.name = "asdf"
node2.name = "téstïng"
self.assertWikicodeEqual(wraptext("asdf"), node1.name)
@@ -113,7 +113,7 @@ class TestTemplate(TreeEqualityTestCase):
plist = [pgenh("1", "bar"), pgens("abc", "def")]
node2 = Template(wraptext("foo"), plist)
self.assertEqual([], node1.params)
- self.assertIs(plist, node2.params)
+ self.assertTrue(plist is node2.params)
def test_has(self):
"""test Template.has()"""
@@ -145,12 +145,12 @@ class TestTemplate(TreeEqualityTestCase):
node4p1 = pgens(" b", " ")
node4 = Template(wraptext("foo"), [pgenh("1", "a"), node4p1])
self.assertRaises(ValueError, node1.get, "foobar")
- self.assertIs(node2p1, node2.get(1))
- self.assertIs(node2p2, node2.get("abc"))
+ self.assertTrue(node2p1 is node2.get(1))
+ self.assertTrue(node2p2 is node2.get("abc"))
self.assertRaises(ValueError, node2.get, "def")
- self.assertIs(node3p1, node3.get("b"))
- self.assertIs(node3p2, node3.get("1"))
- self.assertIs(node4p1, node4.get("b "))
+ self.assertTrue(node3p1 is node3.get("b"))
+ self.assertTrue(node3p2 is node3.get("1"))
+ self.assertTrue(node4p1 is node4.get("b "))
def test_add(self):
"""test Template.add()"""
@@ -270,7 +270,7 @@ class TestTemplate(TreeEqualityTestCase):
self.assertEqual("{{a|b=c|d|e=f}}", node1)
self.assertEqual("{{a|b=c|d|g}}", node2)
self.assertEqual("{{a|b=c|d|e=foo|bar}}", node3)
- self.assertIsInstance(node3.params[2].value.get(1), HTMLEntity)
+ self.assertTrue(isinstance(node3.params[2].value.get(1), HTMLEntity))
self.assertEqual("{{a|e=f|b=c|d}}", node4)
self.assertEqual("{{a|b=c|f=g| d =e}}", node5)
self.assertEqual("{{a|b=c|b=d|f=g|b=e}}", node6)
@@ -280,7 +280,7 @@ class TestTemplate(TreeEqualityTestCase):
self.assertEqual("{{a|b=c|e}}", node10)
self.assertEqual("{{a|b=c|d=foo=bar}}", node11)
self.assertEqual("{{a|b=c|foo=bar}}", node12)
- self.assertIsInstance(node12.params[1].value.get(1), HTMLEntity)
+ self.assertTrue(isinstance(node12.params[1].value.get(1), HTMLEntity))
self.assertEqual("{{a|\nb = c|\nd = e|\nf = g|\nh = i}}", node13)
self.assertEqual("{{a\n|b =c\n|d = e|f =g\n|h = i\n|j =k\n}}", node14)
self.assertEqual("{{a|b = c\n|\nd = e|\nf =g |h =i}}", node15)
@@ -297,13 +297,13 @@ class TestTemplate(TreeEqualityTestCase):
self.assertEqual("{{a|b|c|4=d|5=e|6=f}}", node26)
self.assertEqual("{{a|b|c=foo=bar}}", node27)
self.assertEqual("{{a|b|foo=bar}}", node28)
- self.assertIsInstance(node28.params[1].value.get(1), HTMLEntity)
+ self.assertTrue(isinstance(node28.params[1].value.get(1), HTMLEntity))
self.assertEqual("{{a|b=d}}", node29)
self.assertEqual("{{a|foo=bar}}", node30)
- self.assertIsInstance(node30.params[0].value.get(1), HTMLEntity)
+ self.assertTrue(isinstance(node30.params[0].value.get(1), HTMLEntity))
self.assertEqual("{{a|1=foo=bar}}", node31)
self.assertEqual("{{a|foo=bar}}", node32)
- self.assertIsInstance(node32.params[0].value.get(1), HTMLEntity)
+ self.assertTrue(isinstance(node32.params[0].value.get(1), HTMLEntity))
self.assertEqual("{{a|\nb = c|\nd = foo|\nf = g}}", node33)
self.assertEqual("{{a\n|b =c\n|d = e|f =foo\n|h = i\n}}", node34)
self.assertEqual("{{a|b = c\n|\nd = e|\nf =foo }}", node35)
diff --git a/tests/test_text.py b/tests/test_text.py
index 35ac340..21fe240 100644
--- a/tests/test_text.py
+++ b/tests/test_text.py
@@ -48,7 +48,7 @@ class TestText(unittest.TestCase):
node = Text("foobar")
for a in (True, False):
for b in (True, False):
- self.assertIs(node, node.__strip__(a, b))
+ self.assertTrue(node is node.__strip__(a, b))
def test_showtree(self):
"""test Text.__showtree__()"""
@@ -66,10 +66,10 @@ class TestText(unittest.TestCase):
"""test getter/setter for the value attribute"""
node = Text("foobar")
self.assertEqual("foobar", node.value)
- self.assertIsInstance(node.value, str)
+ self.assertTrue(isinstance(node.value, str))
node.value = "héhéhé"
self.assertEqual("héhéhé", node.value)
- self.assertIsInstance(node.value, str)
+ self.assertTrue(isinstance(node.value, str))
if __name__ == "__main__":
unittest.main(verbosity=2)
diff --git a/tests/test_tokens.py b/tests/test_tokens.py
index 2048bb9..8db6be7 100644
--- a/tests/test_tokens.py
+++ b/tests/test_tokens.py
@@ -34,8 +34,8 @@ class TestTokens(unittest.TestCase):
for name in tokens.__all__:
klass = getattr(tokens, name)
self.assertTrue(issubclass(klass, tokens.Token))
- self.assertIsInstance(klass(), klass)
- self.assertIsInstance(klass(), tokens.Token)
+ self.assertTrue(isinstance(klass(), klass))
+ self.assertTrue(isinstance(klass(), tokens.Token))
def test_attributes(self):
"""check that Token attributes can be managed properly"""
diff --git a/tests/test_wikicode.py b/tests/test_wikicode.py
index 14d801c..3a500c3 100644
--- a/tests/test_wikicode.py
+++ b/tests/test_wikicode.py
@@ -53,9 +53,9 @@ class TestWikicode(TreeEqualityTestCase):
L2 = [Text("barfoo"), Template(wraptext("cba"))]
L3 = "abc{{def}}"
code.nodes = L1
- self.assertIs(L1, code.nodes)
+ self.assertTrue(L1 is code.nodes)
code.nodes = L2
- self.assertIs(L2, code.nodes)
+ self.assertTrue(L2 is code.nodes)
code.nodes = L3
self.assertEqual(["abc", "{{def}}"], code.nodes)
self.assertRaises(ValueError, setattr, code, "nodes", object)
@@ -63,8 +63,8 @@ class TestWikicode(TreeEqualityTestCase):
def test_get(self):
"""test Wikicode.get()"""
code = parse("Have a {{template}} and a [[page|link]]")
- self.assertIs(code.nodes[0], code.get(0))
- self.assertIs(code.nodes[2], code.get(2))
+ self.assertTrue(code.nodes[0] is code.get(0))
+ self.assertTrue(code.nodes[2] is code.get(2))
self.assertRaises(IndexError, code.get, 4)
def test_set(self):
@@ -72,7 +72,7 @@ class TestWikicode(TreeEqualityTestCase):
code = parse("Have a {{template}} and a [[page|link]]")
code.set(1, "{{{argument}}}")
self.assertEqual("Have a {{{argument}}} and a [[page|link]]", code)
- self.assertIsInstance(code.get(1), Argument)
+ self.assertTrue(isinstance(code.get(1), Argument))
code.set(2, None)
self.assertEqual("Have a {{{argument}}}[[page|link]]", code)
code.set(-3, "This is an ")
@@ -104,7 +104,7 @@ class TestWikicode(TreeEqualityTestCase):
code.insert(1, "{{{argument}}}")
self.assertEqual(
"Have a {{{argument}}}{{template}} and a [[page|link]]", code)
- self.assertIsInstance(code.get(1), Argument)
+ self.assertTrue(isinstance(code.get(1), Argument))
code.insert(2, None)
self.assertEqual(
"Have a {{{argument}}}{{template}} and a [[page|link]]", code)
@@ -222,7 +222,7 @@ class TestWikicode(TreeEqualityTestCase):
code = parse("Have a {{template}}")
code.append("{{{argument}}}")
self.assertEqual("Have a {{template}}{{{argument}}}", code)
- self.assertIsInstance(code.get(2), Argument)
+ self.assertTrue(isinstance(code.get(2), Argument))
code.append(None)
self.assertEqual("Have a {{template}}{{{argument}}}", code)
code.append(Text(" foo"))
@@ -254,7 +254,7 @@ class TestWikicode(TreeEqualityTestCase):
def test_filter_family(self):
"""test the Wikicode.i?filter() family of functions"""
def genlist(gen):
- self.assertIsInstance(gen, GeneratorType)
+ self.assertTrue(isinstance(gen, GeneratorType))
return list(gen)
ifilter = lambda code: (lambda **kw: genlist(code.ifilter(**kw)))
@@ -263,7 +263,7 @@ class TestWikicode(TreeEqualityTestCase):
self.assertEqual(["a", "{{b}}", "b", "c", "[[d]]", "d", "{{{e}}}",
"e", "{{f}}", "f", "[[g]]", "g"], func())
self.assertEqual(["{{{e}}}"], func(forcetype=Argument))
- self.assertIs(code.get(4), func(forcetype=Argument)[0])
+ self.assertTrue(code.get(4) is func(forcetype=Argument)[0])
self.assertEqual(list("abcdefg"), func(forcetype=Text))
self.assertEqual([], func(forcetype=Heading))
self.assertRaises(TypeError, func, forcetype=True)
@@ -274,7 +274,7 @@ class TestWikicode(TreeEqualityTestCase):
]
for get_filter in funcs:
self.assertEqual(["{{{e}}}"], get_filter("arguments"))
- self.assertIs(code.get(4), get_filter("arguments")[0])
+ self.assertTrue(code.get(4) is get_filter("arguments")[0])
self.assertEqual([], get_filter("comments"))
self.assertEqual([], get_filter("external_links"))
self.assertEqual([], get_filter("headings"))
diff --git a/tests/test_wikilink.py b/tests/test_wikilink.py
index 7851032..8428b81 100644
--- a/tests/test_wikilink.py
+++ b/tests/test_wikilink.py
@@ -84,8 +84,8 @@ class TestWikilink(TreeEqualityTestCase):
title = wraptext("foobar")
node1 = Wikilink(title)
node2 = Wikilink(title, wraptext("baz"))
- self.assertIs(title, node1.title)
- self.assertIs(title, node2.title)
+ self.assertTrue(title is node1.title)
+ self.assertTrue(title is node2.title)
node1.title = "héhehé"
node2.title = "héhehé"
self.assertWikicodeEqual(wraptext("héhehé"), node1.title)
@@ -96,12 +96,12 @@ class TestWikilink(TreeEqualityTestCase):
text = wraptext("baz")
node1 = Wikilink(wraptext("foobar"))
node2 = Wikilink(wraptext("foobar"), text)
- self.assertIs(None, node1.text)
- self.assertIs(text, node2.text)
+ self.assertTrue(None is node1.text)
+ self.assertTrue(text is node2.text)
node1.text = "buzz"
node2.text = None
self.assertWikicodeEqual(wraptext("buzz"), node1.text)
- self.assertIs(None, node2.text)
+ self.assertTrue(None is node2.text)
if __name__ == "__main__":
unittest.main(verbosity=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment