瀏覽代碼

Skeleton for TestBuilder; adding some nodes to TreeEqualityTestCase.

tags/v0.2
Ben Kurtovic 11 年之前
父節點
當前提交
892092434f
共有 2 個文件被更改,包括 76 次插入8 次删除
  1. +32
    -6
      tests/_test_tree_equality.py
  2. +44
    -2
      tests/test_builder.py

+ 32
- 6
tests/_test_tree_equality.py 查看文件

@@ -23,8 +23,9 @@
from __future__ import unicode_literals
from unittest import TestCase

from mwparserfromhell.nodes import Template, Text, Wikilink
from mwparserfromhell.nodes.extras import Parameter
from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity,
Tag, Template, Text, Wikilink)
from mwparserfromhell.nodes.extras import Attribute, Parameter
from mwparserfromhell.wikicode import Wikicode

class TreeEqualityTestCase(TestCase):
@@ -37,8 +38,13 @@ class TreeEqualityTestCase(TestCase):
def assertNodeEqual(self, expected, actual):
"""Assert that two Nodes have the same type and have the same data."""
registry = {
Text: self.assertTextNodeEqual,
Argument: self.assertArgumentNodeEqual,
Comment: self.assertCommentNodeEqual,
Heading: self.assertHeadingNodeEqual,
HTMLEntity: self.assertHTMLEntityNodeEqual,
Tag: self.assertTagNodeEqual,
Template: self.assertTemplateNodeEqual,
Text: self.assertTextNodeEqual,
Wikilink: self.assertWikilinkNodeEqual
}
for nodetype in registry:
@@ -46,9 +52,25 @@ class TreeEqualityTestCase(TestCase):
self.assertIsInstance(actual, nodetype)
registry[nodetype](expected, actual)

def assertTextNodeEqual(self, expected, actual):
"""Assert that two Text nodes have the same data."""
self.assertEqual(expected.value, actual.value)
def assertArgumentNodeEqual(self, expected, actual):
"""Assert that two Argument nodes have the same data."""
pass

def assertCommentNodeEqual(self, expected, actual):
"""Assert that two Comment nodes have the same data."""
pass

def assertHeadingNodeEqual(self, expected, actual):
"""Assert that two Heading nodes have the same data."""
pass

def assertHTMLEntityNodeEqual(self, expected, actual):
"""Assert that two HTMLEntity nodes have the same data."""
pass

def assertTagNodeEqual(self, expected, actual):
"""Assert that two Tag nodes have the same data."""
pass

def assertTemplateNodeEqual(self, expected, actual):
"""Assert that two Template nodes have the same data."""
@@ -62,6 +84,10 @@ class TreeEqualityTestCase(TestCase):
self.assertWikicodeEqual(exp_param.value, act_param.value)
self.assertIs(exp_param.showkey, act_param.showkey)

def assertTextNodeEqual(self, expected, actual):
"""Assert that two Text nodes have the same data."""
self.assertEqual(expected.value, actual.value)

def assertWikilinkNodeEqual(self, expected, actual):
"""Assert that two Wikilink nodes have the same data."""
self.assertWikicodeEqual(expected.title, actual.title)


+ 44
- 2
tests/test_builder.py 查看文件

@@ -23,8 +23,50 @@
from __future__ import unicode_literals
import unittest

class TestBuilder(unittest.TestCase):
pass
from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity,
Tag, Template, Text, Wikilink)
from mwparserfromhell.nodes.extras import Attribute, Parameter
from mwparserfromhell.smart_list import SmartList
from mwparserfromhell.wikicode import Wikicode

from ._test_tree_equality import TreeEqualityTestCase

wrap = lambda L: Wikicode(SmartList(L))

class TestBuilder(TreeEqualityTestCase):
"""Tests for the builder, which turns tokens into Wikicode objects."""

def test_text(self):
"""tests for building Text nodes"""
pass

def test_template(self):
"""tests for building Template nodes"""
pass

def test_argument(self):
"""tests for building Argument nodes"""
pass

def test_wikilink(self):
"""tests for building Wikilink nodes"""
pass

def test_html_entity(self):
"""tests for building HTMLEntity nodes"""
pass

def test_heading(self):
"""tests for building Heading nodes"""
pass

def test_comment(self):
"""tests for building Comment nodes"""
pass

def test_tag(self):
"""tests for building Tag nodes"""
pass

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

Loading…
取消
儲存