Sfoglia il codice sorgente

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

tags/v0.2
Ben Kurtovic 11 anni fa
parent
commit
1b69b5e882
6 ha cambiato i file con 31 aggiunte e 11 eliminazioni
  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 Vedi File

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

+ 20
- 0
tests/compat.py Vedi 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 Vedi File

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


+ 2
- 1
tests/test_parser.py Vedi File

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




+ 3
- 1
tests/test_smart_list.py Vedi File

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




+ 3
- 1
tests/test_string_mixin.py Vedi File

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


Caricamento…
Annulla
Salva