Esempio n. 1
0
    def test_conversion(self):
        """ Check converting to PDU item works correctly """
        primitive = ImplementationVersionNameNotification()
        primitive.implementation_version_name = b'PYNETDICOM_090'
        item = primitive.from_primitive()

        self.assertTrue(item.encode() == b'\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30\x39\x30')
    def test_assignment_and_exceptions(self):
        """ Check incorrect types/values for implementation_version_name raise exceptions """
        primitive = ImplementationVersionNameNotification()

        ## Check assignment
        reference_name = b'PYNETDICOM_090'

        ## Check maximum length allowable
        primitive.implementation_version_name = b'1234567890ABCDEF'
        self.assertEqual(primitive.implementation_version_name,
                         b'1234567890ABCDEF')

        # bytes
        primitive.implementation_version_name = b'PYNETDICOM_090'
        self.assertTrue(
            primitive.implementation_version_name == reference_name)

        # str
        primitive.implementation_version_name = 'PYNETDICOM_090'
        self.assertTrue(
            primitive.implementation_version_name == reference_name)

        ## Check exceptions
        primitive = ImplementationVersionNameNotification()

        # No value set
        with pytest.raises(ValueError):
            item = primitive.from_primitive()

        # Non UID, bytes or str
        with pytest.raises(TypeError):
            primitive.implementation_version_name = 45.2

        with pytest.raises(TypeError):
            primitive.implementation_version_name = 100

        with pytest.raises(ValueError):
            primitive.implementation_version_name = 'ABCD1234ABCD12345'