Skip to content

Commit f165daa

Browse files
fix : Changes done in test files
- changes done in test files according to key_binding.
1 parent 736628d commit f165daa

File tree

11 files changed

+233
-170
lines changed

11 files changed

+233
-170
lines changed

docs/hotkeys.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
## Switching Messages View
3131
|Command|Key Combination|
3232
| :--- | :---: |
33-
|View the channel of the current message|<kbd>s</kbd>|
33+
|View the of the current message|<kbd>s</kbd>|
3434
|View the topic of the current message|<kbd>S</kbd>|
3535
|Zoom in/out the message's conversation context|<kbd>z</kbd>|
3636
|Switch message view to the compose box target|<kbd>Meta</kbd> + <kbd>.</kbd>|
@@ -46,8 +46,8 @@
4646
| :--- | :---: |
4747
|Search users|<kbd>w</kbd>|
4848
|Search messages|<kbd>/</kbd>|
49-
|Search channels|<kbd>q</kbd>|
50-
|Search topics in a channel|<kbd>q</kbd>|
49+
|Search s|<kbd>q</kbd>|
50+
|Search topics in a |<kbd>q</kbd>|
5151
|Search emojis from emoji picker|<kbd>p</kbd>|
5252
|Submit search and browse results|<kbd>Enter</kbd>|
5353
|Clear search in current panel|<kbd>Esc</kbd>|
@@ -63,12 +63,12 @@
6363
|Show/hide message information|<kbd>i</kbd>|
6464
|Show/hide message sender information|<kbd>u</kbd>|
6565

66-
## channel list actions
66+
## list actions
6767
|Command|Key Combination|
6868
| :--- | :---: |
69-
|Toggle topics in a channel|<kbd>t</kbd>|
70-
|Mute/unmute channels|<kbd>m</kbd>|
71-
|Show/hide channel information & modify settings|<kbd>i</kbd>|
69+
|Toggle topics in a |<kbd>t</kbd>|
70+
|Mute/unmute s|<kbd>m</kbd>|
71+
|Show/hide information & modify settings|<kbd>i</kbd>|
7272

7373
## User list actions
7474
|Command|Key Combination|
@@ -84,7 +84,7 @@
8484
|Reply mentioning the sender of the current message|<kbd>@</kbd>|
8585
|Reply quoting the current message text|<kbd>></kbd>|
8686
|Reply directly to the sender of the current message|<kbd>R</kbd>|
87-
|New message to a channel|<kbd>c</kbd>|
87+
|New message to a |<kbd>c</kbd>|
8888
|New message to a person or group of people|<kbd>x</kbd>|
8989

9090
## Writing a message
@@ -93,7 +93,7 @@
9393
|Cycle through recipient and content boxes|<kbd>Tab</kbd>|
9494
|Send a message|<kbd>Ctrl</kbd> + <kbd>d</kbd> / <kbd>Meta</kbd> + <kbd>Enter</kbd>|
9595
|Save current message as a draft|<kbd>Meta</kbd> + <kbd>s</kbd>|
96-
|Autocomplete @mentions, #channel_names, :emoji: and topics|<kbd>Ctrl</kbd> + <kbd>f</kbd>|
96+
|Autocomplete @mentions, #_names, :emoji: and topics|<kbd>Ctrl</kbd> + <kbd>f</kbd>|
9797
|Cycle through autocomplete suggestions in reverse|<kbd>Ctrl</kbd> + <kbd>r</kbd>|
9898
|Exit message compose box|<kbd>Esc</kbd>|
9999
|Insert new line|<kbd>Enter</kbd>|
@@ -123,11 +123,11 @@
123123
|Delete previous character|<kbd>Ctrl</kbd> + <kbd>h</kbd>|
124124
|Swap with previous character|<kbd>Ctrl</kbd> + <kbd>t</kbd>|
125125

126-
## channel information (press i to view info of a channel)
126+
## information (press i to view info of a )
127127
|Command|Key Combination|
128128
| :--- | :---: |
129-
|Show/hide channel members|<kbd>m</kbd>|
130-
|Copy channel email to clipboard|<kbd>c</kbd>|
129+
|Show/hide members|<kbd>m</kbd>|
130+
|Copy email to clipboard|<kbd>c</kbd>|
131131

132132
## Message information (press i to view info of a message)
133133
|Command|Key Combination|

tests/config/test_keys.py

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from zulipterminal.config import keys
77

88

9-
AVAILABLE_COMMANDS = list(keys.KEY_BINDINGS.keys())
9+
AVAILABLE_COMMANDS = list(keys.key_config.KEY_BINDINGS.keys())
1010

