示例#1
0
    def test_assignment_and_exceptions(self):
        """Check incorrect setting for implementation_version_name raises"""
        primitive = ImplementationVersionNameNotification()

        ## Check assignment
        reference_name = b'PYNETDICOM_090'

        ## Check maximum length allowable
        primitive.implementation_version_name = b'1234567890ABCDEF'
        assert primitive.implementation_version_name == b'1234567890ABCDEF'

        # bytes
        primitive.implementation_version_name = b'PYNETDICOM_090'
        assert primitive.implementation_version_name == reference_name

        # str
        primitive.implementation_version_name = 'PYNETDICOM_090'
        assert 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'
示例#2
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()

        assert item.encode() == (
            b'\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f'
            b'\x30\x39\x30')
示例#3
0
    def test_assignment_and_exceptions(self):
        """Check incorrect setting for implementation_version_name raises"""
        primitive = ImplementationVersionNameNotification()

        ## Check assignment
        reference_name = "PYNETDICOM_090"

        ## Check maximum length allowable
        primitive.implementation_version_name = "1234567890ABCDEF"
        assert primitive.implementation_version_name == "1234567890ABCDEF"

        # bytes
        primitive.implementation_version_name = "PYNETDICOM_090"
        assert primitive.implementation_version_name == reference_name

        # str
        primitive.implementation_version_name = "PYNETDICOM_090"
        assert primitive.implementation_version_name == reference_name

        primitive.implementation_version_name = "P"
        assert primitive.implementation_version_name == "P"

        ## 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

        bad = "ABCD1234ABCD12345"
        msg = (
            f"Invalid 'Implementation Version Name' value '{bad}' - must not "
            "exceed 16 characters"
        )
        with pytest.raises(ValueError, match=msg):
            primitive.implementation_version_name = bad

        primitive.implementation_version_name = ""
        assert primitive.implementation_version_name == ""
        primitive.implementation_version_name = None
        assert primitive.implementation_version_name is None