def test_data_received_in_bad_state(self): """ Ensure the correct RuntimeError is called if the state of the FSM is invalid. """ transport = mock.MagicMock() transport.close = mock.MagicMock() connector = mock.MagicMock() node = mock.MagicMock() p = NetstringProtocol(connector, node) p.connection_made(transport) p._reader_state = 4 with self.assertRaises(RuntimeError): p.data_received('11:hello world@'.encode('utf-8'))