示例#1
0
    def test_assignment_and_exceptions(self):
        """ Check incorrect types/values for properties raise exceptions """
        primitive = AsynchronousOperationsWindowNegotiation()

        ## Check default assignment
        assert primitive.maximum_number_operations_invoked == 1
        assert primitive.maximum_number_operations_performed == 1

        ## Check assignment
        primitive.maximum_number_operations_invoked = 10
        assert primitive.maximum_number_operations_invoked == 10

        primitive.maximum_number_operations_performed = 11
        assert primitive.maximum_number_operations_performed == 11

        ## Check exceptions
        with pytest.raises(TypeError):
            primitive.maximum_number_operations_invoked = 45.2

        with pytest.raises(ValueError):
            primitive.maximum_number_operations_invoked = -1

        with pytest.raises(TypeError):
            primitive.maximum_number_operations_invoked = 'ABCD1234ABCD12345'

        with pytest.raises(TypeError):
            primitive.maximum_number_operations_performed = 45.2

        with pytest.raises(ValueError):
            primitive.maximum_number_operations_performed = -1

        with pytest.raises(TypeError):
            primitive.maximum_number_operations_performed = 'ABCD1234ABCD12345'
示例#2
0
 def test_string(self):
     """Check the string output."""
     primitive = AsynchronousOperationsWindowNegotiation()
     primitive.maximum_number_operations_invoked = 10
     primitive.maximum_number_operations_performed = 0
     assert 'invoked: 10' in primitive.__str__()
     assert 'performed: 0' in primitive.__str__()
示例#3
0
    def _check_async_ops(self):
        """Check the user's response to an Asynchronous Operations request.

        .. currentmodule:: pynetdicom.pdu_primitives

        Returns
        -------
        pdu_primitives.AsynchronousOperationsWindowNegotiation or None
            If the ``evt.EVT_ASYNC_OPS`` handler hasn't been implemented
            then returns ``None``, otherwise returns an
            :class:`AsynchronousOperationsWindowNegotiation` item with the
            default values for the number of operations invoked/performed
            (1, 1).
        """
        # pylint: disable=broad-except
        try:
            # Response is always ignored as async ops is not supported
            inv, perf = self.requestor.asynchronous_operations
            _ = evt.trigger(self.assoc, evt.EVT_ASYNC_OPS, {
                'nr_invoked': inv,
                'nr_performed': perf
            })
        except NotImplementedError:
            return None
        except Exception as exc:
            LOGGER.error(
                "Exception raised in handler bound to 'evt.EVT_ASYNC_OPS'")
            LOGGER.exception(exc)

        item = AsynchronousOperationsWindowNegotiation()
        item.maximum_number_operations_invoked = 1
        item.maximum_number_operations_performed = 1

        return item
示例#4
0
    def test_conversion(self):
        """ Check converting to PDU item works correctly """
        primitive = AsynchronousOperationsWindowNegotiation()
        primitive.maximum_number_operations_invoked = 10
        primitive.maximum_number_operations_performed = 0
        item = primitive.from_primitive()

        assert item.encode() == b'\x53\x00\x00\x04\x00\x0a\x00\x00'
示例#5
0
    def _check_async_ops(self):
        """Check the user's response to an Asynchronous Operations request.

        Returns
        -------
        pdu_primitives.AsynchronousOperationsWindowNegotiation or None
            If the `AE.on_async_ops_window` callback hasn't been implemented
            then returns None, otherwise returns an
            AsynchronousOperationsWindowNegotiation item with the default
            values for the number of operations invoked/performed (1, 1).
        """
        # pylint: disable=broad-except
        try:
            # TODO: refactor in v1.4
            # Response is always ignored as async ops is not supported
            default = evt.get_default_handler(evt.EVT_ASYNC_OPS)
            if self.assoc.get_handlers(evt.EVT_ASYNC_OPS) != default:
                inv, perf = self.assoc.requestor.asynchronous_operations
                _ = evt.trigger(
                    self.assoc,
                    evt.EVT_ASYNC_OPS,
                    {'nr_invoked' : inv, 'nr_performed' : perf}
                )
            else:
                _ = self.assoc.ae.on_async_ops_window(
                    *self.assoc.requestor.asynchronous_operations
                )
        except NotImplementedError:
            return None
        except Exception as exc:
            LOGGER.error(
                "Exception raised in user's 'on_async_ops_window' "
                "implementation"
            )
            LOGGER.exception(exc)

        item = AsynchronousOperationsWindowNegotiation()
        item.maximum_number_operations_invoked = 1
        item.maximum_number_operations_performed = 1

        return item
示例#6
0
 def add_async_ops(self, primitive):
     """Add Asynchronous Ops to the A-ASSOCIATE primitive."""
     item = AsynchronousOperationsWindowNegotiation()
     item.maximum_number_operations_invoked = 2
     item.maximum_number_operations_performed = 3
     primitive.user_information.append(item)