Skip to content

Commit

Permalink
chore: fix python warnings (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamagalhaes authored Jan 16, 2025
1 parent 38e597e commit 22f83ff
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def compute(self) -> list[Effect]:

# Craft a payload to be returned with the effect(s).
payload = {
"note": {"uuid": self.context["note"]["uuid"]},
"note": {"uuid": self.event.context["note"]["uuid"]},
"data": {"narrative": self.NARRATIVE_STRING},
}

Expand Down
7 changes: 5 additions & 2 deletions canvas_sdk/handlers/action_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ def compute(self) -> list[Effect]:
EventType.SHOW_NOTE_HEADER_BUTTON,
EventType.SHOW_NOTE_FOOTER_BUTTON,
):
if self.context["location"].lower() == self.BUTTON_LOCATION.value and self.visible():
if (
self.event.context["location"].lower() == self.BUTTON_LOCATION.value
and self.visible()
):
return [ShowButtonEffect(key=self.BUTTON_KEY, title=self.BUTTON_TITLE).apply()]
else:
return []
elif (
self.event.type == EventType.ACTION_BUTTON_CLICKED
and self.context["key"] == self.BUTTON_KEY
and self.event.context["key"] == self.BUTTON_KEY
):
return self.handle()

Expand Down
2 changes: 1 addition & 1 deletion canvas_sdk/handlers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def compute(self) -> list[Effect]:
"""Handle the application events."""
match self.event.type:
case EventType.APPLICATION__ON_OPEN:
return [self.on_open()] if self.target == self.identifier else []
return [self.on_open()] if self.event.target.id == self.identifier else []
case _:
return []

Expand Down
2 changes: 1 addition & 1 deletion canvas_sdk/handlers/cron_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def compute(self) -> list[Effect]:
"""
if not self.SCHEDULE:
raise ValueError("You must set a SCHEDULE.")
datetime = arrow.get(self.target).datetime
datetime = arrow.get(self.event.target.id).datetime
if datetime in Cron(self.SCHEDULE):
return self.execute()
return []
2 changes: 1 addition & 1 deletion canvas_sdk/protocols/clinical_quality_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def patient_id_from_target(self) -> str:

def patient_id(model: "type[Model]") -> str:
if model == Patient:
return self.target
return self.event.target.id
else:
return cast(
str,
Expand Down
2 changes: 1 addition & 1 deletion plugin_runner/plugin_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _extract_rows_to_dict(rows: list) -> dict[str, PluginAttributes]:


@contextmanager
def download_plugin(plugin_package: str) -> Generator:
def download_plugin(plugin_package: str) -> Generator[Path, None, None]:
"""Download the plugin package from the S3 bucket."""
method = "GET"
host = f"s3-{settings.AWS_REGION}.amazonaws.com"
Expand Down
18 changes: 9 additions & 9 deletions plugin_runner/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from canvas_sdk.handlers.application import Application


class TestApplication(Application):
class ExampleApplication(Application):
"""A concrete implementation of the Application class for testing."""

def on_open(self) -> Effect:
Expand All @@ -15,17 +15,17 @@ def on_open(self) -> Effect:


@pytest.fixture
def app_instance(event: Event) -> TestApplication:
def app_instance(event: Event) -> ExampleApplication:
"""Provide an instance of the TestApplication with a mocked event."""
app = TestApplication(event)
app = ExampleApplication(event)
return app


def test_compute_event_not_targeted() -> None:
"""Test that compute filters out events not targeted for the app."""
request = EventRequest(type=EventType.APPLICATION__ON_OPEN, target="some_identifier")
event = Event(request)
app = TestApplication(event)
app = ExampleApplication(event)

result = app.compute()

Expand All @@ -36,10 +36,10 @@ def test_compute_event_targeted() -> None:
"""Test that compute processes events targeted for the app."""
request = EventRequest(
type=EventType.APPLICATION__ON_OPEN,
target=f"{TestApplication.__module__}:{TestApplication.__qualname__}",
target=f"{ExampleApplication.__module__}:{ExampleApplication.__qualname__}",
)
event = Event(request)
app = TestApplication(event)
app = ExampleApplication(event)
result = app.compute()

assert len(result) == 1, "Expected a single effect if the event target is the app identifier"
Expand All @@ -48,13 +48,13 @@ def test_compute_event_targeted() -> None:

def test_identifier_property() -> None:
"""Test the identifier property of the Application class."""
expected_identifier = f"{TestApplication.__module__}:{TestApplication.__qualname__}"
expected_identifier = f"{ExampleApplication.__module__}:{ExampleApplication.__qualname__}"
request = EventRequest(
type=EventType.APPLICATION__ON_OPEN,
target=f"{TestApplication.__module__}:{TestApplication.__qualname__}",
target=f"{ExampleApplication.__module__}:{ExampleApplication.__qualname__}",
)
event = Event(request)
app = TestApplication(event)
app = ExampleApplication(event)

assert app.identifier == expected_identifier, "The identifier property is incorrect"

Expand Down
13 changes: 12 additions & 1 deletion plugin_runner/tests/test_plugin_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,19 @@ def test_plugin_installation_from_tarball(mocker: MockerFixture) -> None:
tarball_2 = _create_tarball("plugin2")

mocker.patch("plugin_runner.plugin_installer.enabled_plugins", return_value=mock_plugins)

def mock_download_plugin(package: str) -> MagicMock:
mock_context = mocker.Mock()
if package == "plugins/plugin1.tar.gz":
mock_context.__enter__ = mocker.Mock(return_value=tarball_1)
elif package == "plugins/plugin2.tar":
mock_context.__enter__ = mocker.Mock(return_value=tarball_2)
mock_context.__exit__ = mocker.Mock(return_value=None)
return mock_context

mocker.patch(
"plugin_runner.plugin_installer.download_plugin", side_effect=[tarball_1, tarball_2]
"plugin_runner.plugin_installer.download_plugin",
side_effect=mock_download_plugin,
)

install_plugins()
Expand Down
2 changes: 1 addition & 1 deletion test-plugins/my_first_plugin/protocols/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def compute(self) -> list[Effect]:
"""This method gets called when an event of the type RESPONDS_TO is fired."""
log.info(self.NARRATIVE_STRING)
payload = {
"note": {"uuid": self.context["note"]["uuid"]},
"note": {"uuid": self.event.context["note"]["uuid"]},
"data": {"narrative": self.NARRATIVE_STRING},
}

Expand Down

0 comments on commit 22f83ff

Please sign in to comment.