Browse Source

Moving compat stuff exclusively for unit tests to its own file.

tags/v0.2
Ben Kurtovic 11 years ago
parent
commit
1b69b5e882
6 changed files with 31 additions and 11 deletions
  1. +0
    -7
      mwparserfromhell/compat.py
  2. +20
    -0
      tests/compat.py
  3. +3
    -1
      tests/test_docs.py
  4. +2
    -1
      tests/test_parser.py
  5. +3
    -1
      tests/test_smart_list.py
  6. +3
    -1
      tests/test_string_mixin.py

+ 0
- 7
mwparserfromhell/compat.py View File

@@ -16,21 +16,14 @@ if py3k:
bytes = bytes
str = str
basestring = str
range = range
maxsize = sys.maxsize
import html.entities as htmlentities
from io import StringIO
from urllib.parse import urlencode
from urllib.request import urlopen

else:
bytes = str
str = unicode
basestring = basestring
range = xrange
maxsize = sys.maxint
import htmlentitydefs as htmlentities
from StringIO import StringIO
from urllib import urlencode, urlopen

del sys

+ 20
- 0
tests/compat.py View File

@@ -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

+ 3
- 1
tests/test_docs.py View File

@@ -25,7 +25,9 @@ import json
import unittest

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):
"""Integration test cases for mwparserfromhell's documentation."""


+ 2
- 1
tests/test_parser.py View File

@@ -24,12 +24,13 @@ from __future__ import unicode_literals
import unittest

from mwparserfromhell import parser
from mwparserfromhell.compat import range
from mwparserfromhell.nodes import Template, Text, Wikilink
from mwparserfromhell.nodes.extras import Parameter
from mwparserfromhell.smart_list import SmartList
from mwparserfromhell.wikicode import Wikicode

from .compat import range

class TestParser(unittest.TestCase):
"""Tests for the Parser class itself, which tokenizes and builds nodes."""



+ 3
- 1
tests/test_smart_list.py View File

@@ -23,9 +23,11 @@
from __future__ import unicode_literals
import unittest

from mwparserfromhell.compat import py3k, range
from mwparserfromhell.compat import py3k
from mwparserfromhell.smart_list import SmartList, _ListProxy

from .compat import range

class TestSmartList(unittest.TestCase):
"""Test cases for the SmartList class and its child, _ListProxy."""



+ 3
- 1
tests/test_string_mixin.py View File

@@ -25,9 +25,11 @@ from sys import getdefaultencoding
from types import GeneratorType
import unittest

from mwparserfromhell.compat import bytes, py3k, range, str
from mwparserfromhell.compat import bytes, py3k, str
from mwparserfromhell.string_mixin import StringMixIn

from .compat import range

class _FakeString(StringMixIn):
def __init__(self, data):
self._data = data


Loading…
Cancel
Save