Skip to content

Commit

Permalink
Patch pillow mock properly rather than type ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
callumforrester committed Apr 3, 2024
1 parent b113bf0 commit 7a32c20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ allowlist_externals =
sphinx-autobuild
commands =
pytest: pytest -m 'not s03' {posargs}
mypy: mypy src tests -v --ignore-missing-imports --show-traceback --no-strict-optional --check-untyped-defs {posargs}
mypy: mypy src tests --ignore-missing-imports --no-strict-optional --check-untyped-defs {posargs}
pre-commit: pre-commit run --all-files {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""
Expand Down
20 changes: 9 additions & 11 deletions tests/devices/unit_tests/test_oav.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,16 @@ def test_snapshot_trigger_saves_to_correct_file(
mock_open: MagicMock, mock_get, fake_oav
):
image = PIL.Image.open("test")
mock_save = MagicMock()
# mypy doesn't like method assignments
image.save = mock_save # type: ignore
mock_open.return_value.__enter__.return_value = image
st = fake_oav.snapshot.trigger()
st.wait()
expected_calls_to_save = [
call(f"test directory/test filename{addition}.png")
for addition in ["", "_outer_overlay", "_grid_overlay"]
]
calls_to_save = mock_save.mock_calls
assert calls_to_save == expected_calls_to_save
with patch.object(image, "save") as mock_save:
st = fake_oav.snapshot.trigger()
st.wait()
expected_calls_to_save = [
call(f"test directory/test filename{addition}.png")
for addition in ["", "_outer_overlay", "_grid_overlay"]
]
calls_to_save = mock_save.mock_calls
assert calls_to_save == expected_calls_to_save


@patch("requests.get")
Expand Down

0 comments on commit 7a32c20

Please sign in to comment.