1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
# -*- coding: utf-8 -*-
from typing import Dict, Union
import pytest
from _pytest.fixtures import SubRequest
from DisplayCAL.argyll_instruments import (
get_canonical_instrument_name,
remove_vendor_names,
)
from DisplayCAL.cgats import CGATS
INSTR_STR = "i1 DisplayPro, ColorMunki Display"
INSTR_STR_INVERSE = "eye-one displayPro, ColorMunki Display"
REPLACEMENT_STR_STR = {
"DTP94-LCD mode": "DTP94",
"eye-one display": "i1 Display",
"Spyder 2 LCD": "Spyder2",
"Spyder 3": "Spyder3",
}
REPLACEMENT_BSTR_BSTR = {
b"DTP94-LCD mode": b"DTP94",
b"eye-one display": b"i1 Display",
b"Spyder 2 LCD": b"Spyder2",
b"Spyder 3": b"Spyder3",
}
REPLACEMENT_STR_BSTR = {
"DTP94-LCD mode": b"DTP94",
"eye-one display": b"i1 Display",
"Spyder 2 LCD": b"Spyder2",
"Spyder 3": b"Spyder3",
}
REPLACEMENT_BSTR_STR = {
b"DTP94-LCD mode": "DTP94",
b"eye-one display": "i1 Display",
b"Spyder 2 LCD": "Spyder2",
b"Spyder 3": "Spyder3",
}
@pytest.fixture(
scope="session",
name="inst_str_format",
params=("instrument_byte", "instrument_str"),
)
def fixture_inst_str_format(request: SubRequest) -> str:
""" "Return string format of instrument."""
return request.param
@pytest.fixture(scope="module", name="target_instrument")
def fixture_target_instrument(inst_str_format: str, data_files) -> Union[bytes, str]:
"""Return target instrument."""
path = data_files["0_16.ti3"]
cgats = CGATS(path)
if inst_str_format == "instrument_byte":
target_instrument = cgats.queryv1("TARGET_INSTRUMENT")
assert target_instrument == b"X-Rite i1 DisplayPro, ColorMunki Display"
else:
target_instrument = cgats.queryv1("TARGET_INSTRUMENT").decode("utf-8")
assert target_instrument == "X-Rite i1 DisplayPro, ColorMunki Display"
return target_instrument
@pytest.mark.parametrize("inverse", (True, False), ids=("inverse", "not inverse"))
@pytest.mark.parametrize(
"replacement",
(
REPLACEMENT_STR_STR,
REPLACEMENT_BSTR_BSTR,
REPLACEMENT_BSTR_STR,
REPLACEMENT_STR_BSTR,
None,
),
ids=(
"rep_string-string",
"rep_bytes-bytes",
"rep_bytes-string",
"rep_string-bytes",
"no replacement",
),
)
def test_get_canonical_instrument_name(
replacement: Dict[Union[str, bytes], Union[str, bytes]],
target_instrument: Union[bytes, str],
inverse: bool,
) -> None:
"""Test argyll_instruments.get_canonical_instrument_name()."""
result = get_canonical_instrument_name(target_instrument, replacement, inverse)
if inverse and replacement:
expected_result = (
INSTR_STR_INVERSE.encode("utf-8")
if isinstance(target_instrument, bytes)
else INSTR_STR_INVERSE
)
else:
expected_result = (
INSTR_STR.encode("utf-8")
if isinstance(target_instrument, bytes)
else INSTR_STR
)
assert result == expected_result
def test_remove_vendor_names(target_instrument: Union[bytes, str]) -> None:
"""testing the argyll_instruments.remove_vendor_names() function"""
if isinstance(target_instrument, str):
pytest.skip()
result = remove_vendor_names(target_instrument)
expected_result = b"i1 DisplayPro, ColorMunki Display"
assert result == expected_result
|