示例#1
0
    def test_send(self, monkeypatch):
        cue = Checkbox(self.name, self.message, self.options)

        monkeypatch.setattr(cursor, 'hide', lambda: None)
        monkeypatch.setattr(cursor, 'show', lambda: None)
        monkeypatch.setattr(cue, '_draw', lambda: None)

        cue.send()
        assert cue.answer is None
示例#2
0
    def test_draw_with_enter_key(self, monkeypatch):
        cue = Checkbox(self.name, self.message, self.options)
        enter = cue.keys.get('enter')

        monkeypatch.setattr(cursor,
                            'write',
                            lambda _, color=True, newlines=1: None)
        monkeypatch.setattr(cue, 'listen_for_key', lambda: enter)
        monkeypatch.setattr(cursor, 'clear', lambda _: None)

        assert cue._draw() is None
        assert cue.answer == {self.name: []}
示例#3
0
    def test_draw_with_space_key(self, monkeypatch):
        cue = Checkbox(self.name, self.message, self.options)
        space = cue.keys.get('space')
        enter = cue.keys.get('enter')

        moves = [space, space]

        def mock_listen_for_key():
            if moves:
                return moves.pop(0)
            return enter

        monkeypatch.setattr(cursor,
                            'write',
                            lambda _, color=True, newlines=1: None)
        monkeypatch.setattr(cue, 'listen_for_key', mock_listen_for_key)
        monkeypatch.setattr(cursor, 'clear', lambda _: None)

        assert cue._draw() is None
        assert cue.answer == {self.name: []}
示例#4
0
    def test_from_dict(self):
        checkbox_dict = {
            'name': self.name,
            'message': self.message,
            'options': self.options
        }
        cue = Checkbox.from_dict(checkbox_dict)

        assert cue._name == self.name
        assert cue._message == self.message
        assert cue._options == self.options
示例#5
0
    def test_draw_with_up_and_down_keys(self, monkeypatch):
        cue = Checkbox(self.name, self.message, self.options)
        up = cue.keys.get('up')
        down = cue.keys.get('down')
        enter = cue.keys.get('enter')

        moves = [up, down, up, down, down, down, down, down, down, down]

        def mock_listen_for_key():
            if moves:
                return moves.pop(0)
            return enter

        monkeypatch.setattr(cursor,
                            'write',
                            lambda _, color=True, newlines=1: None)
        monkeypatch.setattr(cue, 'listen_for_key', mock_listen_for_key)
        monkeypatch.setattr(cursor, 'clear', lambda _: None)

        assert cue._draw() is None
        assert cue.answer == {self.name: []}
示例#6
0
    def test_init_errors(self):
        bad_options = 1

        with pytest.raises(TypeError):
            cue = Checkbox(self.name, self.message, bad_options)
示例#7
0
    def test_init(self):
        cue = Checkbox(self.name, self.message, self.options)

        assert cue._name == self.name
        assert cue._message == self.message
        assert cue._options == self.options