Skip to content

Commit 6aa8a8d

Browse files
BenediktBurgerBenedikt Moneke
andauthored
Ensure a correctly encoded input for manual input. (#352)
* Ensure a correctly encoded input for manual input. * Test added. Co-authored-by: Benedikt Moneke <Benedikt.Moneke@tu-darmstadt.de>
1 parent f5a7791 commit 6aa8a8d

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/instruments/abstract_instruments/comm/loopback_communicator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def read_raw(self, size=-1):
121121
else:
122122
raise ValueError("Must read a positive value of characters.")
123123
else:
124-
input_var = input("Desired Response: ")
124+
input_var = input("Desired Response: ").encode("utf-8")
125125
return input_var
126126

127127
def write_raw(self, msg):

tests/test_comm/test_loopback.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ def test_loopbackcomm_read_raw_size_invalid():
116116
comm.read_raw(size=-2)
117117

118118

119+
@mock.patch("builtins.input")
120+
def test_loopbackcomm_read_raw_stdin(mock_input):
121+
mock_input.return_value = "Returned string."
122+
comm = LoopbackCommunicator()
123+
assert comm.read_raw() == b"Returned string."
124+
125+
119126
def test_loopbackcomm_write_raw():
120127
mock_stdout = mock.MagicMock()
121128
comm = LoopbackCommunicator(stdout=mock_stdout)
122-
123129
comm.write_raw(b"mock")
124130
mock_stdout.write.assert_called_with(b"mock")
125131

0 commit comments

Comments
 (0)