Ejemplo n.º 1
0
def test_uid_illegal_character(illegal_char):
    """Checks *ValueError* is raised when a UID contains an illegal char."""
    with pytest.raises(ValueError, match='in conformance'):
        URI(_BASE_URL, f'1.2{illegal_char}3')
    with pytest.raises(ValueError, match='in conformance'):
        URI(_BASE_URL, '1.2.3', f'4.5{illegal_char}6')
    with pytest.raises(ValueError, match='in conformance'):
        URI(_BASE_URL, '1.2.3', '4.5.6', f'7.8{illegal_char}9')
Ejemplo n.º 2
0
def test_update_permissive(original, update, expected):
    """Tests for the expected value of `permissive` flag in `URI.update()`."""
    if original is None:
        original_uri = URI(_BASE_URL)
    else:
        original_uri = URI(_BASE_URL, permissive=original)
    updated_uri = original_uri.update(permissive=update)
    assert updated_uri.permissive == expected
Ejemplo n.º 3
0
def test_uid_illegal_format(illegal_uid):
    """Checks *ValueError* is raised if a UID is in an illegal format."""
    with pytest.raises(ValueError, match='in conformance'):
        URI(_BASE_URL, illegal_uid)
    with pytest.raises(ValueError, match='in conformance'):
        URI(_BASE_URL, '1.2.3', illegal_uid)
    with pytest.raises(ValueError, match='in conformance'):
        URI(_BASE_URL, '1.2.3', '4.5.6', illegal_uid)
Ejemplo n.º 4
0
def test_uid_missing_error():
    """Checks *ValueError* is raised when an expected UID is missing."""
    with pytest.raises(ValueError, match='`study_instance_uid` missing with'):
        URI(_BASE_URL, None, '4.5.6')
    with pytest.raises(ValueError, match='`study_instance_uid` missing with'):
        URI(_BASE_URL, None, '4.5.6', '7.8.9')
    with pytest.raises(ValueError, match='`series_instance_uid` missing with'):
        URI(_BASE_URL, '4.5.6', None, '7.8.9')
    with pytest.raises(ValueError, match='`sop_instance_uid` missing with'):
        URI(_BASE_URL, '4.5.6', '7.8.9', None, _FRAMES)
Ejemplo n.º 5
0
def test_suffix_not_compatible():
    """Checks *ValueError* is raised when an incompatible suffix is set."""
    # Metadata.
    with pytest.raises(ValueError, match='\'metadata\'> suffix may only be'):
        URI(_BASE_URL, suffix=URISuffix.METADATA)
    with pytest.raises(ValueError, match='\'metadata\'> suffix may only be'):
        URI(_BASE_URL, _STUDY_UID, _SERIES_UID, _INSTANCE_UID, _FRAMES,
            suffix=URISuffix.METADATA)
    # Rendered.
    with pytest.raises(ValueError, match='\'rendered\'> suffix requires a'):
        URI(_BASE_URL, suffix=URISuffix.RENDERED)
    # Thumbnail.
    with pytest.raises(ValueError, match='\'thumbnail\'> suffix requires a'):
        URI(_BASE_URL, suffix=URISuffix.THUMBNAIL)
Ejemplo n.º 6
0
def test_uid_length():
    """Checks that UIDs longer than 64 characters are disallowed."""
    # Success with 64 characters.
    uid_64 = '1' * 64
    URI(_BASE_URL, uid_64)
    URI(_BASE_URL, '1.2.3', uid_64)
    URI(_BASE_URL, '1.2.3', '4.5.6', uid_64)

    # Failure with 65 characters.
    uid_65 = '1' * 65
    with pytest.raises(ValueError, match='UID cannot have more'):
        URI(_BASE_URL, uid_65)
    with pytest.raises(ValueError, match='UID cannot have more'):
        URI(_BASE_URL, '1.2.3', uid_65)
    with pytest.raises(ValueError, match='UID cannot have more'):
        URI(_BASE_URL, '1.2.3', '4.5.6', uid_65)
