Exemple #1
0
def test__double_stack_raises_when_kwargs_list_lengths_differ():
    with pytest.raises(ValueError) as e:
        bph._double_stack(['a', 'b'], 'foo', 'bar', baz=[1, 2], quux=[3, 4, 5])

    assert str(e.value).endswith(
        "Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [2, 3]"
    )
Exemple #2
0
def test__double_stack_raises_when_spec_in_kwargs():
    with pytest.raises(ValueError) as e:
        bph._double_stack(['a', 'b'], 'foo', 'bar', foo=10)

    assert str(e.value).endswith("Stack property 'foo' cannot appear in keyword args")

    with pytest.raises(ValueError) as e:
        bph._double_stack(['a', 'b'], 'foo', 'bar', bar=10)

    assert str(e.value).endswith("Stack property 'bar' cannot appear in keyword args")
Exemple #3
0
def test__double_stack_raises_when_spec_in_kwargs():
    with pytest.raises(ValueError) as e:
        bph._double_stack(['a', 'b'], 'foo', 'bar', foo=10)

    assert str(e).endswith("Stack property 'foo' cannot appear in keyword args")

    with pytest.raises(ValueError) as e:
        bph._double_stack(['a', 'b'], 'foo', 'bar', bar=10)

    assert str(e).endswith("Stack property 'bar' cannot appear in keyword args")
def test__double_stack_raises_when_kwargs_list_lengths_and_stackers_lengths_differ(
):
    with pytest.raises(ValueError) as e:
        bph._double_stack(['a', 'b', 'c'],
                          'foo',
                          'bar',
                          baz=[1, 2],
                          quux=[3, 4])

    assert str(e).endswith(
        "Keyword argument sequences for broadcasting must be the same length as stackers"
    )
Exemple #5
0
def test__double_stack_broadcast_with_no_kwargs():
    stackers = ['a', 'b', 'c', 'd']
    kws = bph._double_stack(stackers, 'start', 'end')
    assert len(kws) == len(stackers)
    for i, kw in enumerate(kws):
        assert set(['start', 'end', 'name']) == set(kw.keys())
        assert list(kw['start']['expr'].fields) == stackers[:i]
        assert list(kw['end']['expr'].fields) == stackers[:(i + 1)]
Exemple #6
0
def test__double_stack_broadcast_with_no_kwargs():
    stackers = ['a', 'b', 'c', 'd']
    kws = bph._double_stack(stackers, 'start', 'end')
    assert len(kws) == len(stackers)
    for i, kw in enumerate(kws):
        assert set(['start', 'end', 'name']) == set(kw.keys())
        assert list(kw['start']['expr'].fields) == stackers[:i]
        assert list(kw['end']['expr'].fields) == stackers[:(i+1)]
Exemple #7
0
def test__double_stack_broadcast_with_scalar_kwargs():
    stackers = ['a', 'b', 'c', 'd']
    kws = bph._double_stack(stackers, 'start', 'end', foo=10, bar="baz")
    assert len(kws) == len(stackers)
    for i, kw in enumerate(kws):
        assert set(['start', 'end', 'foo', 'bar', 'name']) == set(kw.keys())
        assert list(kw['start']['expr'].fields) == stackers[:i]
        assert list(kw['end']['expr'].fields) == stackers[:(i + 1)]
        assert kw['foo'] == 10
        assert kw['bar'] == "baz"
        assert kw['name'] == stackers[i]
Exemple #8
0
def test__double_stack_broadcast_name_scalar_overrides():
    stackers = ['a', 'b', 'c', 'd']
    kws = bph._double_stack(stackers, 'start', 'end', foo=[10, 20, 30, 40], bar="baz", name="name")
    assert len(kws) == len(stackers)
    for i, kw in enumerate(kws):
        assert set(['start', 'end', 'foo', 'bar', 'name']) == set(kw.keys())
        assert list(kw['start']['expr'].fields) == stackers[:i]
        assert list(kw['end']['expr'].fields) == stackers[:(i+1)]
        assert kw['foo'] == [10, 20, 30, 40][i]
        assert kw['bar'] == "baz"
        assert kw['name'] == "name"
Exemple #9
0
def test__double_stack_broadcast_name_scalar_overrides():
    stackers = ['a', 'b', 'c', 'd']
    kws = bph._double_stack(stackers, 'start', 'end', foo=[10, 20, 30, 40], bar="baz", name="name")
    assert len(kws) == len(stackers)
    for i, kw in enumerate(kws):
        assert set(['start', 'end', 'foo', 'bar', 'name']) == set(kw.keys())
        assert list(kw['start']['expr'].fields) == stackers[:i]
        assert list(kw['end']['expr'].fields) == stackers[:(i+1)]
        assert kw['foo'] == [10, 20, 30, 40][i]
        assert kw['bar'] == "baz"
        assert kw['name'] == "name"
Exemple #10
0
def test__double_stack_broadcast_with_scalar_kwargs():
    stackers = ['a', 'b', 'c', 'd']
    kws = bph._double_stack(stackers, 'start', 'end', foo=10, bar="baz")
    assert len(kws) == len(stackers)
    for i, kw in enumerate(kws):
        assert set(['start', 'end', 'foo', 'bar', 'name']) == set(kw.keys())
        assert list(kw['start']['expr'].fields) == stackers[:i]
        assert list(kw['end']['expr'].fields) == stackers[:(i+1)]
        assert kw['foo'] == 10
        assert kw['bar'] == "baz"
        assert kw['name'] == stackers[i]
Exemple #11
0
def test__double_stack_raises_when_kwargs_list_lengths_and_stackers_lengths_differ():
    with pytest.raises(ValueError) as e:
        bph._double_stack(['a', 'b', 'c'], 'foo', 'bar', baz=[1, 2], quux=[3,4])

    assert str(e).endswith("Keyword argument sequences for broadcasting must be the same length as stackers")