예제 #1
0
    def test_get_method_annotation_var_kw(self):
        def meth(obj, x: int, *args, **kwargs):
            pass

        schema = Schema()
        schema.instance_method('hello')(meth)
        instance_method = schema.hello

        expected = 'def hello(self, x: int, *args, **kwargs): ...'
        assert get_method_annotation('hello', instance_method) == expected
예제 #2
0
    def test_get_method_annotation_kwonly(self):
        def meth(obj, x: int, y: str = None, *, z=None, **kwargs) -> int:
            pass

        schema = Schema()
        schema.instance_method('hello')(meth)
        instance_method = schema.hello

        expected = 'def hello(self, x: int, y: str, *, z: typing.Any, **kwargs) -> int: ...'
        assert get_method_annotation('hello', instance_method) == expected
예제 #3
0
    def test_generate_stub_instance_methods(self):
        def meth1(thing, x: int) -> None:
            pass

        def meth2(thing, y: str) -> int:
            pass

        schema = Schema()
        schema.instance_method('hello')(meth1)
        schema.instance_method('goodbye')(meth2)

        stub = generate_stub(schema, 'Thing').split('\n')
        assert '    def hello(self, x: int) -> None: ...' in stub
        assert '    def goodbye(self, y: str) -> int: ...' in stub
예제 #4
0
 def test_instance_method_decorator(self, mock_method):
     schema = Schema()
     assert schema.instance_method('asdf') is mock_method.return_value
     mock_method.assert_called_once_with(schema, 'asdf')