|
@@ -22,6 +22,7 @@ |
|
|
|
|
|
|
|
|
from __future__ import print_function, unicode_literals |
|
|
from __future__ import print_function, unicode_literals |
|
|
from os import listdir, path |
|
|
from os import listdir, path |
|
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
from mwparserfromhell.compat import py3k |
|
|
from mwparserfromhell.compat import py3k |
|
|
from mwparserfromhell.parser import tokens |
|
|
from mwparserfromhell.parser import tokens |
|
@@ -107,15 +108,25 @@ class TokenizerTestCase(object): |
|
|
@classmethod |
|
|
@classmethod |
|
|
def build(cls): |
|
|
def build(cls): |
|
|
"""Load and install all tests from the 'tokenizer' directory.""" |
|
|
"""Load and install all tests from the 'tokenizer' directory.""" |
|
|
directory = path.join(path.dirname(__file__), "tokenizer") |
|
|
|
|
|
extension = ".mwtest" |
|
|
|
|
|
for filename in listdir(directory): |
|
|
|
|
|
if not filename.endswith(extension): |
|
|
|
|
|
continue |
|
|
|
|
|
with open(path.join(directory, filename), "r") as fp: |
|
|
|
|
|
|
|
|
def load_file(filename): |
|
|
|
|
|
with open(filename, "r") as fp: |
|
|
text = fp.read() |
|
|
text = fp.read() |
|
|
if not py3k: |
|
|
if not py3k: |
|
|
text = text.decode("utf8") |
|
|
text = text.decode("utf8") |
|
|
cls._load_tests(filename[:0-len(extension)], text) |
|
|
cls._load_tests(filename[:0-len(extension)], text) |
|
|
|
|
|
|
|
|
|
|
|
directory = path.join(path.dirname(__file__), "tokenizer") |
|
|
|
|
|
extension = ".mwtest" |
|
|
|
|
|
if len(sys.argv) > 1: # Read specific tests from command line |
|
|
|
|
|
for name in sys.argv[1:]: |
|
|
|
|
|
load_file(path.join(directory, name + extension)) |
|
|
|
|
|
sys.argv = [sys.argv[0]] # So unittest doesn't try to load these |
|
|
|
|
|
cls.skip_others = True |
|
|
|
|
|
else: |
|
|
|
|
|
for filename in listdir(directory): |
|
|
|
|
|
if not filename.endswith(extension): |
|
|
|
|
|
continue |
|
|
|
|
|
load_file(path.join(directory, filename)) |
|
|
|
|
|
cls.skip_others = False |
|
|
|
|
|
|
|
|
TokenizerTestCase.build() |
|
|
TokenizerTestCase.build() |