Procházet zdrojové kódy

Skeleton for TestBuilder; adding some nodes to TreeEqualityTestCase.

tags/v0.2
Ben Kurtovic před 11 roky
rodič
revize
892092434f
2 změnil soubory, kde provedl 76 přidání a 8 odebrání
  1. +32
    -6
      tests/_test_tree_equality.py
  2. +44
    -2
      tests/test_builder.py

+ 32
- 6
tests/_test_tree_equality.py Zobrazit soubor

@@ -23,8 +23,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from unittest import TestCase 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 from mwparserfromhell.wikicode import Wikicode


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


+ 44
- 2
tests/test_builder.py Zobrazit soubor

@@ -23,8 +23,50 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import unittest 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__": if __name__ == "__main__":
unittest.main(verbosity=2) unittest.main(verbosity=2)

Načítá se…
Zrušit
Uložit