示例#1
0
def test_add_xy01_limits_ylim1s(direction, limit, padding):
    if limit.startswith("zero"):
        expected = 0
    elif limit.startswith("fixed"):
        expected = 6
    elif limit.startswith("follow"):
        expected = np.array([5.0, 6, 5])
    elif limit.startswith("explore"):
        expected = np.array([5.0, 6, 6])

    if padding is not None:
        expected += padding
        limit = f"{limit}_{padding}"

    ah_array1 = ah.Array([0, 1, 0], [3, 4, 5],
                         ylim1s=limit,
                         ymargins=0,
                         frames=1)
    ah_array2 = ah.Array([-1, 1, -2], [5, 6, -5])

    ah_objs = [ah_array1, ah_array2]
    if direction == "backward":
        ah_objs = ah_objs[::-1]
    ah_obj = ah.merge(ah_objs).finalize()
    ds = ah_obj[1, 1]

    actual = ds["ylim1"].values
    assert np.isclose(actual, expected).all()
示例#2
0
def test_add_xy01_limits_xlim0s(direction, limit, padding):
    # TODO: test datetimes, strings
    if limit.startswith("zero"):
        expected = 0
    elif limit.startswith("fixed"):
        expected = -2
    elif limit.startswith("follow"):
        expected = np.array([-1.0, 1, -2])
    elif limit.startswith("explore"):
        expected = np.array([-1.0, -1, -2])

    if padding is not None:
        expected -= padding
        limit = f"{limit}_{padding}"

    ah_array1 = ah.Array([0, 1, 0], [3, 4, 5],
                         xlim0s=limit,
                         xmargins=0,
                         frames=1)
    ah_array2 = ah.Array([-1, 1, -2], [5, 6, -5])

    ah_objs = [ah_array1, ah_array2]
    if direction == "backward":
        ah_objs = ah_objs[::-1]
    ah_obj = ah.merge(ah_objs).finalize()
    ds = ah_obj[1, 1]

    actual = ds["xlim0"].values
    assert np.isclose(actual, expected).all()
示例#3
0
def test_match_states(direction, join):
    ah_objs = [ah_array1, ah_array2]
    if join == "cascade":
        num_states = 3
    elif direction == "backward":
        ah_objs = ah_objs[::-1]
        num_states = 2
    else:
        num_states = 2

    ah_obj = ah.merge(ah_objs, join=join)
    for ds in ah_obj.data.values():
        assert len(ds["state"]) == num_states
示例#4
0
def test_propagate_params(direction, join):
    x = [0, 1]
    y = [2, 3]
    args = x, y
    a = ah.Array(
        *args,
        **canvas1_params,
        **subplot1_params,
        **geo1_params,
        **label1_params,
    )
    b = ah.Reference(
        *args,
        **canvas2_params,
    )
    c = ah.Array(
        *args,
        **canvas2_params,
        **subplot2_params,
        **geo2_params,
        **label2_params,
    )
    ah_objs = [a, b, c]

    all1_params = {
        **canvas1_params,
        **subplot1_params,
        **geo1_params,
        **label1_params,
    }
    all2_params = {
        **canvas2_params,
        **subplot2_params,
        **geo2_params,
        **label2_params,
    }
    if direction == "backward":
        all1_params, all2_params = all2_params, all1_params
        ah_objs = ah_objs[::-1]

    ah_obj = ah.merge(ah_objs, join=join)
    for param in all1_params:
        configurable = PARAMS[param]
        key = f"{configurable}_kwds"
        method_key = CONFIGURABLES_KWDS[configurable][param]
        actual = ah_obj[1, 1].attrs[key][method_key]
        expected = all1_params[param]
        assert actual == expected

    for param in all2_params:
        configurable = PARAMS[param]
        key = f"{configurable}_kwds"
        method_key = CONFIGURABLES_KWDS[configurable][param]
        expected = all2_params[param]
        if join == "layout" and param not in CONFIGURABLES["canvas"]:
            actual = ah_obj[1, 3].attrs[key][method_key]
            assert actual == expected
        else:
            actual = ah_obj[1, 1].attrs[key][method_key]
            if param in all1_params:
                assert actual != expected
            else:
                assert actual == expected
示例#5
0
def test_shift_items(direction, join):
    ah_objs = [ah_array1, ah_array1]
    if direction == "backward":
        ah_objs = ah_objs[::-1]
    ah_obj = ah.merge(ah_objs, join=join)
    assert len(ah_obj.data[1, 1]["item"]) == 2
示例#6
0
def test_config_legend_show(num_items):
    ah_obj = ah.merge([ah_array1 for _ in range(num_items)]).finalize()
    ds = ah_obj[1, 1]
    assert not ds.attrs["legend_kwds"]["show"]