Quellcode durchsuchen

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

tags/v0.2
Ben Kurtovic vor 11 Jahren
Ursprung
Commit
1b69b5e882
6 geänderte Dateien mit 31 neuen und 11 gelöschten Zeilen
  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 Datei anzeigen

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

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

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

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

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

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


Laden…
Abbrechen
Speichern