|
| 1 | +import pytest |
| 2 | + |
| 3 | +from rt_utils.utils import COLOR_PALETTE |
| 4 | +from tests.test_rtstruct_builder import get_empty_mask |
| 5 | + |
| 6 | + |
| 7 | +VALID_COLORS = [ |
| 8 | + ('fff', [255, 255, 255]), |
| 9 | + ('#fff', [255, 255, 255]), |
| 10 | + (None, COLOR_PALETTE[0]), |
| 11 | + (COLOR_PALETTE[1], COLOR_PALETTE[1]), |
| 12 | + ('#696969', [105, 105, 105]), |
| 13 | + ('a81414', [168, 20, 20]), |
| 14 | + ('#000', [0, 0, 0]), |
| 15 | +] |
| 16 | + |
| 17 | +INVALID_COLORS = [ |
| 18 | + ('GGG', ValueError), |
| 19 | + ('red', ValueError), |
| 20 | + ('22', ValueError), |
| 21 | + ('[]', ValueError), |
| 22 | + ([], ValueError), |
| 23 | + ([24, 34], ValueError), |
| 24 | + ([24, 34, 454], ValueError), |
| 25 | + ([0, 344, 0], ValueError), |
| 26 | + ('a8141', ValueError), |
| 27 | + ('a814111', ValueError), |
| 28 | + (KeyboardInterrupt, ValueError), |
| 29 | +] |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize('color', VALID_COLORS) |
| 33 | +def test_mask_colors(new_rtstruct, color): |
| 34 | + color_in, color_out = color |
| 35 | + |
| 36 | + name = "Test ROI" |
| 37 | + mask = get_empty_mask(new_rtstruct) |
| 38 | + mask[50:100, 50:100, 0] = 1 |
| 39 | + |
| 40 | + new_rtstruct.add_roi(mask, color=color_in, name=name) |
| 41 | + assert new_rtstruct.ds.ROIContourSequence[0].ROIDisplayColor == color_out |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.parametrize('color', INVALID_COLORS) |
| 45 | +def test_mask_colors_fail(new_rtstruct, color): |
| 46 | + color_in, err = color |
| 47 | + |
| 48 | + name = "Test ROI" |
| 49 | + mask = get_empty_mask(new_rtstruct) |
| 50 | + mask[50:100, 50:100, 0] = 1 |
| 51 | + |
| 52 | + with pytest.raises(err): |
| 53 | + new_rtstruct.add_roi(mask, color=color_in, name=name) |
0 commit comments