Skip to content

Commit

Permalink
Ensure a correctly encoded input for manual input. (#352)
Browse files Browse the repository at this point in the history
* Ensure a correctly encoded input for manual input.

* Test added.

Co-authored-by: Benedikt Moneke <[email protected]>
  • Loading branch information
BenediktBurger and Benedikt Moneke authored May 10, 2022
1 parent f5a7791 commit 6aa8a8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def read_raw(self, size=-1):
else:
raise ValueError("Must read a positive value of characters.")
else:
input_var = input("Desired Response: ")
input_var = input("Desired Response: ").encode("utf-8")
return input_var

def write_raw(self, msg):
Expand Down
8 changes: 7 additions & 1 deletion tests/test_comm/test_loopback.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ def test_loopbackcomm_read_raw_size_invalid():
comm.read_raw(size=-2)


@mock.patch("builtins.input")
def test_loopbackcomm_read_raw_stdin(mock_input):
mock_input.return_value = "Returned string."
comm = LoopbackCommunicator()
assert comm.read_raw() == b"Returned string."


def test_loopbackcomm_write_raw():
mock_stdout = mock.MagicMock()
comm = LoopbackCommunicator(stdout=mock_stdout)

comm.write_raw(b"mock")
mock_stdout.write.assert_called_with(b"mock")

Expand Down

0 comments on commit 6aa8a8d

Please sign in to comment.