def test_config_set_flag_json() -> None: config = Config() config.set_flags(json=False) assert config.always_output_json is False config = Config() config.set_flags(json=True) assert config.always_output_json is True
def test_config_set_flag_units() -> None: config = Config() config.set_flags(units=False) assert config.display_degree_symbol is False assert config.display_percent_symbol is False config = Config() config.set_flags(units=True) assert config.display_degree_symbol is True assert config.display_percent_symbol is True
def test_config_update() -> None: config = Config() config.update(config.dump()) assert config == Config()
def test_config_set_flag_shades() -> None: config = Config() config.set_flags(shades=True) assert config.default_shades_count == DEFAULT_SHADES_COUNT config = Config() config.set_flags(shades=False) assert config.default_shades_count == 0 config = Config() config.set_flags(shades=None) assert config.default_shades_count == 15 config = Config() config.set_flags(shades=10) assert config.default_shades_count == 10
def test_config_set_flag_all() -> None: config = Config() view_keys = frozenset(("name", "hex")) config.get_view_keys = view_keys config.list_view_keys = view_keys config.json_keys = view_keys config.set_flags(all=None) assert config.get_view_keys == view_keys assert config.list_view_keys == view_keys assert config.json_keys == view_keys config.set_flags(all=False) assert config.get_view_keys == view_keys assert config.list_view_keys == view_keys assert config.json_keys == view_keys config.set_flags(all=True) assert config.get_view_keys == VIEW_KEYS assert config.list_view_keys == VIEW_KEYS assert config.json_keys == JSON_KEYS
def test_config_update_bad_key(key: str) -> None: config = Config() with pytest.raises(ConfigKeyError) as err: config.update({key: None}) assert str(err.value).startswith("Bad configuration key")
def test_config_update_bad_data_format(data: Any) -> None: config = Config() with pytest.raises(ConfigFileError) as err: # noinspection PyTypeChecker config.update(data) assert str(err.value).startswith("B")
import pytest from colorpedia.color import Color from colorpedia.config import Config from colorpedia.formatters import ( format_cmyk, format_get_view, format_hex, format_hsl, format_hsv, format_list_view, format_name, format_rgb, ) default_config = Config() custom_config = Config() custom_config.uppercase_hex_codes = False custom_config.get_view_keys = frozenset(("name", "hex")) custom_config.list_view_keys = frozenset(("name", "hex")) custom_config.approx_name_suffix = "*" custom_config.set_flags(units=True) @pytest.mark.parametrize( ("c", "m", "y", "k", "expected"), ( (0.000, 0.010, 0.020, 0.030, "C:0 M:1 Y:2 K:3 "), (0.104, 0.204, 0.304, 0.404, "C:10 M:20 Y:30 K:40 "), (0.106, 0.206, 0.306, 0.406, "C:11 M:21 Y:31 K:41 "),
def print_config(config: Config, sort: bool = True, indent: int = 2): print(json_dumps(config.dump(), sort_keys=sort, indent=indent))
def test_config_update_bad_value(key): config = Config() with pytest.raises(ConfigValueError) as err: config.update({key: None}) assert str(err.value).startswith("Bad value for configuration key")