Explorar el Código

Add a few more tests; use assert*(expected, actual) instead of opposite.

tags/v0.2
Ben Kurtovic hace 11 años
padre
commit
d500f8972e
Se han modificado 3 ficheros con 66 adiciones y 15 borrados
  1. +4
    -3
      tests/_test_tokenizer.py
  2. +3
    -3
      tests/test_docs.py
  3. +59
    -9
      tests/tokenizer/templates.test

+ 4
- 3
tests/_test_tokenizer.py Ver fichero

@@ -47,8 +47,9 @@ class TokenizerTestCase(object):
*label* for the method's docstring.
"""
def inner(self):
expected = data["output"]
actual = self.tokenizer().tokenize(data["input"])
self.assertEqual(actual, data["output"])
self.assertEqual(expected, actual)
if not py3k:
inner.__name__ = funcname.encode("utf8")
inner.__doc__ = data["label"]
@@ -61,7 +62,7 @@ class TokenizerTestCase(object):
counter = 1
digits = len(str(len(tests)))
for test in tests:
data = {"name": "", "label": "", "input": "", "output": []}
data = {"name": None, "label": None, "input": None, "output": None}
try:
for line in test.strip().splitlines():
if line.startswith("name:"):
@@ -92,7 +93,7 @@ class TokenizerTestCase(object):
error = "A test in '{0}' was ignored because it lacked a name"
print(error.format(filename))
continue
if not data["input"] or not data["output"]:
if data["input"] is None or data["output"] is None:
error = "Test '{0}' in '{1}' was ignored because it lacked an input or an output"
print(error.format(data["name"], filename))
continue


+ 3
- 3
tests/test_docs.py Ver fichero

@@ -35,7 +35,7 @@ class TestDocs(unittest.TestCase):
buff = StringIO()
print(input, end="", file=buff)
buff.seek(0)
self.assertEqual(buff.read(), output)
self.assertEqual(output, buff.read())

def test_readme_1(self):
"""test a block of example code in the README"""
@@ -115,9 +115,9 @@ class TestDocs(unittest.TestCase):
raw = urllib.urlopen(url1, urllib.urlencode(data)).read()
res = json.loads(raw)
text = res["query"]["pages"].values()[0]["revisions"][0]["*"]
actual = mwparserfromhell.parse(text)
expected = urllib.urlopen(url2.format(title)).read().decode("utf8")
self.assertEqual(actual, expected)
actual = mwparserfromhell.parse(text)
self.assertEqual(expected, actual)

if __name__ == "__main__":
unittest.main(verbosity=2)

+ 59
- 9
tests/tokenizer/templates.test Ver fichero

@@ -208,17 +208,62 @@ output: [TemplateOpen(), TemplateOpen(), TemplateOpen(), TemplateOpen(), Text(te

---

name: incomplete_tests
name: mixed_nested_templates
label: mixed assortment of nested templates within template names, parameter names, and values
input: "{{{{{{{{foo}}bar|baz=biz}}buzz}}usr|{{bin}}}}"
output: [TemplateOpen(), TemplateOpen(), TemplateOpen(), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text="bar"), TemplateParamSeparator(), Text(text="baz"), TemplateParamEquals(), Text(text="biz"), TemplateClose(), Text(text="buzz"), TemplateClose(), Text(text="usr"), TemplateParamSeparator(), TemplateOpen(), Text(text="bin"), TemplateClose(), TemplateClose()]

---

name: newline_start
label: a newline at the start of a template name
input: "{{\nfoobar}}"
output: [TemplateOpen(), Text(text="\nfoobar"), TemplateClose()]

---

name: newline_end
label: a newline at the end of a template name
input: "{{foobar\n}}"
output: [TemplateOpen(), Text(text="foobar\n"), TemplateClose()]

---

name: newline_start_end
label: a newline at the start and end of a template name
input: "{{\nfoobar\n}}"
output: [TemplateOpen(), Text(text="\nfoobar\n"), TemplateClose()]

---

"{{{{{{{{foo}}bar|baz=biz}}buzz}}usr|{{bin}}}}"
name: newline_mid
label: a newline at the middle of a template name
input: "{{foo\nbar}}"
output: [Text(text="{{foo\nbar}}")]

"{{\nfoobar}}"
"{{foobar\n}}"
"{{\nfoobar\n}}"
"{{foo\nbar}}"
"{{\nfoo\nbar}}"
"{{foo\nbar\n}}"
"{{\nfoo\nbar\n}}"
---

name: newline_start_mid
label: a newline at the start and middle of a template name
input: "{{\nfoo\nbar}}"
output: [Text(text="{{\nfoo\nbar}}")]

---

name: newline_mid_end
label: a newline at the middle and end of a template name
input: "{{foo\nbar\n}}"
output: [Text(text="{{foo\nbar\n}}")]

---

name: newline_start_mid_end
label: a newline at the start, middle, and end of a template name
input: "{{\nfoo\nbar\n}}"
output: [Text(text="{{\nfoo\nbar\n}}")]

---
name: incomplete_tests

"{{foo|\nbar}}"
"{{foo|bar\n}}"
@@ -300,6 +345,11 @@ name: incomplete_tests
"{{[foobar}}"
"{{foobar]}}"

"{{foo|ba{r}}"
"{{foo|ba{r}}}"
"{{foo|ba{r}=baz}}"
"{{foo|ba[r]}}"

"{{foobar"
"{{foobar}"
"{{foobar|"


Cargando…
Cancelar
Guardar