Skip to content

Commit

Permalink
Fix method signature incompatible with supertype's
Browse files Browse the repository at this point in the history
Assertions allow to narrow the type of an ambiguous object.
See https://mypy.readthedocs.io/en/stable/type_narrowing.html
  • Loading branch information
gonzalo-bulnes committed Dec 20, 2022
1 parent e6b1471 commit beb125e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ def update_sources(self, sources: List[Source]) -> List[str]:
if not source_widget:
continue

source_widget.update()
assert isinstance(source_widget, SourceWidget)
source_widget.reload()

# Add widgets for new sources
for uuid in sources_to_add:
Expand Down Expand Up @@ -1304,14 +1305,14 @@ def __init__(
layout.setSpacing(0)
layout.addWidget(self.source_widget)

self.update()
self.reload()

@pyqtSlot(int)
def _on_adjust_preview(self, width: int) -> None:
self.setFixedWidth(width)
self.preview.adjust_preview(width)

def update(self) -> None:
def reload(self) -> None:
"""
Updates the displayed values with the current values from self.source.
"""
Expand Down
22 changes: 11 additions & 11 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ def test_SourceWidget_html_init(mocker):
sw.summary_layout = mocker.MagicMock()

mocker.patch("securedrop_client.gui.base.SvgLabel")
sw.update()
sw.reload()

sw.name.setText.assert_called_once_with("foo <b>bar</b> baz")

Expand Down Expand Up @@ -1828,12 +1828,12 @@ def test_SourceWidget_update_attachment_icon(mocker):
mark_seen_signal = mocker.MagicMock()
sw = SourceWidget(controller, source, mark_seen_signal, mocker.MagicMock())

sw.update()
sw.reload()
assert not sw.paperclip.isHidden()

source.document_count = 0

sw.update()
sw.reload()
assert sw.paperclip.isHidden()


Expand All @@ -1850,7 +1850,7 @@ def test_SourceWidget_update_does_not_raise_exception(mocker):
controller.session.refresh.side_effect = ex
mock_logger = mocker.MagicMock()
mocker.patch("securedrop_client.gui.widgets.logger", mock_logger)
sw.update()
sw.reload()
assert mock_logger.debug.call_count == 1


Expand All @@ -1861,7 +1861,7 @@ def test_SourceWidget_update_skips_setting_snippet_if_deletion_in_progress(mocke
sw = SourceWidget(mocker.MagicMock(), factory.Source(), mocker.MagicMock(), mocker.MagicMock())
sw.deleting = True
sw.set_snippet = mocker.MagicMock()
sw.update()
sw.reload()
sw.set_snippet.assert_not_called()


Expand All @@ -1873,7 +1873,7 @@ def test_SourceWidget_update_skips_setting_snippet_if_sync_is_stale(mocker):
sw.sync_started_timestamp = datetime.now()
sw.deletion_scheduled_timestamp = datetime.now()
sw.set_snippet = mocker.MagicMock()
sw.update()
sw.reload()
sw.set_snippet.assert_not_called()


Expand All @@ -1884,7 +1884,7 @@ def test_SourceWidget_update_skips_setting_snippet_if_conversation_deletion_in_p
sw = SourceWidget(mocker.MagicMock(), factory.Source(), mocker.MagicMock(), mocker.MagicMock())
sw.deleting_conversation = True
sw.set_snippet = mocker.MagicMock()
sw.update()
sw.reload()
sw.set_snippet.assert_not_called()


Expand Down Expand Up @@ -1950,7 +1950,7 @@ def test_SourceWidget_update_truncate_latest_msg(mocker):
mark_seen_signal = mocker.MagicMock()
sw = SourceWidget(controller, source, mark_seen_signal, mocker.MagicMock())

sw.update()
sw.reload()
assert sw.preview.text().endswith("...")


Expand Down Expand Up @@ -2076,7 +2076,7 @@ def test_SourceWidget_preview_after_conversation_deleted(mocker, session, i18n):

controller = mocker.MagicMock()
sw = SourceWidget(controller, source, mocker.MagicMock(), mocker.MagicMock())
sw.update()
sw.reload()
assert sw.preview.property("class") == "conversation_deleted"
assert sw.preview.text() == _("\u2014 All files and messages deleted for this source \u2014")

Expand Down Expand Up @@ -2139,12 +2139,12 @@ def test_SourceWidget_uses_SecureQLabel(mocker):
mark_seen_signal = mocker.MagicMock()
sw = SourceWidget(controller, source, mark_seen_signal, mocker.MagicMock())

sw.update()
sw.reload()
assert isinstance(sw.preview, SecureQLabel)

sw.preview.setTextFormat = mocker.MagicMock()
sw.preview.setText("<b>bad text</b>")
sw.update()
sw.reload()
sw.preview.setTextFormat.assert_called_with(Qt.PlainText)


Expand Down

0 comments on commit beb125e

Please sign in to comment.