def testImproved1 (self): src = u"""<ul><li>Несортированный список. Элемент 1</li><li>Несортированный список. Элемент 2</li><li>Несортированный список. Элемент 3</li><ol><li>Вложенный сортированный список. Элемент 1</li><li>Вложенный сортированный список. Элемент 2</li><li>Вложенный сортированный список. Элемент 3</li><li>Вложенный сортированный список. Элемент 4</li><ul><li>Совсем вложенный сортированный список. Элемент 1</li><li>Совсем вложенный сортированный список. Элемент 2</li></ul><li>Вложенный сортированный список. Элемент 5</li></ol><ul><li>Вложенный несортированный список. Элемент 1</li></ul></ul>""" expectedResult = u"""<ul> <li>Несортированный список. Элемент 1</li> <li>Несортированный список. Элемент 2</li> <li>Несортированный список. Элемент 3</li> <ol> <li>Вложенный сортированный список. Элемент 1</li> <li>Вложенный сортированный список. Элемент 2</li> <li>Вложенный сортированный список. Элемент 3</li> <li>Вложенный сортированный список. Элемент 4</li> <ul> <li>Совсем вложенный сортированный список. Элемент 1</li> <li>Совсем вложенный сортированный список. Элемент 2</li> </ul> <li>Вложенный сортированный список. Элемент 5</li> </ol> <ul> <li>Вложенный несортированный список. Элемент 1</li> </ul> </ul>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (readTextFile (templatepath).strip()) result = tpl.substitute (BrHtmlImprover().run (src)) self.assertIn (expectedResult, result)
def testChangeFontSize (self): self.config.fontSize.value = 20 content = u"бла-бла-бла" result_right = u"""<!DOCTYPE html> <HTML> <HEAD> <META HTTP-EQUIV='X-UA-Compatible' CONTENT='IE=edge' /> <META HTTP-EQUIV='CONTENT-TYPE' CONTENT='TEXT/HTML; CHARSET=UTF-8'/> <STYLE type='text/css'> body, div, p, table { font-size:20pt; font-family:Verdana; } img{border:none} </STYLE> </HEAD> <BODY> <P>бла-бла-бла</P> </BODY> </HTML>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (content=content) self.assertEqual (result, result_right, result)
def testChangeFontSize (self): self.config.fontSize.value = 20 content = u"бла-бла-бла" result_right = u"""<!DOCTYPE html> <html> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge' /> <meta http-equiv='content-type' content='text/html; charset=utf-8'/> <style type='text/css'> body, div, p, table { font-size:20pt; font-family:Verdana; } img{border:none} </style> </head> <body> <p>бла-бла-бла</p> </body> </html>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (content=content) self.assertEqual (result, result_right, result)
def testImproved1(self): src = """<ul><li>Несортированный список. Элемент 1</li><li>Несортированный список. Элемент 2</li><li>Несортированный список. Элемент 3</li><ol><li>Вложенный сортированный список. Элемент 1</li><li>Вложенный сортированный список. Элемент 2</li><li>Вложенный сортированный список. Элемент 3</li><li>Вложенный сортированный список. Элемент 4</li><ul><li>Совсем вложенный сортированный список. Элемент 1</li><li>Совсем вложенный сортированный список. Элемент 2</li></ul><li>Вложенный сортированный список. Элемент 5</li></ol><ul><li>Вложенный несортированный список. Элемент 1</li></ul></ul>""" expectedResult = """<ul> <li>Несортированный список. Элемент 1</li> <li>Несортированный список. Элемент 2</li> <li>Несортированный список. Элемент 3</li> <ol> <li>Вложенный сортированный список. Элемент 1</li> <li>Вложенный сортированный список. Элемент 2</li> <li>Вложенный сортированный список. Элемент 3</li> <li>Вложенный сортированный список. Элемент 4</li> <ul> <li>Совсем вложенный сортированный список. Элемент 1</li> <li>Совсем вложенный сортированный список. Элемент 2</li> </ul> <li>Вложенный сортированный список. Элемент 5</li> </ol> <ul> <li>Вложенный несортированный список. Элемент 1</li> </ul> </ul>""" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(BrHtmlImprover().run(src)) self.assertIn(expectedResult, result)
def testChangeFontSize (self): self.config.fontSize.value = 20 content = u"бла-бла-бла" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (readTextFile (templatepath).strip()) result = tpl.substitute (content=content) self.assertIn (u"font-size:20pt;", result)
def testChangeFontSize(self): self.config.fontSize.value = 20 content = "бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn("font-size:20pt;", result)
def testChangeFontName(self): self.config.fontName.value = u"Arial" content = u"бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn(u"font-family:Arial;", result)
def testChangeFontName(self): self.config.fontName.value = "Arial" content = "бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn("font-family:Arial;", result)
def testDefault (self): content = u"бла-бла-бла" result_right = ur"""<body> бла-бла-бла </body> </html>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (readTextFile (templatepath).strip()) result = tpl.substitute (content=content) self.assertIn (result_right, result.replace ("\r\n", "\n"))
def testChangeUserStyle (self): style = u"p {background-color: maroon; color: white; }" self.config.userStyle.value = style content = u"бла-бла-бла" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (content=content) self.assertTrue (style in result, result)
def testChangeUserStyleRussian (self): style = u"p {background-color: maroon; /* Цвет фона под текстом параграфа */ color: white; /* Цвет текста */ }" self.config.userStyle.value = style content = u"бла-бла-бла" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (content=content) self.assertTrue (style in result, result)
def testDefault(self): content = "бла-бла-бла" result_right = r"""<body> бла-бла-бла </body> </html>""" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertIn(result_right, result.replace("\r\n", "\n"))
def testChangeUserStyleRussian(self): style = u"p {background-color: maroon; /* Цвет фона под текстом параграфа */ color: white; /* Цвет текста */ }" self.config.userStyle.value = style content = u"бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertTrue(style in result, result)
def testChangeUserStyle(self): style = "p {background-color: maroon; color: white; }" self.config.userStyle.value = style content = "бла-бла-бла" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(content=content) self.assertTrue(style in result, result)
def testImproved1 (self): src = u"""<UL><LI>Несортированный список. Элемент 1</LI><LI>Несортированный список. Элемент 2</LI><LI>Несортированный список. Элемент 3</LI><OL><LI>Вложенный сортированный список. Элемент 1</LI><LI>Вложенный сортированный список. Элемент 2</LI><LI>Вложенный сортированный список. Элемент 3</LI><LI>Вложенный сортированный список. Элемент 4</LI><UL><LI>Совсем вложенный сортированный список. Элемент 1</LI><LI>Совсем вложенный сортированный список. Элемент 2</LI></UL><LI>Вложенный сортированный список. Элемент 5</LI></OL><UL><LI>Вложенный несортированный список. Элемент 1</LI></UL></UL>""" expectedResult = u"""<!DOCTYPE html> <HTML> <HEAD> <META HTTP-EQUIV='X-UA-Compatible' CONTENT='IE=edge' /> <META HTTP-EQUIV='CONTENT-TYPE' CONTENT='TEXT/HTML; CHARSET=UTF-8'/> <STYLE type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </STYLE> </HEAD> <BODY> <P> <UL> <LI>Несортированный список. Элемент 1</LI> <LI>Несортированный список. Элемент 2</LI> <LI>Несортированный список. Элемент 3</LI> <OL> <LI>Вложенный сортированный список. Элемент 1</LI> <LI>Вложенный сортированный список. Элемент 2</LI> <LI>Вложенный сортированный список. Элемент 3</LI> <LI>Вложенный сортированный список. Элемент 4</LI> <UL> <LI>Совсем вложенный сортированный список. Элемент 1</LI> <LI>Совсем вложенный сортированный список. Элемент 2</LI> </UL> <LI>Вложенный сортированный список. Элемент 5</LI> </OL> <UL> <LI>Вложенный несортированный список. Элемент 1</LI> </UL> </UL></P> </BODY> </HTML>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result, result)
def testImproved1 (self): src = u"""<ul><li>Несортированный список. Элемент 1</li><li>Несортированный список. Элемент 2</li><li>Несортированный список. Элемент 3</li><ol><li>Вложенный сортированный список. Элемент 1</li><li>Вложенный сортированный список. Элемент 2</li><li>Вложенный сортированный список. Элемент 3</li><li>Вложенный сортированный список. Элемент 4</li><ul><li>Совсем вложенный сортированный список. Элемент 1</li><li>Совсем вложенный сортированный список. Элемент 2</li></ul><li>Вложенный сортированный список. Элемент 5</li></ol><ul><li>Вложенный несортированный список. Элемент 1</li></ul></ul>""" expectedResult = u"""<!DOCTYPE html> <html> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge' /> <meta http-equiv='content-type' content='text/html; charset=utf-8'/> <style type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </style> </head> <body> <p> <ul> <li>Несортированный список. Элемент 1</li> <li>Несортированный список. Элемент 2</li> <li>Несортированный список. Элемент 3</li> <ol> <li>Вложенный сортированный список. Элемент 1</li> <li>Вложенный сортированный список. Элемент 2</li> <li>Вложенный сортированный список. Элемент 3</li> <li>Вложенный сортированный список. Элемент 4</li> <ul> <li>Совсем вложенный сортированный список. Элемент 1</li> <li>Совсем вложенный сортированный список. Элемент 2</li> </ul> <li>Вложенный сортированный список. Элемент 5</li> </ol> <ul> <li>Вложенный несортированный список. Элемент 1</li> </ul> </ul></p> </body> </html>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result, result)
def testImproved2 (self): src = ur"""<h2>Attach links</h2>Attach:file.odt<br><a href="__attach/file.odt">file.odt</a><br><a href="__attach/file.odt">alternative text</a><br><a href="__attach/file with spaces.pdf">file with spaces.pdf</a><h2>Images</h2>""" expectedResult = ur"""<h2>Attach links</h2> Attach:file.odt<br> <a href="__attach/file.odt">file.odt</a><br> <a href="__attach/file.odt">alternative text</a><br> <a href="__attach/file with spaces.pdf">file with spaces.pdf</a> <h2>Images</h2>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (readTextFile (templatepath).strip()) result = tpl.substitute (BrHtmlImprover().run (src)) self.assertIn (expectedResult, result)
def testImproved2(self): src = r"""<h2>Attach links</h2>Attach:file.odt<br><a href="__attach/file.odt">file.odt</a><br><a href="__attach/file.odt">alternative text</a><br><a href="__attach/file with spaces.pdf">file with spaces.pdf</a><h2>Images</h2>""" expectedResult = r"""<h2>Attach links</h2> Attach:file.odt<br> <a href="__attach/file.odt">file.odt</a><br> <a href="__attach/file.odt">alternative text</a><br> <a href="__attach/file with spaces.pdf">file with spaces.pdf</a> <h2>Images</h2>""" templatepath = os.path.join(getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate(readTextFile(templatepath).strip()) result = tpl.substitute(BrHtmlImprover().run(src)) self.assertIn(expectedResult, result)
def testImproved2 (self): src = ur"""<H2>Attach links</H2><P>Attach:file.odt<BR><A HREF="__attach/file.odt">file.odt</A><BR><A HREF="__attach/file.odt">alternative text</A><BR><A HREF="__attach/file with spaces.pdf">file with spaces.pdf</A><P><H2>Images</H2>""" expectedResult = ur"""<!DOCTYPE html> <HTML> <HEAD> <META HTTP-EQUIV='X-UA-Compatible' CONTENT='IE=edge' /> <META HTTP-EQUIV='CONTENT-TYPE' CONTENT='TEXT/HTML; CHARSET=UTF-8'/> <STYLE type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </STYLE> </HEAD> <BODY> <P> <H2>Attach links</H2></P> <P>Attach:file.odt <BR><A HREF="__attach/file.odt">file.odt</A> <BR><A HREF="__attach/file.odt">alternative text</A> <BR><A HREF="__attach/file with spaces.pdf">file with spaces.pdf</A></P> <P> <H2>Images</H2></P> </BODY> </HTML>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result)
def testImproved2 (self): src = ur"""<h2>Attach links</h2><p>Attach:file.odt<br><a href="__attach/file.odt">file.odt</a><br><a href="__attach/file.odt">alternative text</a><br><a href="__attach/file with spaces.pdf">file with spaces.pdf</a><p><h2>Images</h2>""" expectedResult = ur"""<!DOCTYPE html> <html> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge' /> <meta http-equiv='content-type' content='text/html; charset=utf-8'/> <style type='text/css'> body, div, p, table { font-size:10pt; font-family:Verdana; } img{border:none} </style> </head> <body> <p> <h2>Attach links</h2></p> <p>Attach:file.odt <br><a href="__attach/file.odt">file.odt</a> <br><a href="__attach/file.odt">alternative text</a> <br><a href="__attach/file with spaces.pdf">file with spaces.pdf</a></p> <p> <h2>Images</h2></p> </body> </html>""" templatepath = os.path.join (getTemplatesDir(), "__default", "__style.html") tpl = HtmlTemplate (templatepath) result = tpl.substitute (HtmlImprover.run (src) ) self.assertEqual (expectedResult, result)
def testException (self): templatepath = os.path.join (getTemplatesDir(), "html_invalid") self.assertRaises (IOError, HtmlTemplate, templatepath)