forked from venetoarpa/arpav-cline-backend
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
legend not working for some coverage configurations (#244)
* Fixed incorrect admin schema for coverage confs due to changing unit to unit_english and introducing unit_italian * Fixed incorrect parsing of palette files
- Loading branch information
1 parent
b771b70
commit 04f9d81
Showing
3 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from pathlib import Path | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from arpav_ppcv import palette | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"palette_name, expected", | ||
[ | ||
pytest.param( | ||
"fake-palette1", ["#fake-color-1", "#fake-color-2", "#fake-color-3"] | ||
), | ||
pytest.param( | ||
"fake-palette1-inv", ["#fake-color-3", "#fake-color-2", "#fake-color-1"] | ||
), | ||
pytest.param( | ||
"default/fake-palette1", ["#fake-color-1", "#fake-color-2", "#fake-color-3"] | ||
), | ||
pytest.param( | ||
"uncert-stippled/fake-palette1", | ||
["#fake-color-1", "#fake-color-2", "#fake-color-3"], | ||
), | ||
pytest.param( | ||
"default/fake-palette1-inv", | ||
["#fake-color-3", "#fake-color-2", "#fake-color-1"], | ||
), | ||
pytest.param( | ||
"fake-palette2", ["#fake-color-4", "#fake-color-5", "#fake-color-6"] | ||
), | ||
pytest.param( | ||
"fake-palette2-inv", ["#fake-color-6", "#fake-color-5", "#fake-color-4"] | ||
), | ||
pytest.param("other", None), | ||
pytest.param("nonsense", None), | ||
], | ||
) | ||
def test_parse_palette(palette_name: str, expected: list[str]): | ||
fake_palette1_contents = [ | ||
"#fake-color-1", | ||
"#fake-color-2", | ||
"#fake-color-3", | ||
] | ||
fake_palette2_contents = [ | ||
"#fake-color-4", | ||
"#fake-color-5", | ||
"#fake-color-6", | ||
"this is not a color", | ||
"%this is also not a color", | ||
] | ||
fake_other_contents = [ | ||
"something-else", | ||
] | ||
fake_palette1 = mock.MagicMock(spec=Path) | ||
fake_palette1.configure_mock( | ||
**{ | ||
"stem": "fake-palette1", | ||
"read_text.return_value": "\n".join(fake_palette1_contents), | ||
"is_file.return_value": True, | ||
} | ||
) | ||
fake_palette2 = mock.MagicMock( | ||
spec=Path, | ||
**{ | ||
"stem": "fake-palette2", | ||
"read_text.return_value": "\n".join(fake_palette2_contents), | ||
"is_file.return_value": True, | ||
}, | ||
) | ||
fake_other = mock.MagicMock( | ||
spec=Path, | ||
**{ | ||
"stem": "other", | ||
"read_text.return_value": "\n".join(fake_other_contents), | ||
"is_file.return_value": True, | ||
}, | ||
) | ||
mock_palettes_dir = mock.MagicMock(spec=Path) | ||
mock_palettes_dir.iterdir.return_value = [ | ||
fake_palette1, | ||
fake_palette2, | ||
fake_other, | ||
] | ||
result = palette.parse_palette(palette_name, mock_palettes_dir) | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"colors, minimum, maximum, expected", | ||
[ | ||
pytest.param( | ||
["first", "second"], -10, 20, [(-10.0, "first"), (20.0, "second")] | ||
), | ||
pytest.param( | ||
["first", "second", "third"], | ||
-10, | ||
20, | ||
[(-10.0, "first"), (5.0, "second"), (20.0, "third")], | ||
), | ||
], | ||
) | ||
def test_apply_palette( | ||
colors: list[str], minimum: float, maximum: float, expected: list[tuple[float, str]] | ||
): | ||
result = palette.apply_palette(colors, minimum, maximum) | ||
assert result == expected |