Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use socket.sendall instead of socket.send #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hl7/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def send(self, data):
wrapped in an MLLP container). Blocks until the server returns.
"""
# upload the data
self.socket.send(data)
self.socket.sendall(data)
# wait for the ACK/NACK
return self.socket.recv(RECV_BUFFER)

Expand Down
34 changes: 17 additions & 17 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_send(self):
result = self.client.send("foobar\n")
self.assertEqual(result, "thanks")

self.client.socket.send.assert_called_once_with("foobar\n")
self.client.socket.sendall.assert_called_once_with("foobar\n")
self.client.socket.recv.assert_called_once_with(4096)

def test_send_message_unicode(self):
Expand All @@ -46,15 +46,15 @@ def test_send_message_unicode(self):
result = self.client.send_message("foobar")
self.assertEqual(result, "thanks")

self.client.socket.send.assert_called_once_with(b"\x0bfoobar\x1c\x0d")
self.client.socket.sendall.assert_called_once_with(b"\x0bfoobar\x1c\x0d")

def test_send_message_bytestring(self):
self.client.socket.recv.return_value = "thanks"

result = self.client.send_message(b"foobar")
self.assertEqual(result, "thanks")

self.client.socket.send.assert_called_once_with(b"\x0bfoobar\x1c\x0d")
self.client.socket.sendall.assert_called_once_with(b"\x0bfoobar\x1c\x0d")

def test_send_message_hl7_message(self):
self.client.socket.recv.return_value = "thanks"
Expand All @@ -64,15 +64,15 @@ def test_send_message_hl7_message(self):
result = self.client.send_message(message)
self.assertEqual(result, "thanks")

self.client.socket.send.assert_called_once_with(
self.client.socket.sendall.assert_called_once_with(
b"\x0bMSH|^~\\&|GHH LAB|ELAB\r\x1c\x0d"
)

def test_context_manager(self):
with MLLPClient("localhost", 6666) as client:
client.send("hello world")

self.client.socket.send.assert_called_once_with("hello world")
self.client.socket.sendall.assert_called_once_with("hello world")
self.client.socket.close.assert_called_once_with()

def test_context_manager_exception(self):
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_send(self):
mllp_send()

self.mock_socket().connect.assert_called_once_with(("localhost", 6661))
self.mock_socket().send.assert_called_once_with(SB + b"foobar" + EB + CR)
self.mock_socket().sendall.assert_called_once_with(SB + b"foobar" + EB + CR)
self.mock_stdout.assert_called_once_with("thanks")
self.assertFalse(self.mock_exit.called)

Expand All @@ -154,25 +154,25 @@ def test_send_multiple(self):
mllp_send()

self.assertEqual(
self.mock_socket().send.call_args_list[0][0][0], SB + b"foobar" + EB + CR
self.mock_socket().sendall.call_args_list[0][0][0], SB + b"foobar" + EB + CR
)
self.assertEqual(
self.mock_socket().send.call_args_list[1][0][0], SB + b"hello" + EB + CR
self.mock_socket().sendall.call_args_list[1][0][0], SB + b"hello" + EB + CR
)

def test_leftover_buffer(self):
self.write(SB + b"foobar" + EB + CR + SB + b"stuff")

self.assertRaises(MLLPException, mllp_send)

self.mock_socket().send.assert_called_once_with(SB + b"foobar" + EB + CR)
self.mock_socket().sendall.assert_called_once_with(SB + b"foobar" + EB + CR)

def test_quiet(self):
self.option_values.verbose = False

mllp_send()

self.mock_socket().send.assert_called_once_with(SB + b"foobar" + EB + CR)
self.mock_socket().sendall.assert_called_once_with(SB + b"foobar" + EB + CR)
self.assertFalse(self.mock_stdout.called)

def test_port(self):
Expand All @@ -188,7 +188,7 @@ def test_stdin(self):

mllp_send()

self.mock_socket().send.assert_called_once_with(SB + b"hello" + EB + CR)
self.mock_socket().sendall.assert_called_once_with(SB + b"hello" + EB + CR)

def test_loose_no_stdin(self):
self.option_values.loose = True
Expand All @@ -197,7 +197,7 @@ def test_loose_no_stdin(self):

mllp_send()

self.assertFalse(self.mock_socket().send.called)
self.assertFalse(self.mock_socket().sendall.called)
self.mock_stderr().write.assert_called_with("--loose requires --file\n")
self.mock_exit.assert_called_with(1)

Expand All @@ -207,7 +207,7 @@ def test_loose_windows_newline(self):

mllp_send()

self.mock_socket().send.assert_called_once_with(
self.mock_socket().sendall.assert_called_once_with(
SB + b"MSH|^~\\&|foo\rbar" + EB + CR
)

Expand All @@ -217,7 +217,7 @@ def test_loose_unix_newline(self):

mllp_send()

self.mock_socket().send.assert_called_once_with(
self.mock_socket().sendall.assert_called_once_with(
SB + b"MSH|^~\\&|foo\rbar" + EB + CR
)

Expand All @@ -227,7 +227,7 @@ def test_loose_no_mllp_characters(self):

mllp_send()

self.mock_socket().send.assert_called_once_with(
self.mock_socket().sendall.assert_called_once_with(
SB + b"MSH|^~\\&|foo\rbar" + EB + CR
)

Expand All @@ -239,11 +239,11 @@ def test_loose_send_mutliple(self):
mllp_send()

self.assertEqual(
self.mock_socket().send.call_args_list[0][0][0],
self.mock_socket().sendall.call_args_list[0][0][0],
SB + b"MSH|^~\\&|1\rOBX|1" + EB + CR,
)
self.assertEqual(
self.mock_socket().send.call_args_list[1][0][0],
self.mock_socket().sendall.call_args_list[1][0][0],
SB + b"MSH|^~\\&|2\rOBX|2" + EB + CR,
)

Expand Down