- added better mypy support
- updated most unit-test to use the unitttest module - added a single unit-test run file
This commit is contained in:
1 parent
290de97cb5
commit
9e923de7ec
22 files changed
+372
-319
No files matched your search
+52
-30
@@ -1,43 +1,60 @@
|
||||
from contextlib import contextmanager
|
||||
from unittest import TestCase, main
|
||||
from typing import List, Tuple, Callable
|
||||
from os import remove
|
||||
from tempfile import mktemp
|
||||
from pdfmajor.converters.writers.html import HTMLMaker
|
||||
from tqdm import tqdm
|
||||
|
||||
# Make temp file
|
||||
FILE_NAME = mktemp()
|
||||
|
||||
TestFunction = Callable[[HTMLMaker], str];
|
||||
TESTS: List[Tuple[TestFunction, str]] = [];
|
||||
|
||||
with HTMLMaker(FILE_NAME) as html:
|
||||
with html.elm("html", nolineend=True):
|
||||
html.write("test")
|
||||
assert(open(FILE_NAME, 'r').read() == """<html >
|
||||
class HTMLTester(TestCase):
|
||||
@contextmanager
|
||||
def get_html(self):
|
||||
with HTMLMaker(FILE_NAME) as html:
|
||||
yield html
|
||||
def compare(self, expected: str):
|
||||
with open(FILE_NAME, 'r') as f:
|
||||
self.assertEqual(f.read() , expected)
|
||||
|
||||
def test_html_basic(self):
|
||||
with self.get_html() as html:
|
||||
with html.elm("html", nolineend=True):
|
||||
html.write("test")
|
||||
self.compare("""<html >
|
||||
test
|
||||
</html>""")
|
||||
|
||||
|
||||
with HTMLMaker(FILE_NAME) as html:
|
||||
with html.elm("html", nolineend=True):
|
||||
with html.elm("head"):
|
||||
html.singleton("meta", {
|
||||
'http-equiv': "Content-Type",
|
||||
'content': "text/html"
|
||||
})
|
||||
assert(open(FILE_NAME, 'r').read() == """<html >
|
||||
def test_html_with_attributes(self):
|
||||
with self.get_html() as html:
|
||||
with html.elm("html", nolineend=True):
|
||||
with html.elm("head"):
|
||||
html.singleton("meta", {
|
||||
'http-equiv': "Content-Type",
|
||||
'content': "text/html"
|
||||
})
|
||||
self.compare("""<html >
|
||||
<head >
|
||||
<meta http-equiv="Content-Type" content="text/html" />
|
||||
</head>
|
||||
</html>""")
|
||||
|
||||
with HTMLMaker(FILE_NAME) as html:
|
||||
with html.elm("html", nolineend=True):
|
||||
with html.elm("head"):
|
||||
html.singleton("meta", {
|
||||
'http-equiv': "Content-Type",
|
||||
'content': "text/html"
|
||||
})
|
||||
with html.elm("body"):
|
||||
with html.elm("h1", css={"color": "red"}):
|
||||
html.write("Hello World")
|
||||
assert(open(FILE_NAME, 'r').read() == """<html >
|
||||
def test_html_with_children(self):
|
||||
with self.get_html() as html:
|
||||
with html.elm("html", nolineend=True):
|
||||
with html.elm("head"):
|
||||
html.singleton("meta", {
|
||||
'http-equiv': "Content-Type",
|
||||
'content': "text/html"
|
||||
})
|
||||
with html.elm("body"):
|
||||
with html.elm("h1", css={"color": "red"}):
|
||||
html.write("Hello World")
|
||||
self.compare("""<html >
|
||||
<head >
|
||||
<meta http-equiv="Content-Type" content="text/html" />
|
||||
</head>
|
||||
@@ -48,13 +65,18 @@ assert(open(FILE_NAME, 'r').read() == """<html >
|
||||
</body>
|
||||
</html>""")
|
||||
|
||||
with HTMLMaker(FILE_NAME) as html:
|
||||
with html.elm('style'):
|
||||
html.write('''.page { position: relative; overflow: hidden;border: 1px black solid;}''')
|
||||
assert(open(FILE_NAME, 'r').read() == """<style >
|
||||
def test_html_with_css(self):
|
||||
with self.get_html() as html:
|
||||
with html.elm('style'):
|
||||
html.write('''.page { position: relative; overflow: hidden;border: 1px black solid;}''')
|
||||
self.compare("""<style >
|
||||
.page { position: relative; overflow: hidden;border: 1px black solid;}
|
||||
</style>
|
||||
""")
|
||||
|
||||
# Clean up
|
||||
remove(FILE_NAME)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Run Tests
|
||||
main()
|
||||
# Clean up
|
||||
remove(FILE_NAME)
|
||||
Reference in new issue
Block a user