11-
USED_KEYS = {key for values in keys.KEY_BINDINGS.values() for key in values["keys"]}
11+
USED_KEYS = {
12+
key for values in keys.key_config.KEY_BINDINGS.values() for key in values["keys"]
13+
}
1214

1315

14-
@pytest.fixture(params=keys.KEY_BINDINGS.keys())
16+
@pytest.fixture(params=keys.key_config.KEY_BINDINGS.keys())
1517
def valid_command(request: Any) -> str:
1618
return request.param
1719

@@ -22,20 +24,20 @@ def invalid_command(request: Any) -> str:
2224

2325

2426
def test_keys_for_command(valid_command: str) -> None:
25-
assert keys.KEY_BINDINGS[valid_command]["keys"] == keys.keys_for_command(
26-
valid_command
27-
)
27+
assert keys.key_config.KEY_BINDINGS[valid_command][
28+
"keys"
29+
] == keys.key_config.keys_for_command(valid_command)
2830

2931

3032
def test_primary_key_for_command(valid_command: str) -> None:
31-
assert keys.KEY_BINDINGS[valid_command]["keys"][0] == keys.primary_key_for_command(
32-
valid_command
33-
)
33+
assert keys.key_config.KEY_BINDINGS[valid_command]["keys"][
34+
0
35+
] == keys.key_config.key_config.key_config.primary_key_for_command(valid_command)
3436

3537

3638
def test_keys_for_command_invalid_command(invalid_command: str) -> None:
37-
with pytest.raises(keys.InvalidCommand):
38-
keys.keys_for_command(invalid_command)
39+
with pytest.raises(keys.key_config.InvalidCommand):
40+
keys.key_config.keys_for_command(invalid_command)
3941

4042

