|
| 1 | +import pytest |
| 2 | + |
| 3 | +from rtichoke.processing.time_reference_lines import _apply_color_values_times |
| 4 | + |
| 5 | + |
| 6 | +def _curve_list(reference_groups, multiple_reference_groups=True): |
| 7 | + colors_dictionary = { |
| 8 | + "random_guess": "#BEBEBE", |
| 9 | + "perfect_model": "#BEBEBE", |
| 10 | + "treat_none": "#BEBEBE", |
| 11 | + "treat_all": "#BEBEBE", |
| 12 | + } |
| 13 | + for group in reference_groups: |
| 14 | + for key in ( |
| 15 | + group, |
| 16 | + f"random_guess_{group}", |
| 17 | + f"perfect_model_{group}", |
| 18 | + f"treat_none_{group}", |
| 19 | + f"treat_all_{group}", |
| 20 | + ): |
| 21 | + colors_dictionary[key] = "#000000" |
| 22 | + |
| 23 | + return { |
| 24 | + "reference_group_keys": reference_groups, |
| 25 | + "multiple_reference_groups": multiple_reference_groups, |
| 26 | + "colors_dictionary": colors_dictionary, |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | +def test_time_curve_custom_colors_propagate_to_groups_and_references(): |
| 31 | + curve_list = _curve_list(["model_a", "model_b"]) |
| 32 | + |
| 33 | + result = _apply_color_values_times(curve_list, ["#111111", "#222222"]) |
| 34 | + |
| 35 | + for group, expected_color in ( |
| 36 | + ("model_a", "#111111"), |
| 37 | + ("model_b", "#222222"), |
| 38 | + ): |
| 39 | + for key in ( |
| 40 | + group, |
| 41 | + f"random_guess_{group}", |
| 42 | + f"perfect_model_{group}", |
| 43 | + f"treat_none_{group}", |
| 44 | + f"treat_all_{group}", |
| 45 | + ): |
| 46 | + assert result["colors_dictionary"][key] == expected_color |
| 47 | + |
| 48 | + assert result["colors_dictionary"]["random_guess"] == "#BEBEBE" |
| 49 | + assert result["colors_dictionary"]["perfect_model"] == "#BEBEBE" |
| 50 | + assert result["colors_dictionary"]["treat_none"] == "#BEBEBE" |
| 51 | + assert result["colors_dictionary"]["treat_all"] == "#BEBEBE" |
| 52 | + |
| 53 | + |
| 54 | +def test_time_curve_single_model_keeps_existing_black_style(): |
| 55 | + curve_list = _curve_list(["model"], multiple_reference_groups=False) |
| 56 | + |
| 57 | + result = _apply_color_values_times(curve_list, ["#123456"]) |
| 58 | + |
| 59 | + assert result["colors_dictionary"]["model"] == "#000000" |
| 60 | + |
| 61 | + |
| 62 | +def test_time_curve_custom_colors_require_one_per_reference_group(): |
| 63 | + curve_list = _curve_list(["model_a", "model_b"]) |
| 64 | + |
| 65 | + with pytest.raises(ValueError, match="one color per reference group"): |
| 66 | + _apply_color_values_times(curve_list, ["#111111"]) |
0 commit comments