def test_constant_call_with_some_rows(): features = make_features_with_no_columns(num_rows=3) encoding = ConstantColorEncoding(constant='red') values = encoding(features) assert_colors_equal(values, 'red')
def test_quantitative_with_colormap_name(features): colormap = 'gray' encoding = QuantitativeColorEncoding(feature='confidence', colormap=colormap) values = encoding(features) assert_colors_equal(values, [[c] * 3 for c in features['confidence']])
def test_init_with_derived_color(): color = {'feature': 'colors'} features = pd.DataFrame({'colors': ['red', 'green', 'blue']}) text_manager = TextManager(color=color, features=features) actual = text_manager.color._values assert_colors_equal(actual, ['red', 'green', 'blue'])
def test_init_with_constant_color(): color = {'constant': 'red'} features = pd.DataFrame(index=range(3)) text_manager = TextManager(color=color, features=features) actual = text_manager.color._values assert_colors_equal(actual, 'red')
def test_init_with_manual_color(): color = ['red', 'green', 'blue'] features = pd.DataFrame({'class': ['A', 'B', 'C']}) text_manager = TextManager(color=color, features=features) actual = text_manager.color._values assert_colors_equal(actual, ['red', 'green', 'blue'])
def test_manual_with_more_rows(): features = make_features_with_no_columns(num_rows=4) array = ['red', 'green', 'cyan'] default = 'yellow' encoding = ManualColorEncoding(array=array, default=default) values = encoding(features) assert_colors_equal(values, ['red', 'green', 'cyan', 'yellow'])
def test_init_with_derived_color_missing_feature_then_use_fallback(): color = {'feature': 'not_a_feature', 'fallback': 'cyan'} features = pd.DataFrame({'colors': ['red', 'green', 'blue']}) with pytest.warns(RuntimeWarning): text_manager = TextManager(color=color, features=features) actual = text_manager.color._values assert_colors_equal(actual, ['cyan'] * 3)
def test_nominal_with_dict_cycle(features): colormap = ['red', 'yellow', 'green'] encoding = NominalColorEncoding( feature='class', colormap=colormap, ) values = encoding(features) assert_colors_equal(values, ['red', 'yellow', 'green'])
def test_refresh_with_manual_color(): color = ['red', 'green', 'blue'] features = pd.DataFrame(index=range(3)) text_manager = TextManager(color=color, features=features) text_manager.color = ['green', 'cyan', 'yellow'] text_manager.refresh(features) actual = text_manager.color._values assert_colors_equal(actual, ['green', 'cyan', 'yellow'])
def test_copy_paste_with_constant_color(): color = {'constant': 'blue'} features = pd.DataFrame(index=range(3)) text_manager = TextManager(color=color, features=features) copied = text_manager._copy([0, 2]) text_manager._paste(**copied) actual = text_manager.color._values assert_colors_equal(actual, 'blue')
def test_apply_with_constant_color(): color = {'constant': 'red'} features = pd.DataFrame({'class': ['A', 'B', 'C']}) text_manager = TextManager(color=color, features=features) features = pd.DataFrame({'class': ['A', 'B', 'C', 'D', 'E']}) text_manager.apply(features) actual = text_manager.color._values assert_colors_equal(actual, 'red')
def test_copy_paste_with_derived_color(): color = {'feature': 'colors'} features = pd.DataFrame({'colors': ['green', 'red', 'magenta']}) text_manager = TextManager(color=color, features=features) copied = text_manager._copy([0, 2]) text_manager._paste(**copied) actual = text_manager.color._values assert_colors_equal(actual, ['green', 'red', 'magenta', 'green', 'magenta'])
def test_copy_paste_with_manual_color(): color = ['magenta', 'red', 'yellow'] features = pd.DataFrame(index=range(3)) text_manager = TextManager(color=color, features=features) copied = text_manager._copy([0, 2]) text_manager._paste(**copied) actual = text_manager.color._values assert_colors_equal(actual, ['magenta', 'red', 'yellow', 'magenta', 'yellow'])
def test_quantitative_with_contrast_limits(features): colormap = 'gray' encoding = QuantitativeColorEncoding( feature='confidence', colormap=colormap, contrast_limits=(0, 2), ) values = encoding(features) assert encoding.contrast_limits == (0, 2) assert_colors_equal(values, [[c / 2] * 3 for c in features['confidence']])
def test_apply_with_manual_color_then_use_default(): color = { 'array': ['red', 'green', 'blue'], 'default': 'yellow', } features = pd.DataFrame({'class': ['A', 'B', 'C']}) text_manager = TextManager(color=color, features=features) features = pd.DataFrame({'class': ['A', 'B', 'C', 'D', 'E']}) text_manager.apply(features) actual = text_manager.color._values assert_colors_equal(actual, ['red', 'green', 'blue', 'yellow', 'yellow'])
def test_quantitative_with_colormap_values(features): colormap = ['black', 'red'] encoding = QuantitativeColorEncoding(feature='confidence', colormap=colormap) values = encoding(features) assert_colors_equal(values, [[c, 0, 0] for c in features['confidence']])
def test_direct(features): encoding = DirectColorEncoding(feature='custom_colors') values = encoding(features) assert_colors_equal(values, list(features['custom_colors']))