4143
def test_keys_for_command_identity(valid_command: str) -> None:
@@ -44,30 +46,37 @@ def test_keys_for_command_identity(valid_command: str) -> None:
4446
new list which validates that the original keys don't get altered
4547
elsewhere unintentionally.
4648
"""
47-
assert id(keys.KEY_BINDINGS[valid_command]["keys"]) != id(
48-
keys.keys_for_command(valid_command)
49+
assert id(keys.key_config.KEY_BINDINGS[valid_command]["keys"]) != id(
50+
keys.key_config.keys_for_command(valid_command)
4951
)
5052

5153

5254
def test_is_command_key_matching_keys(valid_command: str) -> None:
53-
for key in keys.keys_for_command(valid_command):
54-
assert keys.is_command_key(valid_command, key)
55+
for key in keys.key_config.keys_for_command(valid_command):
56+
assert keys.key_config.key_config.key_config.is_command_key(valid_command, key)
5557

5658

5759
def test_is_command_key_nonmatching_keys(valid_command: str) -> None:
58-
keys_to_test = USED_KEYS - set(keys.keys_for_command(valid_command))
60+
keys_to_test = USED_KEYS - set(keys.key_config.keys_for_command(valid_command))
5961
for key in keys_to_test:
60-
assert not keys.is_command_key(valid_command, key)
62+
assert not keys.key_config.key_config.key_config.is_command_key(
63+
valid_command, key
64+
)
6165

6266

6367
def test_is_command_key_invalid_command(invalid_command: str) -> None:
64-
with pytest.raises(keys.InvalidCommand):
65-
keys.is_command_key(invalid_command, "esc") # key doesn't matter
68+
with pytest.raises(keys.key_config.InvalidCommand):
69+
keys.key_config.key_config.key_config.is_command_key(
70+
invalid_command, "esc"
71+
) # key doesn't matter
6672

6773

6874
def test_HELP_is_not_allowed_as_tip() -> None:
69-
assert keys.KEY_BINDINGS["HELP"]["excluded_from_random_tips"] is True
70-
assert keys.KEY_BINDINGS["HELP"] not in keys.commands_for_random_tips()
75+
assert keys.key_config.KEY_BINDINGS["HELP"]["excluded_from_random_tips"] is True
76+
assert (
77+
keys.key_config.KEY_BINDINGS["HELP"]
78+
not in keys.key_config.commands_for_random_tips()
79+
)
7180

7281

7382
def test_commands_for_random_tips(mocker: MockerFixture) -> None:
@@ -96,20 +105,22 @@ def test_commands_for_random_tips(mocker: MockerFixture) -> None:
96105
"excluded_from_random_tips": True,
97106
},
98107
}
99-
mocker.patch.dict(keys.KEY_BINDINGS, new_key_bindings, clear=True)
100-
result = keys.commands_for_random_tips()
108+
mocker.patch.dict(keys.key_config.KEY_BINDINGS, new_key_bindings, clear=True)
109+
result = keys.key_config.commands_for_random_tips()
101110
assert len(result) == 2
102111
assert new_key_bindings["BETA"] in result
103112
assert new_key_bindings["GAMMA"] in result
104113

105114

106115
def test_updated_urwid_command_map() -> None:
107-
urwid_to_zt_mapping = {v: k for k, v in keys.ZT_TO_URWID_CMD_MAPPING.items()}
116+
urwid_to_zt_mapping = {
117+
v: k for k, v in keys.key_config.ZT_TO_URWID_CMD_MAPPING.items()
118+
}
108119
# Check if keys in command map are actually the ones in KEY_BINDINGS
109-
for key, urwid_cmd in keys.command_map._command.items():
120+
for key, urwid_cmd in keys.key_config.command_map._command.items():
110121
try:
111122
zt_cmd = urwid_to_zt_mapping[urwid_cmd]
112-
assert key in keys.keys_for_command(zt_cmd)
123+
assert key in keys.key_config.keys_for_command(zt_cmd)
113124
except KeyError:
114125
pass
115126

@@ -138,7 +149,7 @@ def test_updated_urwid_command_map() -> None:
138149
],
139150
)
140151
def test_display_key_for_urwid_key(urwid_key: str, display_key: str) -> None:
141-
assert keys.display_key_for_urwid_key(urwid_key) == display_key
152+
assert keys.key_config.display_key_for_urwid_key(urwid_key) == display_key
142153

143154

144155
COMMAND_TO_DISPLAY_KEYS = [
@@ -150,14 +161,20 @@ def test_display_key_for_urwid_key(urwid_key: str, display_key: str) -> None:
150161

151162
@pytest.mark.parametrize("command, display_keys", COMMAND_TO_DISPLAY_KEYS)
152163
def test_display_keys_for_command(command: str, display_keys: List[str]) -> None:
153-
assert keys.display_keys_for_command(command) == display_keys
164+
assert (
165+
keys.key_config.key_config.key_config.display_keys_for_command(command)
166+
== display_keys
167+
)
154168

155169

156170
@pytest.mark.parametrize("command, display_keys", COMMAND_TO_DISPLAY_KEYS)
157171
def test_primary_display_key_for_command(command: str, display_keys: List[str]) -> None:
158-
assert keys.primary_display_key_for_command(command) == display_keys[0]
172+
assert (
173+
keys.key_config.key_config.key_config.primary_display_key_for_command(command)
174+
== display_keys[0]
175+
)
159176

160177

161178
def test_display_keys_for_command_invalid_command(invalid_command: str) -> None:
162-
with pytest.raises(keys.InvalidCommand):
163-
keys.display_keys_for_command(invalid_command)
179+
with pytest.raises(keys.key_config.InvalidCommand):
180+
keys.key_config.key_config.key_config.display_keys_for_command(invalid_command)

tests/conftest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
Message,
1313
MessageType,
1414
)
15-
from zulipterminal.config.keys import (
16-
ZT_TO_URWID_CMD_MAPPING,
17-
keys_for_command,
18-
primary_key_for_command,
19-
)
15+
from zulipterminal.config.keys import key_config
2016
from zulipterminal.helper import (
2117
CustomProfileData,
2218
Index,
@@ -1495,8 +1491,8 @@ def compose_box_is_open(request: Any) -> bool:
14951491

14961492
@pytest.fixture(
14971493
params=[
1498-
("mouse press", 4, primary_key_for_command("GO_UP")),
1499-
("mouse press", 5, primary_key_for_command("GO_DOWN")),
1494+
("mouse press", 4, key_config.primary_key_for_command("GO_UP")),
1495+
("mouse press", 5, key_config.primary_key_for_command("GO_DOWN")),
15001496
],
15011497
ids=[
15021498
"mouse_scroll_up",
@@ -1511,7 +1507,11 @@ def mouse_scroll_event(request: Any) -> Tuple[Any]:
15111507

15121508

15131509
@pytest.fixture(
1514-
params=[key for cmd in ZT_TO_URWID_CMD_MAPPING for key in keys_for_command(cmd)],
1510+
params=[
1511+
key
1512+
for cmd in key_config.ZT_TO_URWID_CMD_MAPPING
1513+
for key in key_config.keys_for_command(cmd)
1514+
],
15151515
ids=lambda param: "nav-key:{}".format(*param),
15161516
)
15171517
def navigation_key(request: Any) -> str:

tests/helper/test_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pytest_mock import MockerFixture
66

77
from zulipterminal.api_types import Composition
8-
from zulipterminal.config.keys import primary_display_key_for_command
8+
from zulipterminal.config.keys import key_config
99
from zulipterminal.helper import (
1010
Index,
1111
canonicalize_color,
@@ -469,7 +469,7 @@ def test_notify_if_message_sent_outside_narrow(
469469
notify_if_message_sent_outside_narrow(req, controller)
470470

471471
if footer_updated:
472-
key = primary_display_key_for_command("NARROW_MESSAGE_RECIPIENT")
472+
key = key_config.primary_display_key_for_command("NARROW_MESSAGE_RECIPIENT")
473473
report_success.assert_called_once_with(
474474
[
475475
"Message is sent outside of current narrow."

tests/ui/test_ui.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from urwid import Widget
66

77
from zulipterminal.api_types import Composition
8-
from zulipterminal.config.keys import keys_for_command
8+
from zulipterminal.config.keys import key_config
99
from zulipterminal.ui import LEFT_WIDTH, RIGHT_WIDTH, TAB_WIDTH, View
1010
from zulipterminal.urwid_types import urwid_Box
1111

@@ -299,7 +299,7 @@ def test_keypress_normal_mode_navigation(
299299

300300
super_keypress.assert_called_once_with(size, navigation_key)
301301

302-
@pytest.mark.parametrize("key", keys_for_command("ALL_MENTIONS"))
302+
@pytest.mark.parametrize("key", key_config.keys_for_command("ALL_MENTIONS"))
303303
def test_keypress_ALL_MENTIONS(
304304
self,
305305
view: View,
@@ -316,7 +316,7 @@ def test_keypress_ALL_MENTIONS(
316316

317317
view.mentioned_button.activate.assert_called_once_with(key)
318318

319-
@pytest.mark.parametrize("key", keys_for_command("STREAM_MESSAGE"))
319+
@pytest.mark.parametrize("key", key_config.keys_for_command("STREAM_MESSAGE"))
320320
@pytest.mark.parametrize("autohide", [True, False], ids=["autohide", "no_autohide"])
321321
def test_keypress_STREAM_MESSAGE(
322322
self,
@@ -341,7 +341,7 @@ def test_keypress_STREAM_MESSAGE(
341341
assert returned_key == key
342342
assert view.body.focus_col == 1
343343

344-
@pytest.mark.parametrize("key", keys_for_command("NEW_HINT"))
344+
@pytest.mark.parametrize("key", key_config.keys_for_command("NEW_HINT"))
345345
def test_keypress_NEW_HINT(
346346
self,
347347
view: View,
@@ -358,7 +358,7 @@ def test_keypress_NEW_HINT(
358358
set_footer_text.assert_called_once_with()
359359
assert returned_key == key
360360

361-
@pytest.mark.parametrize("key", keys_for_command("SEARCH_PEOPLE"))
361+
@pytest.mark.parametrize("key", key_config.keys_for_command("SEARCH_PEOPLE"))
362362
@pytest.mark.parametrize("autohide", [True, False], ids=["autohide", "no_autohide"])
363363
def test_keypress_autohide_users(
364364
self,
@@ -383,7 +383,7 @@ def test_keypress_autohide_users(
383383
mocked_users_view.keypress.assert_called_once_with(size, key)
384384
assert view.body.focus_position == 2
385385

386-
@pytest.mark.parametrize("key", keys_for_command("SEARCH_STREAMS"))
386+
@pytest.mark.parametrize("key", key_config.keys_for_command("SEARCH_STREAMS"))
387387
@pytest.mark.parametrize("autohide", [True, False], ids=["autohide", "no_autohide"])
388388
def test_keypress_autohide_streams(
389389
self,
@@ -430,7 +430,7 @@ def test_keypress_autohide_streams(
430430
"no_draft_composition",
431431
],
432432
)
433-
@pytest.mark.parametrize("key", keys_for_command("OPEN_DRAFT"))
433+
@pytest.mark.parametrize("key", key_config.keys_for_command("OPEN_DRAFT"))
434434
@pytest.mark.parametrize("autohide", [True, False], ids=["autohide", "no_autohide"])
435435
def test_keypress_OPEN_DRAFT(
436436
self,
@@ -479,7 +479,7 @@ def test_keypress_OPEN_DRAFT(
479479
["No draft message was saved in this session."]
480480
)
481481

482-
@pytest.mark.parametrize("key", keys_for_command("SEARCH_PEOPLE"))
482+
@pytest.mark.parametrize("key", key_config.keys_for_command("SEARCH_PEOPLE"))
483483
def test_keypress_edit_mode(
484484
self,
485485
view: View,

0 commit comments

Comments
 (0)