Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikilicious committed Jun 23, 2024
1 parent 4ad4991 commit a4b04a4
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions tests/test_connection/test_connection_misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import sys
from unittest import mock

import pytest
from serial import Serial
Expand Down Expand Up @@ -50,24 +51,13 @@ def test_setting_password_does_not_log(caplog):
assert "Dawkins" not in caplog.text, "Password found in log message"


# pytest can't delattr read_all? what?
# def test_pyserial_read_all_fix_for_34(monkeypatch):
# """
# pyserial==3.5 has method .read_all
# pyserial==3.4 does not
#
# pygmc checks hasattr else it manually gets 'in_waiting' bytes and uses it in .read()
# """
# cmd_response_map = {b"MATH": b"YES"}
# mock_dev = get_mock_dev(cmd_response_map)
# mock_dev_serial = Serial(mock_dev.port)
#
# connection = pygmc.connection.Connection(
# port="dummy", baudrate=123, serial_connection=mock_dev_serial
# )
#
# # let's fake pyserial==3.4
# monkeypatch.delattr(connection._con, "read_all")
# # The true test is getting a response with read_all deleted
# response = connection.get(b"MATH", wait_sleep=0)
# assert response == b"YES", "Unexpected response"
def test_connection_timeout_msg(caplog):
with caplog.at_level(logging.DEBUG, logger="pygmc"):

with mock.patch("serial.Serial") as mock_serial:
mock_serial.side_effect = TimeoutError

with pytest.raises(TimeoutError):
pygmc.connection.Connection("dummy", baudrate=123)

assert "consider reconnecting USB" in caplog.text

0 comments on commit a4b04a4

Please sign in to comment.