Esempio n. 1
0
    def test_empty_passthrough(self):
        """Test an empty value passes through validation"""
        uid = set_uid('', 'foo')
        assert uid == UID('')

        uid = set_uid(b'', 'foo')
        assert uid == UID('')

        uid = set_uid(UID(''), 'foo')
        assert uid == UID('')
Esempio n. 2
0
    def test_empty_passthrough(self):
        """Test an empty value passes through validation"""
        uid = set_uid("", "foo")
        assert uid == UID("")

        uid = set_uid(b"", "foo")
        assert uid == UID("")

        uid = set_uid(UID(""), "foo")
        assert uid == UID("")
Esempio n. 3
0
    def test_bytes_decoding_error(self, caplog):
        """Test invalid bytes raises exception"""
        b = "1.2.3".encode("utf_32")
        assert isinstance(b, bytes)
        msg = (
            r"Unable to decode 'FF FE 00 00 31 00 00 00 2E 00 00 00 32 00 00 "
            r"00 2E 00 00 00 33 00 00 00' using the ascii codec\(s\)")
        with caplog.at_level(logging.ERROR, logger="pynetdicom"):
            with pytest.raises(ValueError, match=msg):
                set_uid(b, "foo")

            assert ("'ascii' codec can't decode byte 0xff in position 0"
                    ) in caplog.text
Esempio n. 4
0
 def test_bytes(self):
     """Test bytes -> UID"""
     b = "1.2.3".encode("ascii")
     assert isinstance(b, bytes)
     uid = set_uid(b, "foo")
     assert isinstance(uid, UID)
     assert uid == "1.2.3"
Esempio n. 5
0
 def test_bytes(self):
     """Test bytes -> UID"""
     b = '1.2.3'.encode('ascii')
     assert isinstance(b, bytes)
     uid = set_uid(b, 'foo')
     assert isinstance(uid, UID)
     assert uid == '1.2.3'
Esempio n. 6
0
    def test_valid_non_conformant_warns(self, caplog):
        """Test a valid but non-conformant UID warns"""
        with caplog.at_level(logging.WARNING, logger="pynetdicom"):
            uid = set_uid("1.2.03", "foo")
            assert isinstance(uid, UID)
            assert uid == "1.2.03"

            assert "Non-conformant 'foo' value '1.2.03'" in caplog.text
Esempio n. 7
0
    def test_no_validation(self, caplog):
        """Test skipping validation"""
        with caplog.at_level(logging.WARNING, logger="pynetdicom"):
            uid = set_uid("abc" * 22, "foo", validate=False)
            assert isinstance(uid, UID)
            assert uid == "abc" * 22

            assert not caplog.text
Esempio n. 8
0
    def test_no_validation(self, caplog):
        """Test skipping validation"""
        with caplog.at_level(logging.WARNING, logger='pynetdicom'):
            uid = set_uid('abc' * 22, 'foo', validate=False)
            assert isinstance(uid, UID)
            assert uid == 'abc' * 22

            assert not caplog.text
Esempio n. 9
0
    def test_invalid_raises(self, caplog):
        """Test invalid UID raises exception"""
        with caplog.at_level(logging.ERROR, logger="pynetdicom"):
            bad = "abc" * 22
            msg = f"Invalid 'foo' value '{bad}' - must not exceed 64 characters"
            with pytest.raises(ValueError, match=msg):
                uid = set_uid(bad, "foo")
                assert isinstance(uid, UID)
                assert uid == bad

            assert msg in caplog.text
Esempio n. 10
0
 def test_none_disallowed(self):
     """Test None raises exception"""
     msg = "'foo' must be str, bytes or UID, not 'NoneType'"
     with pytest.raises(TypeError, match=msg):
         set_uid(None, "foo", allow_none=False)
Esempio n. 11
0
 def test_none_allowed(self):
     """Test None -> None"""
     uid = set_uid(None, "foo", allow_none=True)
     assert uid is None
Esempio n. 12
0
 def test_uid(self):
     """Test UID -> UID"""
     uid = set_uid(UID("1.2.3"), "foo")
     assert isinstance(uid, UID)
     assert uid == "1.2.3"
Esempio n. 13
0
 def test_str(self):
     """Test str -> UID"""
     uid = set_uid('1.2.3', 'foo')
     assert isinstance(uid, UID)
     assert uid == '1.2.3'
Esempio n. 14
0
 def test_str(self):
     """Test str -> UID"""
     uid = set_uid("1.2.3", "foo")
     assert isinstance(uid, UID)
     assert uid == "1.2.3"
Esempio n. 15
0
 def test_uid(self):
     """Test UID -> UID"""
     uid = set_uid(UID('1.2.3'), 'foo')
     assert isinstance(uid, UID)
     assert uid == '1.2.3'
Esempio n. 16
0
 def test_empty_raises(self):
     """Test empty raises exception"""
     msg = r"Invalid 'foo' value - must not be an empty str"
     with pytest.raises(ValueError, match=msg):
         set_uid("", "foo", allow_empty=False)
Esempio n. 17
0
 def abstract_syntax(self, value: Union[str, bytes, UID]) -> None:
     """Set the context's *Abstract Syntax*."""
     self._abstract_syntax = (set_uid(value, "abstract_syntax", True, False,
                                      True))