Ejemplo n.º 7
0
def test_from_string_service_uri():
    """Checks that Service URL is parsed correctly and behaves as expected."""
    service_uri = URI.from_string(_BASE_URL)
    # Properties.
    assert service_uri.base_url == _BASE_URL
    assert service_uri.study_instance_uid is None
    assert service_uri.series_instance_uid is None
    assert service_uri.sop_instance_uid is None
    assert service_uri.type == URIType.SERVICE
    assert service_uri.suffix is None
    # String representation.
    assert str(service_uri) == _BASE_URL
    assert str(service_uri.base_uri()) == _BASE_URL
    # Constructor.
    assert str(service_uri) == str(URI(_BASE_URL))

    with pytest.raises(ValueError, match='Cannot get a Study URI'):
        service_uri.study_uri()
    with pytest.raises(ValueError, match='Cannot get a Series URI'):
        service_uri.series_uri()
    with pytest.raises(ValueError, match='Cannot get an Instance URI'):
        service_uri.instance_uri()
    with pytest.raises(ValueError, match='Cannot get a Frame URI'):
        service_uri.frame_uri()
Ejemplo n.º 8
0
def test_uid_permissive_invalid(uid):
    """Tests that invalid "permissive" UIDs are rejected."""
    with pytest.raises(ValueError, match='Permissive mode'):
        URI(_BASE_URL, uid, permissive=True)
Ejemplo n.º 9
0
def test_uid_permissive_valid(uid):
    """Tests valid "permissive" UIDs are accommodated iff the flag is set."""
    with pytest.raises(ValueError, match='in conformance'):
        URI(_BASE_URL, uid, permissive=False)
    URI(_BASE_URL, uid, permissive=True)
Ejemplo n.º 10
0
def test_update_error(uri_args, update_args, error_msg):
    """Tests for failure if the `URI` returned by `update()` is invalid."""
    with pytest.raises(ValueError, match=error_msg):
        URI(*uri_args).update(*update_args)
Ejemplo n.º 11
0
def test_update(uri_args, update_args, expected_uri_args):
    """Tests for failure if the `URI` returned by `update()` is invalid."""
    actual_uri = URI(*uri_args).update(*update_args)
    expected_uri = URI(*expected_uri_args)
    assert actual_uri == expected_uri
Ejemplo n.º 12
0
def test_frames_empty():
    """Checks *ValueError* is raised if frame list is empty."""
    with pytest.raises(ValueError, match='cannot be empty'):
        URI(_BASE_URL, _STUDY_UID, _SERIES_UID, _INSTANCE_UID, [])
Ejemplo n.º 13
0
def test_eq_false(params):
    """Tests the `==` operator implementation for failed comparison."""
    other_params = (None if param is None else param + '1' for param in params)
    assert URI(*params) != URI(*other_params)
Ejemplo n.º 14
0
def test_eq_true(params):
    """Tests the `==` operator implementation for successful comparison."""
    assert URI(*params) == URI(*params)
Ejemplo n.º 15
0
def test_trailing_slash_error():
    """Tests constructor failure if the Service URL has a trailing slash."""
    base_url = 'https://oh-well-this-was-fun.com/'
    with pytest.raises(ValueError, match='trailing forward slash'):
        URI(base_url)
Ejemplo n.º 16
0
def test_frames_ascending_order():
    """Checks *ValueError* is raised if frames are not in ascending order."""
    with pytest.raises(ValueError, match='must be in ascending'):
        URI(_BASE_URL, _STUDY_UID, _SERIES_UID, _INSTANCE_UID, [4, 3, 5])
Ejemplo n.º 17
0
def test_eq_not_implemented():
    """Tests the `==` operator implementation for incompatible type."""
    assert URI(_BASE_URL) != 0
Ejemplo n.º 18
0
def test_non_positive_frame_numbers(illegal_frame_number):
    """Checks *ValueError* is raised if frame numbers are not positive."""
    with pytest.raises(ValueError, match='must be positive'):
        URI(_BASE_URL, _STUDY_UID, _SERIES_UID, _INSTANCE_UID,
            [illegal_frame_number])