'In order to make sure the protocol never gets any invalid data sent
into the middle of a box, it must be locked for switching before it is
switched.  It can only be unlocked if the switch failed, and attempting
to send a box while it is locked should raise an exception.'

def test_protocolSwitchInvalidStates(self):

    a = amp.BinaryBoxProtocol(self)
    a.makeConnection(self)
    sampleBox = amp.Box({'some': 'data'})
    a._lockForSwitch()
    self.assertRaises(amp.ProtocolSwitched, a.sendBox, sampleBox)
    a._unlockFromSwitch()
    a.sendBox(sampleBox)
    self.assertEqual(''.join(self.data), sampleBox.serialize())
    a._lockForSwitch()
    otherProto = TestProto(None, 'outgoing    data')
    a._switchTo(otherProto)
    self.assertRaises(amp.ProtocolSwitched, a._unlockFromSwitch)
