def test_simplespan(self): input = HTMLParser(StringIO("<span>test</span>")) lines = list(_group_lines(input)) self.assertEquals(len(lines), 1) self.assertTrue(isinstance(lines[0], Stream)) for (a, b) in zip(lines[0], input): self.assertEqual(a, b)
def test_simplespan(self): input = HTMLParser(StringIO(u"<span>test</span>"), encoding=None) lines = list(_group_lines(input)) self.assertEqual(len(lines), 1) self.assertIsInstance(lines[0], Stream) for (a, b) in zip(lines[0], input): self.assertEqual(a, b)
def test_empty_text_stream(self): """ http://trac.edgewall.org/ticket/4336 """ input = [(TEXT, "", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEquals(len(lines), 0)
def test_empty_text_stream(self): """ http://trac.edgewall.org/ticket/4336 """ input = [(TEXT, "", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEqual(len(lines), 0)
def test_empty_text_in_span(self): """ http://trac.edgewall.org/ticket/4336 """ ns = Namespace('http://www.w3.org/1999/xhtml') input = [(START, (ns.span, Attrs([])), (None, -1, -1)), (TEXT, "", (None, -1, -1)), (END, ns.span, (None, -1, -1)), ] lines = list(_group_lines(input)) self.assertEqual(len(lines), 0)
def test_newline2(self): """ Same as test_newline above, but make sure it behaves properly wrt the trailing \\n, especially given it's inside an element. """ input = HTMLParser(StringIO('<span class="c">a\nb\n</span>')) expected = ['<span class="c">a</span>', '<span class="c">b</span>', ] lines = list(_group_lines(input)) self.assertEquals(len(lines), len(expected)) for a, b in zip(lines, expected): self.assertEquals(a.render('html'), b)
def test_newline(self): """ If the text element does not end with a newline, it's not properly closed. """ input = HTMLParser(StringIO('<span class="c">a\nb</span>')) expected = ['<span class="c">a</span>', '<span class="c">b</span>', ] lines = list(_group_lines(input)) self.assertEquals(len(lines), len(expected)) for a, b in zip(lines, expected): self.assertEquals(a.render('html'), b)
def test_multinewline(self): """ ditto. """ input = HTMLParser(StringIO('<span class="c">\n\n\na</span>')) expected = ['<span class="c"></span>', '<span class="c"></span>', '<span class="c"></span>', '<span class="c">a</span>', ] lines = list(_group_lines(input)) self.assertEquals(len(lines), len(expected)) for a, b in zip(lines, expected): self.assertEquals(a.render('html'), b)
def test_text_only_stream2(self): input = [(TEXT, "test\n", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEqual(len(lines), 1) self.assertIsInstance(lines[0], Stream) self.assertEqual(lines[0].events, [(TEXT, "test", (None, -1, -1))])
def test_empty_stream(self): # FIXME: this currently fails lines = list(_group_lines([])) self.assertEqual(len(lines), 0)
def test_newline_stream2(self): input = [(TEXT, "\n\n\n", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEquals(len(lines), 3)
def test_text_only_stream2(self): input = [(TEXT, "test\n", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEquals(len(lines), 1) self.assertTrue(isinstance(lines[0], Stream)) self.assertEquals(lines[0].events, [(TEXT, "test", (None, -1, -1))])
def test_text_only_stream(self): input = [(TEXT, "test", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEquals(len(lines), 1) self.assertTrue(isinstance(lines[0], Stream)) self.assertEquals(lines[0].events, input)
def test_newline_stream2(self): input = [(TEXT, "\n\n\n", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEqual(len(lines), 3)
def test_text_only_stream(self): input = [(TEXT, "test", (None, -1, -1))] lines = list(_group_lines(input)) self.assertEqual(len(lines), 1) self.assertIsInstance(lines[0], Stream) self.assertEqual(lines[0].events, input)