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))
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
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}}
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}}
({}, 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
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]
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}}