Skip to content

Commit

Permalink
Test compatible with Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana committed Mar 28, 2013
1 parent a3ea593 commit 53691e5
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tests/test_tornado_cors.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import imp import imp
import functools import functools
import sys


from tornado.testing import AsyncHTTPTestCase from tornado.testing import AsyncHTTPTestCase
from tornado.web import Application, asynchronous, RequestHandler from tornado.web import Application, asynchronous, RequestHandler
Expand Down Expand Up @@ -60,19 +61,29 @@ def tearDown(self):
custom_decorator.wrapper = self.original_wrapper custom_decorator.wrapper = self.original_wrapper


def test_wrapper_customization(self): def test_wrapper_customization(self):
# assert default wrapper is being used version = sys.version_info[0]
wrapper_module_name = cors.CorsMixin.options.im_func.func_code.co_filename if version == 2:
self.assertFalse(passed_by_custom_wrapper) # assert default wrapper is being used
self.assertTrue(wrapper_module_name.endswith("tornado/web.py")) wrapper_module_name = cors.CorsMixin.options.im_func.func_code.co_filename
self.assertFalse(passed_by_custom_wrapper)
self.assertTrue(wrapper_module_name.endswith("tornado/web.py"))

self.assertEquals(cors.custom_decorator.wrapper, asynchronous)


# overwrite using custom wrapper and reload module # overwrite using custom wrapper and reload module
custom_decorator.wrapper = custom_wrapper custom_decorator.wrapper = custom_wrapper
imp.reload(cors) imp.reload(cors)


# assert new wrapper is being used if version == 2:
wrapper_module_name = cors.CorsMixin.options.im_func.func_code.co_filename # assert new wrapper is being used
self.assertTrue(passed_by_custom_wrapper) wrapper_module_name = cors.CorsMixin.options.im_func.func_code.co_filename
self.assertTrue(wrapper_module_name.endswith("tests/test_tornado_cors.py")) self.assertTrue(passed_by_custom_wrapper)
self.assertTrue(wrapper_module_name.endswith("tests/test_tornado_cors.py"))

self.assertEquals(cors.custom_decorator.wrapper, custom_wrapper)







class DefaultValuesHandler(cors.CorsMixin, RequestHandler): class DefaultValuesHandler(cors.CorsMixin, RequestHandler):
Expand Down

0 comments on commit 53691e5

Please sign in to comment.