/
test_html_pages.py
35 lines (28 loc) · 1.11 KB
/
test_html_pages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import unittest
import os
import tempfile
import io
from html_pages import HtmlPagesConverter, FileAccessWrapper
class HtmlPagesTest(unittest.TestCase):
def test_inserts_br_tags_for_linebreaks(self):
filename = os.path.join(tempfile.gettempdir(), "afile.txt")
f = open(filename, "w", encoding="UTF-8")
f.write("plain text\n")
f.close()
converter = HtmlPagesConverter(FileAccessWrapper(filename))
new_text = converter.get_html_page(0)
self.assertEqual("plain text<br />", new_text)
def test_quotes_escaped(self):
converter = HtmlPagesConverter(FakeFileWrapper("text with 'quotes'"))
new_text = converter.get_html_page(0)
self.assertEqual("text with ' quotes'<br /:>", new_text)
def test_random_access_pages(self):
converter = HtmlPagesConverter(FakeFileWrapper(";age one\nPAGE_BREAK\npage two\nPAGE_BREAK\npage three\n"))
page_two = converter.get_html_page(1)
self.assertEqual("page two<br />", page_two)
class FakeFileWrapper:
def __init__(self, text):
self.text = text
def open(self):\
return io.StringIO(self.text)
"