1
|
|
|
from typing import Callable |
2
|
|
|
from unittest import TestCase |
3
|
|
|
from jacked._compatibility_impl import get_args_and_return_type |
4
|
|
|
from jacked._typing import NoneType |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class TestCompatibilityImpl(TestCase): |
8
|
|
|
|
9
|
|
|
def test_get_args_and_return_type(self): |
10
|
|
|
arg_types, return_type = get_args_and_return_type( |
11
|
|
|
Callable[[int, str], float]) |
12
|
|
|
|
13
|
|
|
self.assertEqual((int, str), arg_types) |
14
|
|
|
self.assertEqual(float, return_type) |
15
|
|
|
|
16
|
|
|
def test_get_args_and_return_type_no_args(self): |
17
|
|
|
arg_types, return_type = get_args_and_return_type( |
18
|
|
|
Callable[[], float]) |
19
|
|
|
|
20
|
|
|
self.assertEqual(tuple(), arg_types) |
21
|
|
|
self.assertEqual(float, return_type) |
22
|
|
|
|
23
|
|
|
def test_get_args_and_return_type_no_return_type(self): |
24
|
|
|
arg_types, return_type = get_args_and_return_type( |
25
|
|
|
Callable[[int, str], None]) |
26
|
|
|
|
27
|
|
|
self.assertEqual((int, str), arg_types) |
28
|
|
|
self.assertEqual(NoneType, return_type) |
29
|
|
|
|
30
|
|
|
def test_get_args_and_return_type_no_hints(self): |
31
|
|
|
arg_types1, return_type1 = get_args_and_return_type(Callable) |
32
|
|
|
arg_types2, return_type2 = get_args_and_return_type(callable) |
33
|
|
|
|
34
|
|
|
self.assertEqual(None, arg_types1) |
35
|
|
|
self.assertEqual(None, return_type1) |
36
|
|
|
self.assertEqual(None, arg_types2) |
37
|
|
|
self.assertEqual(None, return_type2) |
38
|
|
|
|