-
-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Disable cycling while editing a PM #1280
base: main
Are you sure you want to change the base?
Changes from 1 commit
b45eb77
7cfffe0
cdb0fad
415f31f
2a66b5d
691296d
f1590cb
ba32129
40e6067
ac20ad7
2bd5228
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1706,6 +1706,39 @@ def focus_val(x: str) -> int: | |
expected_focus_col_name | ||
) | ||
|
||
def test_private_box_view( | ||
self, | ||
mocker: MockerFixture, | ||
user_dict: List[Dict[str, Any]], | ||
user_id_email_dict: Dict[int, str], | ||
) -> None: | ||
recipient_user_ids = [11] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to suggest placing this as a default argument, but I'm not sure if this has the typical python issue with potential errors from persistent mutable default arguments. Typing it as a If we do this, that eases any parametrizing them later - and saves a blank line in this case ;) |
||
|
||
write_box = WriteBox(self.view) | ||
write_box.to_write_box = mocker.MagicMock(spec=ReadlineEdit) | ||
enable_autocomplete = mocker.patch.object(ReadlineEdit, "enable_autocomplete") | ||
Comment on lines
+1721
to
+1722
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
enable_autocomplete = write_box.to_write_box.enable_autocomplete or alternatively substituting that inline where you have the assert_has_calls, since you only use/assert enable_autocomplete once in the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems rather that the previous line isn't necessary, as the So we need to patch |
||
write_box.model.user_id_email_dict = user_id_email_dict | ||
write_box.model.user_dict = user_dict | ||
connect_signal_mock = mocker.patch.object(urwid, "connect_signal") | ||
write_box.private_box_view(recipient_user_ids=recipient_user_ids) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Unless the test is only a few lines, please separate the line being tested from the setup and assert lines by blank lines, to make it easier to pick out which lines are which (you did this in the previous commit!) |
||
enable_autocomplete.assert_has_calls( | ||
[ | ||
mock.call( | ||
func=write_box._to_box_autocomplete, | ||
key=primary_key_for_command("AUTOCOMPLETE"), | ||
key_reverse=primary_key_for_command("AUTOCOMPLETE_REVERSE"), | ||
), | ||
mock.call( | ||
func=write_box.generic_autocomplete, | ||
key=primary_key_for_command("AUTOCOMPLETE"), | ||
key_reverse=primary_key_for_command("AUTOCOMPLETE_REVERSE"), | ||
), | ||
] | ||
) | ||
connect_signal_mock.assert_called_once() | ||
assert isinstance(write_box.to_write_box, ReadlineEdit) | ||
assert write_box.to_write_box.text == "To: Human 1 <[email protected]>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could consider a multi-person DM here, to cover a more complex case, or parametrize this for empty/single/multi. The latter isn't necessary, but would cover all the cases and you might find it useful to flex your pytest muscles - particularly if you extract them into a fixture (see a comment on a later commit) Note how if you parametrize this, you can consider that as a series of changes:
|
||
|
||
def test__setup_common_private_compose(self, mocker: MockerFixture) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate you committing to writing this test, though I'm not entirely sold on the importance of this test, since it's heavily focused on the UI only and risks mimicking the code itself (as per various other UI tests we have). The DM vs DM-edit tests currently in later commits have more significance due to expressing the differences. Also note that the DM test, which should really be the first commit (see another comment) does already test some of this behavior. It can often be tricky knowing whether to test internal helper functions like this, since we could change the implementation of the DM view to not use this, or use this differently, and then we have a test that's less used/useful, or perhaps needs updating in addition to the test for the other functions, which adds more overhead to what needs doing without necessarily adding a benefit. For now let's keep this, though note that comments I make regarding other tests also apply here to various degrees. |
||
write_box = WriteBox(self.view) | ||
write_box.to_write_box = mocker.MagicMock() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re this commit in general: