From ab259cf3711c72bd39a74746d762117edab7defa Mon Sep 17 00:00:00 2001 From: Krish Patel Date: Fri, 11 Aug 2023 11:28:24 -0400 Subject: [PATCH 1/3] remove scrbu.py old moidule --- openadapt/scrub.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 openadapt/scrub.py diff --git a/openadapt/scrub.py b/openadapt/scrub.py deleted file mode 100644 index e69de29bb..000000000 From 26cd07ccd0cb8e417a4e38e6526c5f5ce579ed26 Mon Sep 17 00:00:00 2001 From: Krish Patel Date: Fri, 11 Aug 2023 11:34:20 -0400 Subject: [PATCH 2/3] format test script --- .../privacy/providers/test_presidio_scrub.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/openadapt/privacy/providers/test_presidio_scrub.py b/tests/openadapt/privacy/providers/test_presidio_scrub.py index 443602c40..2da5bbe67 100644 --- a/tests/openadapt/privacy/providers/test_presidio_scrub.py +++ b/tests/openadapt/privacy/providers/test_presidio_scrub.py @@ -6,18 +6,16 @@ import warnings from PIL import Image -import pytest -from openadapt import config, scrub +from openadapt import config from openadapt.privacy.base import Modality, ScrubbingProviderFactory from openadapt.privacy.providers.presidio import PresidioScrubbingProvider scrub = PresidioScrubbingProvider() -def test_scrubbing_provider_factory(): - """Test the ScrubbingProviderFactory for Modality.TEXT in PresidioScrubbingProvider.""" - +def test_scrubbing_provider_factory() -> None: + """Test the ScrubbingProviderFactory for Modality.TEXT.""" providers = ScrubbingProviderFactory.get_for_modality(Modality.TEXT) # Ensure that we get at least one provider @@ -31,9 +29,8 @@ def test_scrubbing_provider_factory(): assert Modality.TEXT in provider.capabilities -def test_presidio_scrub_text(): +def test_presidio_scrub_text() -> None: """Test that PresidioScrubbingProvider can scrub text.""" - text = "My phone number is 123-456-7890." expected_result = "My phone number is ." @@ -52,10 +49,10 @@ def _hex_to_rgb(hex_color: int) -> tuple[int, int, int]: tuple[int, int, int]: RGB values. """ assert 0x000000 <= hex_color <= 0xFFFFFF - b = (hex_color >> 16) & 0xFF - g = (hex_color >> 8) & 0xFF - r = hex_color & 0xFF - return r, g, b + blue = (hex_color >> 16) & 0xFF + green = (hex_color >> 8) & 0xFF + red = hex_color & 0xFF + return red, green, blue def test_scrub_image() -> None: @@ -85,7 +82,7 @@ def test_scrub_image() -> None: mask_pixels = sum( 1 for pixel in scrubbed_image.getdata() - if pixel == _hex_to_rgb(config.SCRUB_FILL_COLOR) + if pixel == _hex_to_rgb(config.SCRUB_FILL_COLOR) # pylint: disable=no-member ) total_pixels = scrubbed_image.width * scrubbed_image.height From a6c9d370f1ec5f51542fa17432343e714cf1956c Mon Sep 17 00:00:00 2001 From: Krish Patel Date: Fri, 11 Aug 2023 11:43:05 -0400 Subject: [PATCH 3/3] format base.py and presidio.py --- openadapt/privacy/base.py | 16 ++++++++-------- openadapt/privacy/providers/presidio.py | 7 +++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/openadapt/privacy/base.py b/openadapt/privacy/base.py index bbad7e7db..533bb02f0 100644 --- a/openadapt/privacy/base.py +++ b/openadapt/privacy/base.py @@ -1,15 +1,15 @@ -"""The Base (Parent) Class for Privacy Scrubbing Providers""" +"""The Base (Parent) Class for Privacy Scrubbing Providers.""" from typing import List from PIL import Image -from pydantic import BaseModel +from pydantic import BaseModel # pylint: disable=no-name-in-module from openadapt import config class Modality: # pylint: disable=too-few-public-methods - """A Base Class for Modality Types""" + """A Base Class for Modality Types.""" TEXT = "TEXT" PIL_IMAGE = "PIL_IMAGE" @@ -18,13 +18,13 @@ class Modality: # pylint: disable=too-few-public-methods class ScrubbingProvider(BaseModel): - """A Base Class for Scrubbing Providers""" + """A Base Class for Scrubbing Providers.""" name: str capabilities: List[str] class Config: # pylint: disable=too-few-public-methods - """Pydantic Config Class""" + """Pydantic Config Class.""" arbitrary_types_allowed = True @@ -74,7 +74,7 @@ def scrub_mp4( # pylint: disable=too-many-arguments playback_speed_multiplier: float = 1.0, crop_start_time: int = 0, crop_end_time: int | None = None, - ): + ) -> str: """Scrub a mp4 file. Args: @@ -91,13 +91,13 @@ def scrub_mp4( # pylint: disable=too-many-arguments class ScrubbingProviderFactory: # pylint: disable=too-few-public-methods - """A Factory Class for Scrubbing Providers""" + """A Factory Class for Scrubbing Providers.""" @staticmethod def get_for_modality( modality: Modality, ) -> List[ScrubbingProvider]: - """Get Scrubbing Providers for a given Modality + """Get Scrubbing Providers for a given Modality. Args: modality (Modality): Modality Type diff --git a/openadapt/privacy/providers/presidio.py b/openadapt/privacy/providers/presidio.py index 4ed8d7d25..6bee4207c 100644 --- a/openadapt/privacy/providers/presidio.py +++ b/openadapt/privacy/providers/presidio.py @@ -1,4 +1,4 @@ -""" A Module for Presidio Scrubbing Provider Class """ +"""A Module for Presidio Scrubbing Provider Class.""" from typing import List @@ -14,7 +14,7 @@ class PresidioScrubbingProvider(ScrubbingProvider): # pylint: disable=W0223 - """A Class for Presidio Scrubbing Provider""" + """A Class for Presidio Scrubbing Provider.""" name: str = config.SCRUB_PROVIDER_NAME[0] # pylint: disable=E1101 capabilities: List[Modality] = [Modality.TEXT, Modality.PIL_IMAGE] @@ -187,8 +187,7 @@ def scrub_dict( def scrub_list_dicts( self, input_list: list[dict], list_keys: list = None ) -> list[dict]: - """Scrub list of dicts to remove PII/PHI - using Presidio ANALYZER.TRF and Anonymizer. + """Scrub list of dicts to remove PII/PHI. Args: input_list (list[dict]): A list of dicts to be scrubbed