def test_new_encode(self): """ Check encoding using new generic method """ pdu = A_RELEASE_RQ() pdu.Decode(a_release_rq) s = pdu.encode() self.assertEqual(s, a_release_rq)
def test_stream_encode(self): """ Check encoding an release_rq produces the correct output """ pdu = A_RELEASE_RQ() pdu.Decode(a_release_rq) s = pdu.Encode() self.assertEqual(s, a_release_rq)
def test_generic_encode(self): """ Check using the new pdu.encode produces the correct output """ pdu = A_RELEASE_RQ() pdu.Decode(a_release_rq) s = pdu.Encode() t = pdu.encode() self.assertEqual(s, t)
def test_decode(self): """ Check decoding the release_rq stream produces the correct objects """ pdu = A_RELEASE_RQ() pdu.decode(a_release_rq) assert pdu.pdu_type == 0x05 assert pdu.pdu_length == 4 assert len(pdu) == 10
def test_to_primitive(self): """ Check converting PDU to primitive """ pdu = A_RELEASE_RQ() pdu.decode(a_release_rq) primitive = pdu.to_primitive() assert primitive.reason == "normal" assert primitive.result is None
def test_to_primitive(self): """ Check converting PDU to primitive """ pdu = A_RELEASE_RQ() pdu.Decode(a_release_rq) primitive = pdu.ToParams() self.assertEqual(primitive.reason, "normal") self.assertEqual(primitive.result, None)
def test_stream_decode_values_types(self): """ Check decoding the release_rq stream produces the correct objects """ pdu = A_RELEASE_RQ() pdu.Decode(a_release_rq) self.assertEqual(pdu.pdu_type, 0x05) self.assertEqual(pdu.pdu_length, 4) self.assertEqual(pdu.get_length(), 10) self.assertTrue(isinstance(pdu.pdu_type, int)) self.assertTrue(isinstance(pdu.pdu_length, int))
def test_wrap_encode_items(self): """Test PDU._wrap_encode_items().""" release_a = A_RELEASE_RQ() release_b = A_RELEASE_RQ() pdu = PDU() out = pdu._wrap_encode_items([release_a]) assert out == b'\x05\x00\x00\x00\x00\x04\x00\x00\x00\x00' out = pdu._wrap_encode_items([release_a, release_a]) assert out == b'\x05\x00\x00\x00\x00\x04\x00\x00\x00\x00' * 2
def test_from_primitive(self): """ Check converting PDU to primitive """ orig_pdu = A_RELEASE_RQ() orig_pdu.decode(a_release_rq) primitive = orig_pdu.to_primitive() new_pdu = A_RELEASE_RQ() new_pdu.from_primitive(primitive) assert new_pdu == orig_pdu
def AR_1(dul): """Association release AR-1. Send Association release request State-event triggers: Sta6 + Evt11 .. [1] DICOM Standard 2015b, PS3.8, Table 9-8, "Associate Release Related Actions" Parameters ---------- dul : pynetdicom3.dul.DULServiceProvider The DICOM Upper Layer Service instance for the local AE Returns ------- str Sta7, the next state of the state machine """ # Send A-RELEASE-RQ PDU dul.pdu = A_RELEASE_RQ() dul.pdu.FromParams(dul.primitive) # Callback dul.assoc.acse.debug_send_release_rq(dul.pdu) bytestream = dul.pdu.Encode() dul.scu_socket.send(bytestream) return 'Sta7'
def test_from_primitive(self): """ Check converting PDU to primitive """ orig_pdu = A_RELEASE_RQ() orig_pdu.Decode(a_release_rq) primitive = orig_pdu.ToParams() new_pdu = A_RELEASE_RQ() new_pdu.FromParams(primitive) self.assertEqual(new_pdu, orig_pdu)
def test__pdu_to_event(self): """Test that good PDU paramters return expected results""" dul = DummyDUL() p2e = dul._pdu_to_event pdu_types = [ A_ASSOCIATE_RQ(), A_ASSOCIATE_AC(), A_ASSOCIATE_RJ(), P_DATA_TF(), A_RELEASE_RQ(), A_RELEASE_RP(), A_ABORT_RQ(), 'TEST' ] event_str = [ 'Evt6', 'Evt3', 'Evt4', 'Evt10', 'Evt12', 'Evt13', 'Evt16', 'Evt19' ] for pdu, evt in zip(pdu_types, event_str): self.assertEqual(p2e(pdu), evt)
def _socket_to_pdu(self, data): """Returns the PDU object associated with an incoming data stream. Parameters ---------- data : bytes The incoming data stream Returns ------- pdu : pynetdicom3.pdu.PDU The decoded data as a PDU object """ pdutype = unpack('B', data[0:1])[0] acse = self.assoc.acse pdu_types = { 0x01: (A_ASSOCIATE_RQ(), acse.debug_receive_associate_rq), 0x02: (A_ASSOCIATE_AC(), acse.debug_receive_associate_ac), 0x03: (A_ASSOCIATE_RJ(), acse.debug_receive_associate_rj), 0x04: (P_DATA_TF(), acse.debug_receive_data_tf), 0x05: (A_RELEASE_RQ(), acse.debug_receive_release_rq), 0x06: (A_RELEASE_RP(), acse.debug_receive_release_rp), 0x07: (A_ABORT_RQ(), acse.debug_receive_abort) } if pdutype in pdu_types: pdu = pdu_types[pdutype][0] pdu.Decode(data) # ACSE callbacks pdu_types[pdutype][1](pdu) return pdu return None
def test_string_output(self): """Test the string output""" pdu = A_RELEASE_RQ() pdu.Decode(a_release_rq) self.assertTrue("0x05" in pdu.__str__()) self.assertTrue("10 bytes" in pdu.__str__())
def test_encode(self): """ Check encoding an release_rq produces the correct output """ pdu = A_RELEASE_RQ() pdu.decode(a_release_rq) assert pdu.encode() == a_release_rq
def test_init(self): """Test a new A_RELEASE_RQ PDU""" pdu = A_RELEASE_RQ() assert pdu.pdu_type == 0x05 assert pdu.pdu_length == 4 assert len(pdu) == 10
def test_string_output(self): """Test the string output""" pdu = A_RELEASE_RQ() pdu.decode(a_release_rq) assert "0x05" in pdu.__str__() assert "4 bytes" in pdu.__str__()