File: cythonapp_test.py

package info (click to toggle)
python-tornado 6.2.0-3%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,396 kB
  • sloc: python: 27,837; javascript: 156; sh: 99; ansic: 58; xml: 49; makefile: 48; sql: 23
file content (35 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from tornado.testing import AsyncTestCase, gen_test
from tornado.util import ArgReplacer
import unittest

import cythonapp


class CythonCoroutineTest(AsyncTestCase):
    @gen_test
    def test_native_coroutine(self):
        x = yield cythonapp.native_coroutine()
        self.assertEqual(x, "goodbye")

    @gen_test
    def test_decorated_coroutine(self):
        x = yield cythonapp.decorated_coroutine()
        self.assertEqual(x, "goodbye")


class CythonArgReplacerTest(unittest.TestCase):
    def test_arg_replacer_function(self):
        replacer = ArgReplacer(cythonapp.function_with_args, 'two')
        args = (1, 'old', 3)
        kwargs = {}
        self.assertEqual(replacer.get_old_value(args, kwargs), 'old')
        self.assertEqual(replacer.replace('new', args, kwargs),
                         ('old', [1, 'new', 3], {}))

    def test_arg_replacer_method(self):
        replacer = ArgReplacer(cythonapp.AClass().method_with_args, 'two')
        args = (1, 'old', 3)
        kwargs = {}
        self.assertEqual(replacer.get_old_value(args, kwargs), 'old')
        self.assertEqual(replacer.replace('new', args, kwargs),
                         ('old', [1, 'new', 3], {}))