Skip to content

Commit f23be89

Browse files
committed
tests: Add tests for numeric response data in stat() method
1 parent 18dfd83 commit f23be89

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Lib/test/test_poplib.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,27 @@ def test_pass_(self):
289289
def test_stat(self):
290290
self.assertEqual(self.client.stat(), (10, 100))
291291

292+
original_shortcmd = self.client._shortcmd
293+
def mock_shortcmd_invalid_format(cmd):
294+
if cmd == 'STAT':
295+
return b'+OK'
296+
return original_shortcmd(cmd)
297+
298+
self.client._shortcmd = mock_shortcmd_invalid_format
299+
with self.assertRaises(poplib.error_proto):
300+
self.client.stat()
301+
302+
def mock_shortcmd_invalid_data(cmd):
303+
if cmd == 'STAT':
304+
return b'+OK abc def'
305+
return original_shortcmd(cmd)
306+
307+
self.client._shortcmd = mock_shortcmd_invalid_data
308+
with self.assertRaises(poplib.error_proto):
309+
self.client.stat()
310+
311+
self.client._shortcmd = original_shortcmd
312+
292313
def test_list(self):
293314
self.assertEqual(self.client.list()[1:],
294315
([b'1 1', b'2 2', b'3 3', b'4 4', b'5 5'],

0 commit comments

Comments
 (0)