Skip to content

Commit 09335c9

Browse files
NiklasMMjohnpaulett
authored andcommitted
Use socket.sendall instead of socket.send
Close #41
1 parent 9371204 commit 09335c9

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

hl7/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def send(self, data):
8484
wrapped in an MLLP container). Blocks until the server returns.
8585
"""
8686
# upload the data
87-
self.socket.send(data)
87+
self.socket.sendall(data)
8888
# wait for the ACK/NACK
8989
return self.socket.recv(RECV_BUFFER)
9090

tests/test_client.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_send(self):
3737
result = self.client.send("foobar\n")
3838
self.assertEqual(result, "thanks")
3939

40-
self.client.socket.send.assert_called_once_with("foobar\n")
40+
self.client.socket.sendall.assert_called_once_with("foobar\n")
4141
self.client.socket.recv.assert_called_once_with(4096)
4242

4343
def test_send_message_unicode(self):
@@ -46,15 +46,15 @@ def test_send_message_unicode(self):
4646
result = self.client.send_message("foobar")
4747
self.assertEqual(result, "thanks")
4848

49-
self.client.socket.send.assert_called_once_with(b"\x0bfoobar\x1c\x0d")
49+
self.client.socket.sendall.assert_called_once_with(b"\x0bfoobar\x1c\x0d")
5050

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

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

57-
self.client.socket.send.assert_called_once_with(b"\x0bfoobar\x1c\x0d")
57+
self.client.socket.sendall.assert_called_once_with(b"\x0bfoobar\x1c\x0d")
5858

5959
def test_send_message_hl7_message(self):
6060
self.client.socket.recv.return_value = "thanks"
@@ -64,15 +64,15 @@ def test_send_message_hl7_message(self):
6464
result = self.client.send_message(message)
6565
self.assertEqual(result, "thanks")
6666

67-
self.client.socket.send.assert_called_once_with(
67+
self.client.socket.sendall.assert_called_once_with(
6868
b"\x0bMSH|^~\\&|GHH LAB|ELAB\r\x1c\x0d"
6969
)
7070

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

75-
self.client.socket.send.assert_called_once_with("hello world")
75+
self.client.socket.sendall.assert_called_once_with("hello world")
7676
self.client.socket.close.assert_called_once_with()
7777

7878
def test_context_manager_exception(self):
@@ -142,7 +142,7 @@ def test_send(self):
142142
mllp_send()
143143

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

@@ -153,25 +153,25 @@ def test_send_multiple(self):
153153
mllp_send()
154154

155155
self.assertEqual(
156-
self.mock_socket().send.call_args_list[0][0][0], SB + b"foobar" + EB + CR
156+
self.mock_socket().sendall.call_args_list[0][0][0], SB + b"foobar" + EB + CR
157157
)
158158
self.assertEqual(
159-
self.mock_socket().send.call_args_list[1][0][0], SB + b"hello" + EB + CR
159+
self.mock_socket().sendall.call_args_list[1][0][0], SB + b"hello" + EB + CR
160160
)
161161

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

165165
self.assertRaises(MLLPException, mllp_send)
166166

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

169169
def test_quiet(self):
170170
self.option_values.verbose = False
171171

172172
mllp_send()
173173

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

177177
def test_port(self):
@@ -187,7 +187,7 @@ def test_stdin(self):
187187

188188
mllp_send()
189189

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

192192
def test_loose_no_stdin(self):
193193
self.option_values.loose = True
@@ -196,7 +196,7 @@ def test_loose_no_stdin(self):
196196

197197
mllp_send()
198198

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

@@ -206,7 +206,7 @@ def test_loose_windows_newline(self):
206206

207207
mllp_send()
208208

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

@@ -216,7 +216,7 @@ def test_loose_unix_newline(self):
216216

217217
mllp_send()
218218

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

@@ -226,7 +226,7 @@ def test_loose_no_mllp_characters(self):
226226

227227
mllp_send()
228228

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

@@ -238,11 +238,11 @@ def test_loose_send_mutliple(self):
238238
mllp_send()
239239

240240
self.assertEqual(
241-
self.mock_socket().send.call_args_list[0][0][0],
241+
self.mock_socket().sendall.call_args_list[0][0][0],
242242
SB + b"MSH|^~\\&|1\rOBX|1" + EB + CR,
243243
)
244244
self.assertEqual(
245-
self.mock_socket().send.call_args_list[1][0][0],
245+
self.mock_socket().sendall.call_args_list[1][0][0],
246246
SB + b"MSH|^~\\&|2\rOBX|2" + EB + CR,
247247
)
248248

0 commit comments

Comments
 (0)