from cherrypy.test import test
test.prefer_parent_path()
import os
localDir = os.path.join(os.getcwd(), os.path.dirname(__file__))
tidy_path = os.path.join(localDir, "tidy")
import cherrypy
from cherrypy import tools
doctype = ('')
def setup_server():
class Root:
_cp_config = {
'tools.tidy.on': True,
'tools.tidy.tidy_path': tidy_path,
'tools.tidy.temp_dir': localDir,
}
def plaintext(self):
yield "Hello, world"
plaintext.exposed = True
plaintext._cp_config = {'tools.tidy.warnings': False}
def validhtml(self):
return "
This should be valid
"
validhtml.exposed = True
validhtml._cp_config = {'tools.tidy.warnings': False}
def warning(self, skip_doctype=False):
if skip_doctype:
# This should raise a warning
pass
else:
yield doctype
yield "Meh"
yield "Normal body"
warning.exposed = True
cherrypy.config.update({'environment': 'test_suite'})
cherrypy.tree.mount(Root())
from cherrypy.test import helper
class TidyTest(helper.CPWebCase):
def test_Tidy_Tool(self):
if not os.path.exists(tidy_path) and not os.path.exists(tidy_path + ".exe"):
print "skipped (tidy not found) ",
return
self.getPage('/validhtml')
self.assertStatus(200)
self.assertBody("This should be valid
")
self.getPage('/plaintext')
self.assertStatus(200)
self.assertBody('Hello, world')
self.getPage('/warning')
self.assertStatus(200)
self.assertBody(doctype + "Meh"
"Normal body")
self.getPage('/warning?skip_doctype=YES')
self.assertStatus(200)
self.assertInBody("Wrong HTML")
if __name__ == "__main__":
setup_server()
helper.testmain()