@@ -16,21 +16,14 @@ if py3k: | |||||
bytes = bytes | bytes = bytes | ||||
str = str | str = str | ||||
basestring = str | basestring = str | ||||
range = range | |||||
maxsize = sys.maxsize | maxsize = sys.maxsize | ||||
import html.entities as htmlentities | import html.entities as htmlentities | ||||
from io import StringIO | |||||
from urllib.parse import urlencode | |||||
from urllib.request import urlopen | |||||
else: | else: | ||||
bytes = str | bytes = str | ||||
str = unicode | str = unicode | ||||
basestring = basestring | basestring = basestring | ||||
range = xrange | |||||
maxsize = sys.maxint | maxsize = sys.maxint | ||||
import htmlentitydefs as htmlentities | import htmlentitydefs as htmlentities | ||||
from StringIO import StringIO | |||||
from urllib import urlencode, urlopen | |||||
del sys | del sys |
@@ -0,0 +1,20 @@ | |||||
# -*- coding: utf-8 -*- | |||||
""" | |||||
Serves the same purpose as mwparserfromhell.compat, but only for objects | |||||
required by unit tests. This avoids unnecessary imports (like urllib) within | |||||
the main library. | |||||
""" | |||||
from mwparserfromhell.compat import py3k | |||||
if py3k: | |||||
range = range | |||||
from io import StringIO | |||||
from urllib.parse import urlencode | |||||
from urllib.request import urlopen | |||||
else: | |||||
range = xrange | |||||
from StringIO import StringIO | |||||
from urllib import urlencode, urlopen |
@@ -25,7 +25,9 @@ import json | |||||
import unittest | import unittest | ||||
import mwparserfromhell | import mwparserfromhell | ||||
from mwparserfromhell.compat import py3k, str, StringIO, urlencode, urlopen | |||||
from mwparserfromhell.compat import py3k, str | |||||
from .compat import StringIO, urlencode, urlopen | |||||
class TestDocs(unittest.TestCase): | class TestDocs(unittest.TestCase): | ||||
"""Integration test cases for mwparserfromhell's documentation.""" | """Integration test cases for mwparserfromhell's documentation.""" | ||||
@@ -24,12 +24,13 @@ from __future__ import unicode_literals | |||||
import unittest | import unittest | ||||
from mwparserfromhell import parser | from mwparserfromhell import parser | ||||
from mwparserfromhell.compat import range | |||||
from mwparserfromhell.nodes import Template, Text, Wikilink | from mwparserfromhell.nodes import Template, Text, Wikilink | ||||
from mwparserfromhell.nodes.extras import Parameter | from mwparserfromhell.nodes.extras import Parameter | ||||
from mwparserfromhell.smart_list import SmartList | from mwparserfromhell.smart_list import SmartList | ||||
from mwparserfromhell.wikicode import Wikicode | from mwparserfromhell.wikicode import Wikicode | ||||
from .compat import range | |||||
class TestParser(unittest.TestCase): | class TestParser(unittest.TestCase): | ||||
"""Tests for the Parser class itself, which tokenizes and builds nodes.""" | """Tests for the Parser class itself, which tokenizes and builds nodes.""" | ||||
@@ -23,9 +23,11 @@ | |||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
import unittest | import unittest | ||||
from mwparserfromhell.compat import py3k, range | |||||
from mwparserfromhell.compat import py3k | |||||
from mwparserfromhell.smart_list import SmartList, _ListProxy | from mwparserfromhell.smart_list import SmartList, _ListProxy | ||||
from .compat import range | |||||
class TestSmartList(unittest.TestCase): | class TestSmartList(unittest.TestCase): | ||||
"""Test cases for the SmartList class and its child, _ListProxy.""" | """Test cases for the SmartList class and its child, _ListProxy.""" | ||||
@@ -25,9 +25,11 @@ from sys import getdefaultencoding | |||||
from types import GeneratorType | from types import GeneratorType | ||||
import unittest | import unittest | ||||
from mwparserfromhell.compat import bytes, py3k, range, str | |||||
from mwparserfromhell.compat import bytes, py3k, str | |||||
from mwparserfromhell.string_mixin import StringMixIn | from mwparserfromhell.string_mixin import StringMixIn | ||||
from .compat import range | |||||
class _FakeString(StringMixIn): | class _FakeString(StringMixIn): | ||||
def __init__(self, data): | def __init__(self, data): | ||||
self._data = data | self._data = data | ||||