Esempio n. 1
0
def test_source_limits_on_change(listener, sources, low, high):
    source_limits = colors.SourceLimits()
    for source in sources:
        source_limits.add_source(source)
    source_limits.add_subscriber(listener)
    source_limits.on_change(None, None, None)  # attr, old, new
    listener.assert_called_once_with(colors.set_source_limits(low, high))
Esempio n. 2
0
def test_limits_reducer_source():
    low, high = 42, 1729
    action = colors.set_source_limits(low, high)
    state = colors.limits_reducer({}, action)
    origin = "column_data_source"
    assert state["colorbar"]["limits"][origin]["low"] == low
    assert state["colorbar"]["limits"][origin]["high"] == high
Esempio n. 3
0
def test_middleware_given_fixed_allows_source_limit_actions():
    log = Log()
    store = redux.Store(colors.reducer, middlewares=[colors.palettes, log])
    actions = [colors.set_source_limits(0, 100)]
    for action in actions:
        store.dispatch(action)
    assert log.actions == actions
    assert store.state == {"colorbar": {"low": 0, "high": 100}}
Esempio n. 4
0
def test_middleware_given_fixed_swallows_source_limit_actions():
    log = Log()
    store = redux.Store(colors.reducer, middlewares=[colors.palettes, log])
    actions = [colors.set_fixed(True), colors.set_source_limits(0, 100)]
    for action in actions:
        store.dispatch(action)
    assert log.actions == [colors.set_fixed(True)]
    assert store.state == {"colorbar": {"fixed": True}}
Esempio n. 5
0
    ({}, colors.set_palette_numbers([1, 2, 3]), {
        "colorbar": {
            "numbers": [1, 2, 3]
        }
    }),
    ({}, colors.set_user_high(100), {
        "colorbar": {
            "high": 100
        }
    }),
    ({}, colors.set_user_low(0), {
        "colorbar": {
            "low": 0
        }
    }),
    ({}, colors.set_source_limits(0, 100), {
        "colorbar": {
            "low": 0,
            "high": 100
        }
    }),
])
def test_reducer(state, action, expect):
    result = colors.reducer(state, action)
    assert expect == result


def test_reducer_immutable_state():
    state = {"colorbar": {"number": 1}}
    colors.reducer(state, colors.set_palette_number(3))
    assert state["colorbar"]["number"] == 1
Esempio n. 6
0
def test_middleware_given_fixed_allows_source_limit_actions():
    store = redux.Store(colors.reducer)
    action = colors.set_source_limits(0, 100)
    assert list(colors.palettes(store, action)) == [action]
Esempio n. 7
0
def test_middleware_given_fixed_swallows_source_limit_actions():
    store = redux.Store(colors.reducer, middlewares=[colors.palettes])
    store.dispatch(colors.set_fixed(True))
    action = colors.set_source_limits(0, 100)
    assert list(colors.palettes(store, action)) == []
    assert store.state == {"colorbar": {"fixed": True}}