Skip to content

Commit 1885053

Browse files
committed
Improve coverage for confirm cue
1 parent 2c24486 commit 1885053

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

tests/test_confirm.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99

10-
from cues import confirm
10+
from cues import confirm, cursor
1111
from cues.confirm import Confirm
1212

1313

@@ -39,6 +39,37 @@ def test_from_dict(self):
3939
assert cue._name == self.name
4040
assert cue._message == self.message
4141

42+
def test_send(self, monkeypatch):
43+
cue = Confirm(self.name, self.message)
44+
45+
monkeypatch.setattr(cursor, 'hide', lambda: None)
46+
monkeypatch.setattr(cursor, 'show', lambda: None)
47+
monkeypatch.setattr(cue, '_draw', lambda: None)
48+
49+
cue.send()
50+
51+
assert cue.answer is None
52+
53+
def test_draw_with_y(self, monkeypatch):
54+
cue = Confirm(self.name, self.message)
55+
56+
monkeypatch.setattr(cue, 'listen_for_key', lambda: cue.keys.get('y'))
57+
monkeypatch.setattr(cursor, 'write', lambda _, color=True: None)
58+
59+
cue._draw()
60+
61+
assert cue.answer == {self.name: True}
62+
63+
def test_draw_with_n(self, monkeypatch):
64+
cue = Confirm(self.name, self.message)
65+
66+
monkeypatch.setattr(cue, 'listen_for_key', lambda: cue.keys.get('n'))
67+
monkeypatch.setattr(cursor, 'write', lambda _, color=True: None)
68+
69+
cue._draw()
70+
71+
assert cue.answer == {self.name: False}
72+
4273
# For dev use only (do NOT use with CI):
4374

4475
# def test__draw(self):
@@ -50,5 +81,6 @@ def test_from_dict(self):
5081
# print(f'My answer: {answer}')
5182

5283

53-
def test_main():
54-
assert confirm.main(1) == None
84+
def test_main(monkeypatch):
85+
monkeypatch.setattr(Confirm, 'send', lambda _: None)
86+
assert confirm.main() is None

0 commit comments

Comments
 (0)