Ejemplo n.º 1
0
    def test_adding(self):
        """Tests for adding a new constant to the Status enum."""
        with pytest.raises(AttributeError, match=r'PENDING_WITH_WARNING'):
            Status.PENDING_WITH_WARNING

        Status.add('PENDING_WITH_WARNING', 0xFF01)
        assert 0xFF01 == Status.PENDING_WITH_WARNING
        assert 0x0000 == Status.SUCCESS
        assert 0xFE00 == Status.CANCEL
        assert 0xFF00 == Status.PENDING
Ejemplo n.º 2
0
    def test_status_enum(self):
        """Test failure to decode the dataset"""
        # Hard to test directly as decode errors won't show up until the
        #   dataset is actually used
        Status.add("UNABLE_TO_DECODE", 0xC210)

        def handle(event):
            try:
                for elem in event.dataset.iterall():
                    pass
            except:
                status = Dataset()
                status.Status = Status.UNABLE_TO_DECODE
                status.ErrorComment = "Unable to decode the dataset"
                return status

            return Status.SUCCESS

        handlers = [(evt.EVT_C_STORE, handle)]

        self.ae = ae = AE()
        ae.add_supported_context(CTImageStorage)
        ae.add_requested_context(CTImageStorage, ExplicitVRLittleEndian)
        scp = ae.start_server(("localhost", 11112),
                              block=False,
                              evt_handlers=handlers)

        assoc = ae.associate("localhost", 11112)
        assert assoc.is_established

        req = C_STORE()
        req.MessageID = 1
        req.AffectedSOPClassUID = DATASET.SOPClassUID
        req.AffectedSOPInstanceUID = DATASET.SOPInstanceUID
        req.Priority = 0x0002
        req.DataSet = BytesIO(
            b"\x08\x00\x01\x00\x40\x40\x00\x00\x00\x00\x00\x08\x00\x49")

        # Send C-STORE request to DIMSE and get response
        assoc._reactor_checkpoint.clear()
        assoc.dimse.send_msg(req, 1)
        with pytest.warns(UserWarning):
            cx_id, rsp = assoc.dimse.get_msg(True)
        assoc._reactor_checkpoint.set()

        assert rsp.Status == 0xC210
        assert rsp.ErrorComment == "Unable to decode the dataset"
        assoc.release()
        assert assoc.is_released

        scp.shutdown()