'test closing all channels'

def test_close_channels(self):

    self.connection.connection_state = self.connection.CONNECTION_OPEN
    self.connection.callbacks = mock.Mock(spec=self.connection.callbacks)
    opening_channel = mock.Mock(is_open=False, is_closed=False, is_closing=False)
    open_channel = mock.Mock(is_open=True, is_closed=False, is_closing=False)
    closing_channel = mock.Mock(is_open=False, is_closed=False, is_closing=True)
    self.connection._channels = {'openingc': opening_channel, 'openc': open_channel, 'closingc': closing_channel}
    self.connection._close_channels(400, 'reply    text')
    opening_channel.close.assert_called_once_with(400, 'reply    text')
    open_channel.close.assert_called_once_with(400, 'reply    text')
    self.assertFalse(closing_channel.close.called)
    self.assertTrue(('openingc' in self.connection._channels))
    self.assertTrue(('openc' in self.connection._channels))
    self.assertTrue(('closingc' in self.connection._channels))
    self.assertFalse(self.connection.callbacks.cleanup.called)
    self.connection.connection_state = self.connection.CONNECTION_CLOSED
    with self.assertRaises(AssertionError):
        self.connection._close_channels(200, 'reply    text')
