diff --git a/openadapt/config.py b/openadapt/config.py index 1659b20a4..1c1b3665b 100644 --- a/openadapt/config.py +++ b/openadapt/config.py @@ -41,7 +41,7 @@ "SCRUB_CHAR": "*", "SCRUB_LANGUAGE": "en", # TODO support lists in getenv_fallback - "SCRUB_FILL_COLOR": 0xFF0000, + "SCRUB_FILL_COLOR": 0x0000FF, "SCRUB_CONFIG_TRF": { "nlp_engine_name": "spacy", "models": [{"lang_code": "en", "model_name": "en_core_web_trf"}], diff --git a/tests/openadapt/test_scrub.py b/tests/openadapt/test_scrub.py index 2a8db073f..a9358cb7c 100644 --- a/tests/openadapt/test_scrub.py +++ b/tests/openadapt/test_scrub.py @@ -9,22 +9,18 @@ from openadapt import scrub, config -def _hex_to_rgb(hex_value): - hex_value = hex(hex_value) # Convert integer to hex string - hex_value = hex_value.lstrip('0x') # Remove '0x' if present - - if len(hex_value) != 6: - raise ValueError("Invalid hex value. Must be in the format '0xXXXXXX'.") - - try: - b = int(hex_value[0:2], 16) - g = int(hex_value[2:4], 16) - r = int(hex_value[4:6], 16) - except ValueError: - raise ValueError("Invalid hex value. Must be in the format '0xXXXXXX'.") +def _hex_to_rgb(hex_color: int) -> tuple[int, int, int]: + """ + Convert a hex color (int) to RGB + """ + assert 0x000000 <= hex_color <= 0xFFFFFF + b = (hex_color >> 16) & 0xFF + g = (hex_color >> 8) & 0xFF + r = hex_color & 0xFF return r, g, b + def test_scrub_image() -> None: """ Test that the scrubbed image data is different @@ -53,7 +49,8 @@ def test_scrub_image() -> None: # Count the number of pixels having the color of the mask mask_pixels = sum( - 1 for pixel in scrubbed_image.getdata() if pixel == _hex_to_rgb(config.SCRUB_FILL_COLOR) + 1 for pixel in scrubbed_image.getdata() + if pixel == _hex_to_rgb(config.SCRUB_FILL_COLOR) ) total_pixels = scrubbed_image.width * scrubbed_image.height