Drop support for EOL Python 2.6, 3.2 and 3.3tags/v0.5.2
@@ -6,4 +6,3 @@ partial_branches = | |||||
pragma: no branch | pragma: no branch | ||||
if py3k: | if py3k: | ||||
if not py3k: | if not py3k: | ||||
if py26: |
@@ -1,16 +1,12 @@ | |||||
language: python | language: python | ||||
python: | python: | ||||
- 2.6 | |||||
- 2.7 | - 2.7 | ||||
- 3.2 | |||||
- 3.3 | |||||
- 3.4 | - 3.4 | ||||
- 3.5 | - 3.5 | ||||
- 3.6 | - 3.6 | ||||
- nightly | - nightly | ||||
sudo: false | sudo: false | ||||
install: | install: | ||||
- if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then pip install coverage==3.7.1; fi | |||||
- pip install coveralls | - pip install coveralls | ||||
- python setup.py build | - python setup.py build | ||||
script: | script: | ||||
@@ -10,9 +10,7 @@ meant to be imported directly from within the parser's modules. | |||||
import sys | import sys | ||||
py26 = (sys.version_info[0] == 2) and (sys.version_info[1] == 6) | |||||
py3k = (sys.version_info[0] == 3) | py3k = (sys.version_info[0] == 3) | ||||
py32 = py3k and (sys.version_info[1] == 2) | |||||
if py3k: | if py3k: | ||||
bytes = bytes | bytes = bytes | ||||
@@ -40,7 +40,7 @@ class Attribute(StringMixIn): | |||||
pad_before_eq="", pad_after_eq="", check_quotes=True): | pad_before_eq="", pad_after_eq="", check_quotes=True): | ||||
super(Attribute, self).__init__() | super(Attribute, self).__init__() | ||||
if check_quotes and not quotes and self._value_needs_quotes(value): | if check_quotes and not quotes and self._value_needs_quotes(value): | ||||
raise ValueError("given value {0!r} requires quotes".format(value)) | |||||
raise ValueError("given value {!r} requires quotes".format(value)) | |||||
self._name = name | self._name = name | ||||
self._value = value | self._value = value | ||||
self._quotes = quotes | self._quotes = quotes | ||||
@@ -79,7 +79,7 @@ class Attribute(StringMixIn): | |||||
"""Coerce a quote type into an acceptable value, or raise an error.""" | """Coerce a quote type into an acceptable value, or raise an error.""" | ||||
orig, quotes = quotes, str(quotes) if quotes else None | orig, quotes = quotes, str(quotes) if quotes else None | ||||
if quotes not in [None, '"', "'"]: | if quotes not in [None, '"', "'"]: | ||||
raise ValueError("{0!r} is not a valid quote type".format(orig)) | |||||
raise ValueError("{!r} is not a valid quote type".format(orig)) | |||||
return quotes | return quotes | ||||
@property | @property | ||||
@@ -41,7 +41,7 @@ class Parameter(StringMixIn): | |||||
def __init__(self, name, value, showkey=True): | def __init__(self, name, value, showkey=True): | ||||
super(Parameter, self).__init__() | super(Parameter, self).__init__() | ||||
if not showkey and not self.can_hide_key(name): | if not showkey and not self.can_hide_key(name): | ||||
raise ValueError("key {0!r} cannot be hidden".format(name)) | |||||
raise ValueError("key {!r} cannot be hidden".format(name)) | |||||
self._name = name | self._name = name | ||||
self._value = value | self._value = value | ||||
self._showkey = showkey | self._showkey = showkey | ||||
@@ -53,10 +53,10 @@ class HTMLEntity(Node): | |||||
def __unicode__(self): | def __unicode__(self): | ||||
if self.named: | if self.named: | ||||
return "&{0};".format(self.value) | |||||
return "&{};".format(self.value) | |||||
if self.hexadecimal: | if self.hexadecimal: | ||||
return "&#{0}{1};".format(self.hex_char, self.value) | |||||
return "&#{0};".format(self.value) | |||||
return "&#{}{};".format(self.hex_char, self.value) | |||||
return "&#{};".format(self.value) | |||||
def __strip__(self, **kwargs): | def __strip__(self, **kwargs): | ||||
if kwargs.get("normalize"): | if kwargs.get("normalize"): | ||||
@@ -35,7 +35,7 @@ class ParserError(Exception): | |||||
can happen. Its appearance indicates a bug. | can happen. Its appearance indicates a bug. | ||||
""" | """ | ||||
def __init__(self, extra): | def __init__(self, extra): | ||||
msg = "This is a bug and should be reported. Info: {0}.".format(extra) | |||||
msg = "This is a bug and should be reported. Info: {}.".format(extra) | |||||
super(ParserError, self).__init__(msg) | super(ParserError, self).__init__(msg) | ||||
@@ -44,7 +44,7 @@ class Token(dict): | |||||
args.append(key + "=" + repr(value[:97] + "...")) | args.append(key + "=" + repr(value[:97] + "...")) | ||||
else: | else: | ||||
args.append(key + "=" + repr(value)) | args.append(key + "=" + repr(value)) | ||||
return "{0}({1})".format(type(self).__name__, ", ".join(args)) | |||||
return "{}({})".format(type(self).__name__, ", ".join(args)) | |||||
def __eq__(self, other): | def __eq__(self, other): | ||||
return isinstance(other, type(self)) and dict.__eq__(self, other) | return isinstance(other, type(self)) and dict.__eq__(self, other) | ||||
@@ -28,7 +28,7 @@ interface for the ``unicode`` type (``str`` on py3k) in a dynamic manner. | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
from sys import getdefaultencoding | from sys import getdefaultencoding | ||||
from .compat import bytes, py26, py3k, str | |||||
from .compat import bytes, py3k, str | |||||
__all__ = ["StringMixIn"] | __all__ = ["StringMixIn"] | ||||
@@ -109,21 +109,12 @@ class StringMixIn(object): | |||||
def __getattr__(self, attr): | def __getattr__(self, attr): | ||||
if not hasattr(str, attr): | if not hasattr(str, attr): | ||||
raise AttributeError("{0!r} object has no attribute {1!r}".format( | |||||
raise AttributeError("{!r} object has no attribute {!r}".format( | |||||
type(self).__name__, attr)) | type(self).__name__, attr)) | ||||
return getattr(self.__unicode__(), attr) | return getattr(self.__unicode__(), attr) | ||||
if py3k: | if py3k: | ||||
maketrans = str.maketrans # Static method can't rely on __getattr__ | maketrans = str.maketrans # Static method can't rely on __getattr__ | ||||
if py26: | |||||
@inheritdoc | |||||
def encode(self, encoding=None, errors=None): | |||||
if encoding is None: | |||||
encoding = getdefaultencoding() | |||||
if errors is not None: | |||||
return self.__unicode__().encode(encoding, errors) | |||||
return self.__unicode__().encode(encoding) | |||||
del inheritdoc | del inheritdoc |
@@ -80,7 +80,7 @@ class MemoryTest(object): | |||||
raw = raw.encode("raw_unicode_escape") | raw = raw.encode("raw_unicode_escape") | ||||
data["input"] = raw.decode("unicode_escape") | data["input"] = raw.decode("unicode_escape") | ||||
number = str(counter).zfill(digits) | number = str(counter).zfill(digits) | ||||
fname = "test_{0}{1}_{2}".format(name, number, data["name"]) | |||||
fname = "test_{}{}_{}".format(name, number, data["name"]) | |||||
self._tests.append((fname, data["input"])) | self._tests.append((fname, data["input"])) | ||||
counter += 1 | counter += 1 | ||||
@@ -117,7 +117,7 @@ class MemoryTest(object): | |||||
tmpl = "{0}LEAKING{1}: {2:n} bytes, {3:.2%} inc ({4:n} bytes/loop)" | tmpl = "{0}LEAKING{1}: {2:n} bytes, {3:.2%} inc ({4:n} bytes/loop)" | ||||
sys.stdout.write(tmpl.format(Color.YELLOW, Color.RESET, d, p, bpt)) | sys.stdout.write(tmpl.format(Color.YELLOW, Color.RESET, d, p, bpt)) | ||||
else: | else: | ||||
sys.stdout.write("{0}OK{1}".format(Color.GREEN, Color.RESET)) | |||||
sys.stdout.write("{}OK{}".format(Color.GREEN, Color.RESET)) | |||||
def run(self): | def run(self): | ||||
"""Run the memory test suite.""" | """Run the memory test suite.""" | ||||
@@ -27,15 +27,15 @@ from glob import glob | |||||
from os import environ | from os import environ | ||||
import sys | import sys | ||||
if ((sys.version_info[0] == 2 and sys.version_info[1] < 6) or | |||||
(sys.version_info[1] == 3 and sys.version_info[1] < 2)): | |||||
raise RuntimeError("mwparserfromhell needs Python 2.6+ or 3.2+") | |||||
if ((sys.version_info[0] == 2 and sys.version_info[1] < 7) or | |||||
(sys.version_info[1] == 3 and sys.version_info[1] < 4)): | |||||
raise RuntimeError("mwparserfromhell needs Python 2.7 or 3.4+") | |||||
from setuptools import setup, find_packages, Extension | from setuptools import setup, find_packages, Extension | ||||
from setuptools.command.build_ext import build_ext | from setuptools.command.build_ext import build_ext | ||||
from mwparserfromhell import __version__ | from mwparserfromhell import __version__ | ||||
from mwparserfromhell.compat import py26, py3k | |||||
from mwparserfromhell.compat import py3k | |||||
with open("README.rst", **({'encoding':'utf-8'} if py3k else {})) as fp: | with open("README.rst", **({'encoding':'utf-8'} if py3k else {})) as fp: | ||||
long_docs = fp.read() | long_docs = fp.read() | ||||
@@ -82,7 +82,6 @@ setup( | |||||
name = "mwparserfromhell", | name = "mwparserfromhell", | ||||
packages = find_packages(exclude=("tests",)), | packages = find_packages(exclude=("tests",)), | ||||
ext_modules = [tokenizer] if use_extension else [], | ext_modules = [tokenizer] if use_extension else [], | ||||
tests_require = ["unittest2"] if py26 else [], | |||||
test_suite = "tests.discover", | test_suite = "tests.discover", | ||||
version = __version__, | version = __version__, | ||||
author = "Ben Kurtovic", | author = "Ben Kurtovic", | ||||
@@ -90,7 +89,7 @@ setup( | |||||
url = "https://github.com/earwig/mwparserfromhell", | url = "https://github.com/earwig/mwparserfromhell", | ||||
description = "MWParserFromHell is a parser for MediaWiki wikicode.", | description = "MWParserFromHell is a parser for MediaWiki wikicode.", | ||||
long_description = long_docs, | long_description = long_docs, | ||||
download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{0}".format(__version__), | |||||
download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{}".format(__version__), | |||||
keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing", | keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing", | ||||
license = "MIT License", | license = "MIT License", | ||||
classifiers = [ | classifiers = [ | ||||
@@ -99,11 +98,9 @@ setup( | |||||
"Intended Audience :: Developers", | "Intended Audience :: Developers", | ||||
"License :: OSI Approved :: MIT License", | "License :: OSI Approved :: MIT License", | ||||
"Operating System :: OS Independent", | "Operating System :: OS Independent", | ||||
"Programming Language :: Python :: 2.6", | |||||
"Programming Language :: Python :: 2", | |||||
"Programming Language :: Python :: 2.7", | "Programming Language :: Python :: 2.7", | ||||
"Programming Language :: Python :: 3", | "Programming Language :: Python :: 3", | ||||
"Programming Language :: Python :: 3.2", | |||||
"Programming Language :: Python :: 3.3", | |||||
"Programming Language :: Python :: 3.4", | "Programming Language :: Python :: 3.4", | ||||
"Programming Language :: Python :: 3.5", | "Programming Language :: Python :: 3.5", | ||||
"Programming Language :: Python :: 3.6", | "Programming Language :: Python :: 3.6", | ||||
@@ -118,7 +118,7 @@ class TokenizerTestCase(object): | |||||
if restrict and data["name"] != restrict: | if restrict and data["name"] != restrict: | ||||
continue | continue | ||||
fname = "test_{0}{1}_{2}".format(name, number, data["name"]) | |||||
fname = "test_{}{}_{}".format(name, number, data["name"]) | |||||
meth = cls._build_test_method(fname, data) | meth = cls._build_test_method(fname, data) | ||||
setattr(cls, fname, meth) | setattr(cls, fname, meth) | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
from unittest2 import TestCase | |||||
except ImportError: | |||||
from unittest import TestCase | |||||
from unittest import TestCase | |||||
from mwparserfromhell.compat import range | from mwparserfromhell.compat import range | ||||
from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity, | from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity, | ||||
@@ -1,8 +1,6 @@ | |||||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
""" | """ | ||||
Discover tests using ``unittest2` for Python 2.6. | |||||
It appears the default distutils test suite doesn't play nice with | It appears the default distutils test suite doesn't play nice with | ||||
``setUpClass`` thereby making some tests fail. Using ``unittest2`` to load | ``setUpClass`` thereby making some tests fail. Using ``unittest2`` to load | ||||
tests seems to work around that issue. | tests seems to work around that issue. | ||||
@@ -12,12 +10,7 @@ http://stackoverflow.com/a/17004409/753501 | |||||
import os.path | import os.path | ||||
from mwparserfromhell.compat import py26 | |||||
if py26: | |||||
import unittest2 as unittest | |||||
else: | |||||
import unittest | |||||
import unittest | |||||
def additional_tests(): | def additional_tests(): | ||||
project_root = os.path.split(os.path.dirname(__file__))[0] | project_root = os.path.split(os.path.dirname(__file__))[0] | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Argument, Text | from mwparserfromhell.nodes import Argument, Text | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Template | from mwparserfromhell.nodes import Template | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import py3k | from mwparserfromhell.compat import py3k | ||||
from mwparserfromhell.nodes import (Argument, Comment, ExternalLink, Heading, | from mwparserfromhell.nodes import (Argument, Comment, ExternalLink, Heading, | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Comment | from mwparserfromhell.nodes import Comment | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
try: | try: | ||||
from mwparserfromhell.parser._tokenizer import CTokenizer | from mwparserfromhell.parser._tokenizer import CTokenizer | ||||
@@ -23,11 +23,7 @@ | |||||
from __future__ import print_function, unicode_literals | from __future__ import print_function, unicode_literals | ||||
import json | import json | ||||
import os | import os | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
import mwparserfromhell | import mwparserfromhell | ||||
from mwparserfromhell.compat import py3k, str | from mwparserfromhell.compat import py3k, str | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import ExternalLink, Text | from mwparserfromhell.nodes import ExternalLink, Text | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Heading, Text | from mwparserfromhell.nodes import Heading, Text | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import HTMLEntity | from mwparserfromhell.nodes import HTMLEntity | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Text | from mwparserfromhell.nodes import Text | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell import parser | from mwparserfromhell import parser | ||||
from mwparserfromhell.compat import range | from mwparserfromhell.compat import range | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.parser.tokenizer import Tokenizer | from mwparserfromhell.parser.tokenizer import Tokenizer | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from ._test_tokenizer import TokenizerTestCase | from ._test_tokenizer import TokenizerTestCase | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import py3k, range | from mwparserfromhell.compat import py3k, range | ||||
from mwparserfromhell.smart_list import SmartList, _ListProxy | from mwparserfromhell.smart_list import SmartList, _ListProxy | ||||
@@ -139,36 +135,36 @@ class TestSmartList(unittest.TestCase): | |||||
self.assertEqual(b"[0, 1, 2, 3, u'one', u'two']", str(list1)) | self.assertEqual(b"[0, 1, 2, 3, u'one', u'two']", str(list1)) | ||||
self.assertEqual(b"[0, 1, 2, 3, u'one', u'two']", repr(list1)) | self.assertEqual(b"[0, 1, 2, 3, u'one', u'two']", repr(list1)) | ||||
self.assertTrue(list1 < list3) | |||||
self.assertTrue(list1 <= list3) | |||||
self.assertFalse(list1 == list3) | |||||
self.assertTrue(list1 != list3) | |||||
self.assertFalse(list1 > list3) | |||||
self.assertFalse(list1 >= list3) | |||||
self.assertLess(list1, list3) | |||||
self.assertLessEqual(list1, list3) | |||||
self.assertNotEqual(list1, list3) | |||||
self.assertNotEqual(list1, list3) | |||||
self.assertLessEqual(list1, list3) | |||||
self.assertLess(list1, list3) | |||||
other1 = [0, 2, 3, 4] | other1 = [0, 2, 3, 4] | ||||
self.assertTrue(list1 < other1) | |||||
self.assertTrue(list1 <= other1) | |||||
self.assertFalse(list1 == other1) | |||||
self.assertTrue(list1 != other1) | |||||
self.assertFalse(list1 > other1) | |||||
self.assertFalse(list1 >= other1) | |||||
self.assertLess(list1, other1) | |||||
self.assertLessEqual(list1, other1) | |||||
self.assertNotEqual(list1, other1) | |||||
self.assertNotEqual(list1, other1) | |||||
self.assertLessEqual(list1, other1) | |||||
self.assertLess(list1, other1) | |||||
other2 = [0, 0, 1, 2] | other2 = [0, 0, 1, 2] | ||||
self.assertFalse(list1 < other2) | |||||
self.assertFalse(list1 <= other2) | |||||
self.assertFalse(list1 == other2) | |||||
self.assertTrue(list1 != other2) | |||||
self.assertTrue(list1 > other2) | |||||
self.assertTrue(list1 >= other2) | |||||
self.assertGreaterEqual(list1, other2) | |||||
self.assertGreater(list1, other2) | |||||
self.assertNotEqual(list1, other2) | |||||
self.assertNotEqual(list1, other2) | |||||
self.assertGreater(list1, other2) | |||||
self.assertGreaterEqual(list1, other2) | |||||
other3 = [0, 1, 2, 3, "one", "two"] | other3 = [0, 1, 2, 3, "one", "two"] | ||||
self.assertFalse(list1 < other3) | |||||
self.assertTrue(list1 <= other3) | |||||
self.assertTrue(list1 == other3) | |||||
self.assertFalse(list1 != other3) | |||||
self.assertFalse(list1 > other3) | |||||
self.assertTrue(list1 >= other3) | |||||
self.assertGreaterEqual(list1, other3) | |||||
self.assertLessEqual(list1, other3) | |||||
self.assertEqual(list1, other3) | |||||
self.assertEqual(list1, other3) | |||||
self.assertLessEqual(list1, other3) | |||||
self.assertGreaterEqual(list1, other3) | |||||
self.assertTrue(bool(list1)) | self.assertTrue(bool(list1)) | ||||
self.assertFalse(bool(list2)) | self.assertFalse(bool(list2)) | ||||
@@ -198,10 +194,10 @@ class TestSmartList(unittest.TestCase): | |||||
self.assertEqual(["two", "one", 3, 2, 1, 0], list(reversed(list1))) | self.assertEqual(["two", "one", 3, 2, 1, 0], list(reversed(list1))) | ||||
self.assertEqual([], list(reversed(list2))) | self.assertEqual([], list(reversed(list2))) | ||||
self.assertTrue("one" in list1) | |||||
self.assertTrue(3 in list1) | |||||
self.assertFalse(10 in list1) | |||||
self.assertFalse(0 in list2) | |||||
self.assertIn("one", list1) | |||||
self.assertIn(3, list1) | |||||
self.assertNotIn(10, list1) | |||||
self.assertNotIn(0, list2) | |||||
self.assertEqual([], list2 * 5) | self.assertEqual([], list2 * 5) | ||||
self.assertEqual([], 5 * list2) | self.assertEqual([], 5 * list2) | ||||
@@ -23,13 +23,9 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
from sys import getdefaultencoding | from sys import getdefaultencoding | ||||
from types import GeneratorType | 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 | from mwparserfromhell.string_mixin import StringMixIn | ||||
class _FakeString(StringMixIn): | class _FakeString(StringMixIn): | ||||
@@ -54,9 +50,7 @@ class TestStringMixIn(unittest.TestCase): | |||||
"rsplit", "rstrip", "split", "splitlines", "startswith", "strip", | "rsplit", "rstrip", "split", "splitlines", "startswith", "strip", | ||||
"swapcase", "title", "translate", "upper", "zfill"] | "swapcase", "title", "translate", "upper", "zfill"] | ||||
if py3k: | if py3k: | ||||
if not py32: | |||||
methods.append("casefold") | |||||
methods.extend(["format_map", "isidentifier", "isprintable", | |||||
methods.extend(["casefold", "format_map", "isidentifier", "isprintable", | |||||
"maketrans"]) | "maketrans"]) | ||||
else: | else: | ||||
methods.append("decode") | methods.append("decode") | ||||
@@ -90,33 +84,33 @@ class TestStringMixIn(unittest.TestCase): | |||||
str4 = "this is a fake string" | str4 = "this is a fake string" | ||||
str5 = "fake string, this is" | 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): | def test_other_magics(self): | ||||
"""test other magically implemented features, like len() and iter()""" | """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: str1[11]) | ||||
self.assertRaises(IndexError, lambda: str2[0]) | 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): | def test_other_methods(self): | ||||
"""test the remaining non-magic methods of StringMixIn""" | """test the remaining non-magic methods of StringMixIn""" | ||||
@@ -329,7 +323,7 @@ class TestStringMixIn(unittest.TestCase): | |||||
self.assertEqual("", str15.lower()) | self.assertEqual("", str15.lower()) | ||||
self.assertEqual("foobar", str16.lower()) | self.assertEqual("foobar", str16.lower()) | ||||
self.assertEqual("ß", str22.lower()) | self.assertEqual("ß", str22.lower()) | ||||
if py3k and not py32: | |||||
if py3k: | |||||
self.assertEqual("", str15.casefold()) | self.assertEqual("", str15.casefold()) | ||||
self.assertEqual("foobar", str16.casefold()) | self.assertEqual("foobar", str16.casefold()) | ||||
self.assertEqual("ss", str22.casefold()) | self.assertEqual("ss", str22.casefold()) | ||||
@@ -378,7 +372,7 @@ class TestStringMixIn(unittest.TestCase): | |||||
self.assertEqual(actual, str25.rsplit(None, 3)) | self.assertEqual(actual, str25.rsplit(None, 3)) | ||||
actual = [" this is a sentence with", "", "whitespace", ""] | actual = [" this is a sentence with", "", "whitespace", ""] | ||||
self.assertEqual(actual, str25.rsplit(" ", 3)) | self.assertEqual(actual, str25.rsplit(" ", 3)) | ||||
if py3k and not py32: | |||||
if py3k: | |||||
actual = [" this is a", "sentence", "with", "whitespace"] | actual = [" this is a", "sentence", "with", "whitespace"] | ||||
self.assertEqual(actual, str25.rsplit(maxsplit=3)) | self.assertEqual(actual, str25.rsplit(maxsplit=3)) | ||||
@@ -396,7 +390,7 @@ class TestStringMixIn(unittest.TestCase): | |||||
self.assertEqual(actual, str25.split(None, 3)) | self.assertEqual(actual, str25.split(None, 3)) | ||||
actual = ["", "", "", "this is a sentence with whitespace "] | actual = ["", "", "", "this is a sentence with whitespace "] | ||||
self.assertEqual(actual, str25.split(" ", 3)) | self.assertEqual(actual, str25.split(" ", 3)) | ||||
if py3k and not py32: | |||||
if py3k: | |||||
actual = ["this", "is", "a", "sentence with whitespace "] | actual = ["this", "is", "a", "sentence with whitespace "] | ||||
self.assertEqual(actual, str25.split(maxsplit=3)) | self.assertEqual(actual, str25.split(maxsplit=3)) | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Tag, Template, Text | from mwparserfromhell.nodes import Tag, Template, Text | ||||
@@ -22,11 +22,7 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
from difflib import unified_diff | from difflib import unified_diff | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import HTMLEntity, Template, Text | from mwparserfromhell.nodes import HTMLEntity, Template, Text | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Text | from mwparserfromhell.nodes import Text | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import py3k | from mwparserfromhell.compat import py3k | ||||
from mwparserfromhell.parser import tokens | from mwparserfromhell.parser import tokens | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.nodes import Template, Text | from mwparserfromhell.nodes import Template, Text | ||||
from mwparserfromhell.utils import parse_anything | from mwparserfromhell.utils import parse_anything | ||||
@@ -24,11 +24,7 @@ from __future__ import unicode_literals | |||||
from functools import partial | from functools import partial | ||||
import re | import re | ||||
from types import GeneratorType | from types import GeneratorType | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import py3k, str | from mwparserfromhell.compat import py3k, str | ||||
from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity, | from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity, | ||||
@@ -21,11 +21,7 @@ | |||||
# SOFTWARE. | # SOFTWARE. | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
try: | |||||
import unittest2 as unittest | |||||
except ImportError: | |||||
import unittest | |||||
import unittest | |||||
from mwparserfromhell.compat import str | from mwparserfromhell.compat import str | ||||
from mwparserfromhell.nodes import Text, Wikilink | from mwparserfromhell.nodes import Text, Wikilink | ||||