def test_init(self): """Test initialisation of event.Event.""" event = evt.Event(None, evt.EVT_C_STORE) assert event.assoc is None assert event._event == evt.EVT_C_STORE assert isinstance(event.timestamp, datetime) assert event.event == evt.EVT_C_STORE assert event.event.name == 'EVT_C_STORE' assert isinstance(event.event.description, str) def callable(): return 'some value' event = evt.Event(None, evt.EVT_C_STORE, { 'aa': True, 'bb': False, 'cc': callable }) assert event.assoc is None assert event._event == evt.EVT_C_STORE assert event.event == evt.EVT_C_STORE assert isinstance(event.timestamp, datetime) assert event.event.name == 'EVT_C_STORE' assert isinstance(event.event.description, str) assert event.cc() == 'some value' assert event.aa is True assert event.bb is False
def test_init(self): """Test initialisation of event.Event.""" event = evt.Event(None, evt.EVT_C_STORE) assert event.assoc is None assert event._event == evt.EVT_C_STORE assert isinstance(event.timestamp, datetime) assert event.event == evt.EVT_C_STORE assert event.event.name == "EVT_C_STORE" assert isinstance(event.event.description, str) def callable(): return "some value" event = evt.Event( None, evt.EVT_C_STORE, {"aa": True, "bb": False, "cc": callable} ) assert event.assoc is None assert event._event == evt.EVT_C_STORE assert event.event == evt.EVT_C_STORE assert isinstance(event.timestamp, datetime) assert event.event.name == "EVT_C_STORE" assert isinstance(event.event.description, str) assert event.cc() == "some value" assert event.aa is True assert event.bb is False
def test_is_cancelled_non(self): """Test Event.is_cancelled with wrong event type.""" event = evt.Event(None, evt.EVT_DATA_RECV) assert event.is_cancelled is False def is_cancelled(msg_id): if msg_id in [1, 2, 3]: return True return False # No Message ID event = evt.Event(None, evt.EVT_DATA_RECV, {"_is_cancelled": is_cancelled}) assert event.is_cancelled is False
def test_raises(self): """Test property getters raise if not correct event type.""" event = evt.Event(None, evt.EVT_DATA_RECV) msg = (r"The corresponding event is not a C-STORE " r"request and has no 'Data Set' parameter") with pytest.raises(AttributeError, match=msg): event.dataset msg = ( r"The corresponding event is not a C-FIND, C-GET or C-MOVE request " r"and has no 'Identifier' parameter") with pytest.raises(AttributeError, match=msg): event.identifier msg = ( r"The corresponding event is not an N-ACTION request and has no " r"'Action Information' parameter") with pytest.raises(AttributeError, match=msg): event.action_information msg = ( r"The corresponding event is not an N-CREATE request and has no " r"'Attribute List' parameter") with pytest.raises(AttributeError, match=msg): event.attribute_list msg = (r"The corresponding event is not an N-EVENT-REPORT request and " r"has no 'Event Information' parameter") with pytest.raises(AttributeError, match=msg): event.event_information msg = (r"The corresponding event is not an N-SET request and has no " r"'Modification List' parameter") with pytest.raises(AttributeError, match=msg): event.modification_list
def test_is_cancelled(self): """Test Event.is_cancelled with correct event type.""" def is_cancelled(msg_id): if msg_id in [1, 2, 3]: return True return False message = namedtuple("Message", ["MessageID"]) msg = message(1) msg2 = message(7) event = evt.Event( None, evt.EVT_DATA_RECV, {"_is_cancelled": is_cancelled, "request": msg} ) assert event.is_cancelled is True event = evt.Event( None, evt.EVT_DATA_RECV, {"_is_cancelled": is_cancelled, "request": msg2} ) assert event.is_cancelled is False
def test_raises(self): """Test property getters raise if not correct event type.""" event = evt.Event(None, evt.EVT_DATA_RECV) msg = (r"The corresponding event is not a C-STORE " r"request and has no 'Data Set' parameter") with pytest.raises(AttributeError, match=msg): event.dataset msg = ( r"The corresponding event is not a C-FIND, C-GET or C-MOVE request " r"and has no 'Identifier' parameter") with pytest.raises(AttributeError, match=msg): event.identifier
def test_assign_existing(self): """Test adding an attribute that already exists.""" msg = r"'Event' object already has an attribute 'assoc'" with pytest.raises(AttributeError, match=msg): event = evt.Event(None, evt.EVT_C_STORE, {'assoc': None})
def test_raises(self): """Test property getters raise if not correct event type.""" event = evt.Event(None, evt.EVT_DATA_RECV) msg = (r"The corresponding event is not a C-STORE " r"request and has no 'Data Set' parameter") with pytest.raises(AttributeError, match=msg): event.dataset msg = ( r"The corresponding event is not a C-FIND, C-GET or C-MOVE request " r"and has no 'Identifier' parameter") with pytest.raises(AttributeError, match=msg): event.identifier msg = (r"The corresponding event is not a C-MOVE request " r"and has no 'Move Destination' parameter") with pytest.raises(AttributeError, match=msg): event.move_destination msg = ( r"The corresponding event is not an N-ACTION request and has no " r"'Action Information' parameter") with pytest.raises(AttributeError, match=msg): event.action_information msg = ( r"The corresponding event is not an N-CREATE request and has no " r"'Attribute List' parameter") with pytest.raises(AttributeError, match=msg): event.attribute_list msg = (r"The corresponding event is not an N-EVENT-REPORT request and " r"has no 'Event Information' parameter") with pytest.raises(AttributeError, match=msg): event.event_information msg = (r"The corresponding event is not an N-SET request and has no " r"'Modification List' parameter") with pytest.raises(AttributeError, match=msg): event.modification_list msg = (r"The corresponding event is not an N-GET request and has no " r"'Attribute Identifier List' parameter") with pytest.raises(AttributeError, match=msg): event.attribute_identifiers msg = ( r"The corresponding event is not an N-ACTION request and has no " r"'Action Type ID' parameter") with pytest.raises(AttributeError, match=msg): event.action_type msg = (r"The corresponding event is not an N-EVENT-REPORT request and " r"has no 'Event Type ID' parameter") with pytest.raises(AttributeError, match=msg): event.event_type msg = (r"The corresponding event is not a DIMSE service request and " r"has no 'Message ID' parameter") with pytest.raises(AttributeError, match=msg): event.message_id msg = (r"The corresponding event is either not a C-STORE request or " r"'STORE_RECV_CHUNKED_DATASET' is not True.") with pytest.raises(AttributeError, match=msg): event.dataset_path