'command_list_end' before 'command_list_start' now returns 'unknown command' error instead of crashing

This commit is contained in:
Stein Magnus Jodal 2010-06-24 19:47:44 +02:00
parent 873e387618
commit d093e498d8
2 changed files with 8 additions and 0 deletions

View File

@ -169,6 +169,9 @@ class MpdFrontend(object):
@handle_pattern(r'^command_list_end$')
def _command_list_end(self):
"""See :meth:`_command_list_begin`."""
if self.command_list is False:
# Test for False exactly, and not e.g. empty list
raise MpdUnknownCommand(command='command_list_end')
(command_list, self.command_list) = (self.command_list, False)
(command_list_ok, self.command_list_ok) = (self.command_list_ok, False)
result = []

View File

@ -67,6 +67,11 @@ class CommandListsTest(unittest.TestCase):
result = self.h.handle_request(u'command_list_end')
self.assert_(u'OK' in result)
def test_command_list_end_without_start_first_is_an_unknown_command(self):
result = self.h.handle_request(u'command_list_end')
self.assertEquals(result[0],
u'ACK [5@0] {} unknown command "command_list_end"')
def test_command_list_with_ping(self):
self.h.handle_request(u'command_list_begin')
self.assertEqual([], self.h.command_list)