Esempio n. 1
0
def test_spread_combine_with_f_vararg():
    h, f, g = Mock(), Mock(), Mock()
    restrict_arity(f, Arity(1, 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 == h.return_value
    assert get_arity(c) == Arity(4, 5)
Esempio n. 2
0
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)
Esempio n. 3
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)
Esempio n. 4
0
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)
Esempio n. 5
0
def test_compatibility_with_unbounded_arity():
    arity = Arity(2, False)
    assert not arity.is_compatible(1)
    assert arity.is_compatible(2)
    assert arity.is_compatible(3)
    assert arity.is_compatible(4)
Esempio n. 6
0
def test_compatibility_with_maximum_arity():
    arity = Arity(2, 3)
    assert not arity.is_compatible(1)
    assert arity.is_compatible(2)
    assert arity.is_compatible(3)
    assert not arity.is_compatible(4)
Esempio n. 7
0
def test_compatibility_with_fixed_arity():
    arity = Arity(2)
    assert not arity.is_compatible(1)
    assert arity.is_compatible(2)
    assert not arity.is_compatible(3)
Esempio n. 8
0
def test_spread_combine_f_and_g_cant_both_be_vararg():
    h, f, g = Mock(), Mock(), Mock()
    restrict_arity(f, Arity(2, 3))
    restrict_arity(g, Arity(2, 3))
    with pytest.raises(AssertionError):
        spread_combine(h, f, g)