Exemplo n.º 1
0
 def test_showtree(self):
     """test Heading.__showtree__()"""
     output = []
     getter = object()
     get = lambda code: output.append((getter, code))
     node1 = Heading(wraptext("foobar"), 3)
     node2 = Heading(wraptext(" baz "), 4)
     node1.__showtree__(output.append, get, None)
     node2.__showtree__(output.append, get, None)
     valid = ["===", (getter, node1.title), "===",
              "====", (getter, node2.title), "===="]
     self.assertEqual(valid, output)
Exemplo n.º 2
0
    def test_heading(self):
        """tests for building Heading nodes"""
        tests = [
            ([tokens.HeadingStart(level=2), tokens.Text(text="foobar"),
              tokens.HeadingEnd()],
             wrap([Heading(wraptext("foobar"), 2)])),

            ([tokens.HeadingStart(level=4), tokens.Text(text="spam"),
              tokens.Text(text="eggs"), tokens.HeadingEnd()],
             wrap([Heading(wraptext("spam", "eggs"), 4)])),
        ]
        for test, valid in tests:
            self.assertWikicodeEqual(valid, self.builder.build(test))
Exemplo n.º 3
0
 def test_title(self):
     """test getter/setter for the title attribute"""
     title = wraptext("foobar")
     node = Heading(title, 3)
     self.assertIs(title, node.title)
     node.title = "héhehé"
     self.assertWikicodeEqual(wraptext("héhehé"), node.title)
Exemplo n.º 4
0
 def test_level(self):
     """test getter/setter for the level attribute"""
     node = Heading(wraptext("foobar"), 3)
     self.assertEqual(3, node.level)
     node.level = 5
     self.assertEqual(5, node.level)
     self.assertRaises(ValueError, setattr, node, "level", 0)
     self.assertRaises(ValueError, setattr, node, "level", 7)
     self.assertRaises(ValueError, setattr, node, "level", "abc")
     self.assertRaises(ValueError, setattr, node, "level", False)
Exemplo n.º 5
0
 def test_strip(self):
     """test Heading.__strip__()"""
     node = Heading(wraptext("foobar"), 3)
     for a in (True, False):
         for b in (True, False):
             self.assertEqual("foobar", node.__strip__(a, b))
Exemplo n.º 6
0
 def test_children(self):
     """test Heading.__children__()"""
     node = Heading(wrap([Text("foo"), Text("bar")]), 3)
     gen = node.__children__()
     self.assertEqual(node.title, next(gen))
     self.assertRaises(StopIteration, next, gen)
Exemplo n.º 7
0
 def test_unicode(self):
     """test Heading.__unicode__()"""
     node = Heading(wraptext("foobar"), 2)
     self.assertEqual("==foobar==", str(node))
     node2 = Heading(wraptext(" zzz "), 5)
     self.assertEqual("===== zzz =====", str(node2))
Exemplo n.º 8
0
 def test_strip(self):
     """test Heading.__strip__()"""
     node = Heading(wraptext("foobar"), 3)
     self.assertEqual("foobar", node.__strip__())