示例#1
0
    def test_return_type(self):
        """ Check stream returns the value of the first byte as an int """
        s = BytesIO(b'\x01\x02\x03\x04\x04')
        pdu = PDU()

        item_type = pdu._next_item_type(s)
        self.assertTrue(isinstance(item_type, int))
示例#2
0
    def test_normal_stream(self):
        """ Check that a stream returns the value of the first byte  """
        s = BytesIO(b'\x01\x02\x03\x04\x04')
        pdu = PDU()

        item_type = pdu._next_item_type(s)
        self.assertTrue(item_type == 1)
示例#3
0
    def test_empty_stream(self):
        """ Check that an empty stream returns None """
        s = BytesIO(b'')
        pdu = PDU()

        item_type = pdu._next_item_type(s)
        self.assertTrue(item_type is None)
示例#4
0
    def test_generate_items_raises(self):
        """Test failure modes of PDU._generate_items method."""
        pdu = PDU()

        # Short data
        data = b'\x10\x00\x00\x02\x01'
        gen = pdu._generate_items(data)
        with pytest.raises(AssertionError):
            next(gen)
示例#5
0
    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
示例#6
0
    def test_correct_item(self):
        """ Check that stream returns correct item type """
        pdu = PDU()

        item = pdu._next_item(BytesIO(b'\x01'))
        self.assertTrue(isinstance(item, A_ASSOCIATE_RQ))

        item = pdu._next_item(BytesIO(b'\x02'))
        self.assertTrue(isinstance(item, A_ASSOCIATE_AC))

        item = pdu._next_item(BytesIO(b'\x10'))
        self.assertTrue(isinstance(item, ApplicationContextItem))
示例#7
0
    def test_wrap_generate_items(self):
        """Test PDU._wrap_generate_items()."""
        pdu = PDU()
        out = pdu._wrap_generate_items(b'')
        assert out == []

        data = b'\x10\x00\x00\x03\x31\x2e\x32'
        out = pdu._wrap_generate_items(data)
        assert out[0].application_context_name == '1.2'

        data += b'\x10\x00\x00\x04\x31\x2e\x32\x33'
        out = pdu._wrap_generate_items(data)
        assert out[0].application_context_name == '1.2'
        assert out[1].application_context_name == '1.23'
示例#8
0
 def test_inequality(self):
     """Test the inequality operator"""
     self.assertFalse(PDU() != PDU())
     self.assertTrue(PDU() != 'TEST')
     pdu = PDU()
     pdu.formats = ['a']
     self.assertTrue(pdu != PDU())
示例#9
0
    def test_generate_items(self):
        """Test the PDU._generate_items method."""
        pdu = PDU()
        gen = pdu._generate_items(b'')
        with pytest.raises(StopIteration):
            next(gen)

        data = b'\x10\x00\x00\x02\x01\x02'
        gen = pdu._generate_items(data)
        assert next(gen) == (0x10, data)
        with pytest.raises(StopIteration):
            next(gen)

        data += b'\x20\x00\x00\x03\x01\x02\x03'
        gen = pdu._generate_items(data)
        assert next(gen) == (0x10, b'\x10\x00\x00\x02\x01\x02')
        assert next(gen) == (0x20, b'\x20\x00\x00\x03\x01\x02\x03')
        with pytest.raises(StopIteration):
            next(gen)
示例#10
0
 def test_encoders_raises(self):
     """Test the PDU._encoders property raises NotImplementedError."""
     pdu = PDU()
     with pytest.raises(NotImplementedError):
         pdu._encoders
示例#11
0
 def test_wrap_bytes(self):
     """Test PDU._wrap_bytes()."""
     pdu = PDU()
     assert pdu._wrap_bytes(b'') == b''
     assert pdu._wrap_bytes(b'\x00\x01') == b'\x00\x01'
示例#12
0
 def test_decode_raises(self):
     """Test the PDU.decode method raises NotImplementedError."""
     pdu = PDU()
     with pytest.raises(NotImplementedError):
         pdu.decode(a_release_rq)
示例#13
0
 def test_encode_raises(self):
     """Test the PDU.encode method raises NotImplementedError."""
     pdu = PDU()
     with pytest.raises(NotImplementedError):
         pdu.encode()
示例#14
0
 def test_wrap_pack(self):
     """Test PDU._wrap_pack()."""
     pdu = PDU()
     out = pdu._wrap_pack(1, PACK_UCHAR)
     assert out == b'\x01'
示例#15
0
 def test_wrap_unpack(self):
     """Test PDU._wrap_unpack()."""
     pdu = PDU()
     out = pdu._wrap_unpack(b'\x01', UNPACK_UCHAR)
     assert out == 1
示例#16
0
 def test_hash_raises(self):
     """Test hash(PDU) raises exception."""
     pdu = PDU()
     with pytest.raises(TypeError):
         hash(pdu)
示例#17
0
 def test_wrap_encode_uid(self):
     """Test PDU._wrap_encode_uid()."""
     pdu = PDU()
     uid = UID('1.2.840.10008.1.1')
     out = pdu._wrap_encode_uid(uid)
     assert out == b'1.2.840.10008.1.1'
示例#18
0
 def test_pdu_length_raises(self):
     """Test PDU.pdu_length raises NotImplementedError."""
     pdu = PDU()
     with pytest.raises(NotImplementedError):
         pdu.pdu_length
示例#19
0
    def test_unknown_item_type(self):
        """ Check that an unknown item value raises ValueError """
        s = BytesIO(b'\x00\x02\x03\x04\x04')
        pdu = PDU()

        self.assertRaises(ValueError, pdu._next_item, s)
示例#20
0
 def test_pdu_type_raises(self):
     """Test PDU.pdu_type raises ValueError."""
     pdu = PDU()
     with pytest.raises(ValueError):
         pdu.pdu_type