Created
December 15, 2016 05:34
-
-
Save judeaugustinej/31f7a4291a78837b10c804097435a2fe to your computer and use it in GitHub Desktop.
Test Coverage for tornado app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.set_status(400) | |
self.write("Hello, world") | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tornado==4.4.2 | |
coverage==4.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import tornado.ioloop | |
from tornado.httpclient import HTTPRequest | |
from tornado.testing import AsyncHTTPTestCase, gen_test | |
from hello import application | |
class SimpleTest(AsyncHTTPTestCase): | |
def get_app(self): | |
return application | |
def get_new_ioloop(self): | |
return tornado.ioloop.IOLoop.instance() | |
@gen_test | |
def test_bad_request(self): | |
request = HTTPRequest(url=self.get_url('/')) | |
with self.assertRaises(tornado.httpclient.HTTPError) as context: | |
yield self.http_client.fetch(request) | |
self.assertEqual(context.exception.code, 400) | |
if __name__ == "__main__": | |
unittest.main(verbosity=2) | |
# in cmdline run | |
# coverage run --source=. --omit=env/* test_hello.py | |
# coverage report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment