示例#1
0
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')
示例#2
0
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']])
示例#3
0
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'])
示例#4
0
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')
示例#5
0
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'])
示例#6
0
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'])
示例#7
0
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)
示例#8
0
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'])
示例#9
0
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'])
示例#10
0
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')
示例#11
0
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')
示例#12
0
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'])
示例#13
0
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'])
示例#14
0
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']])
示例#15
0
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'])
示例#16
0
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']])
示例#17
0
def test_direct(features):
    encoding = DirectColorEncoding(feature='custom_colors')
    values = encoding(features)
    assert_colors_equal(values, list(features['custom_colors']))