def test_call_all_kw(self, mocker): func = mocker.Mock() obj = injector.WantSignature( func, ['a', 'b', 'c'], set(['a']), set(['b', 'c']), False, True, ) result = obj( (), { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }, { 'b': 'b', 'f': 'f' }, ) assert result == func.return_value func.assert_called_once_with(a=1, b='b', c=3, d=4, e=5, f='f')
def test_init_overlap(self): with pytest.raises(ValueError): injector.WantSignature( 'func', ['a', 'b', 'c'], set(['a', 'b']), set(['b', 'c']), 'pos', 'kw', )
def test_contains_all_kw(self): obj = injector.WantSignature( 'func', ['a', 'b', 'c'], set(['a']), set(['b', 'c']), False, True, ) assert 'd' in obj
def test_contains_false(self): obj = injector.WantSignature( 'func', ['a', 'b', 'c'], set(['a']), set(['b', 'c']), False, False, ) assert 'd' not in obj
def test_call_missing(self, mocker): func = mocker.Mock() obj = injector.WantSignature( func, ['a', 'b', 'c'], set(['a']), set(['b', 'c']), False, False, ) with pytest.raises(TypeError): obj((), {'b': 2, 'c': 3, 'd': 4, 'e': 5}) func.assert_not_called()
def test_call_positional(self, mocker): func = mocker.Mock() obj = injector.WantSignature( func, ['self', 'a', 'b', 'c'], set(['self', 'a']), set(['b', 'c']), False, False, ) result = obj(('self', ), {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}) assert result == func.return_value func.assert_called_once_with('self', a=1, b=2, c=3)
def test_init_base(self): result = injector.WantSignature( 'func', ['a', 'b', 'c'], set(['a']), set(['b', 'c']), 'pos', 'kw', ) assert result.func == 'func' assert result.arg_order == ['a', 'b', 'c'] assert result.required == set(['a']) assert result.optional == set(['b', 'c']) assert result.all_pos == 'pos' assert result.all_kw == 'kw' assert result.all_args == set(['a', 'b', 'c'])
def test_call_too_many_positional(self, mocker): func = mocker.Mock() obj = injector.WantSignature( func, ['a', 'b', 'c'], set(['a']), set(['b', 'c']), False, False, ) with pytest.raises(TypeError): obj( ('a', 'b', 'c', 'd'), { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }, ) func.assert_not_called()