def test_spread_combine(): h, f, g = Mock(), Mock(), Mock() restrict_arity(f, 2) restrict_arity(g, 3) c = spread_combine(h, f, g) result = c(1, 2, 3, 4, 5) f.assert_called_once_with(1, 2) g.assert_called_once_with(3, 4, 5) h.assert_called_once_with(f.return_value, g.return_value) assert result is h.return_value assert get_arity(c) == Arity(5)
def test_spread_combine_with_g_vararg(): h, f, g = Mock(), Mock(), Mock() restrict_arity(f, 2) restrict_arity(g, Arity(0, False)) c = spread_combine(h, f, g) result = c(1, 2, 3, 4, 5) f.assert_called_once_with(1, 2) g.assert_called_once_with(3, 4, 5) h.assert_called_once_with(f.return_value, g.return_value) assert result == h.return_value assert get_arity(c) == Arity(2, False)
def test_get_arity_of_arbitrary_function(): assert get_arity(lambda: None) == Arity(0) assert get_arity(lambda x: None) == Arity(1) assert get_arity(lambda x, y, z: None) == Arity(3) assert get_arity(lambda x, y, z=0: None) == Arity(2, 3) assert get_arity(lambda *args: None) == Arity(0, False) assert get_arity(lambda **kwargs: None) == Arity(0)
def test_parallel_combine_arity_equals_arity_of_f_and_g(): h = restrict_arity(Mock(), 2) p = parallel_combine(h, lambda x, y, z: 0, lambda x, y, z: 0) assert get_arity(p) == Arity(3)
def test_composition_arity_equals_arity_of_g(): f = restrict_arity(Mock(), 1) h = compose(f, lambda x, y: 0) assert get_arity(h) == Arity(2)