예제 #1
0
def test_user_inputs_raises(user_input_params):
    # GIVEN a set of inputs of the wrong data type or shape
    input_data, exception = user_input_params

    # WHEN an attempt is made to decode it
    # THEN it raises a particular exception
    with pytest.raises(exception):
        ljpeg.decode(input_data)
예제 #2
0
def test_decode_unsupported_marker_raises(example_numpy_lossy_photo):
    # GIVEN a lossy jpg (which isn't supported)
    input_file = example_numpy_lossy_photo

    # WHEN there's an attempt to decode it
    # THEN it raises an exception
    with pytest.raises(NotImplementedError):
        ljpeg.decode(input_file)
예제 #3
0
def test_decode_tqi_value_raises(example_numpy_lossless_photo_w_bad_tqi_value):
    # GIVEN a lossless jpg with a bad Hi value
    input_file = example_numpy_lossless_photo_w_bad_tqi_value
    expected = 'Tqi should be zero'

    # WHEN an attempt is made to decode it
    # THEN it raises a particular exception with particular text
    with pytest.raises(ValueError) as e:
        ljpeg.decode(input_file)
        err_msg = e.value.args[0]
        assert err_msg == expected
예제 #4
0
def test_decode_vi_value_raises(example_numpy_lossless_photo_w_bad_vi_value):
    # GIVEN a lossless jpg with a bad Hi value
    input_file = example_numpy_lossless_photo_w_bad_vi_value
    expected = 'Pixels are an unsupported shape, Vi'

    # WHEN attempt is made to decode it
    # THEN it raises a particular exception with particular text
    with pytest.raises(NotImplementedError) as e:
        ljpeg.decode(input_file)
        err_msg = e.value.args[0]
        assert err_msg == expected
예제 #5
0
def test_decode_huffman_value_raises(
        example_numpy_lossless_photo_w_bad_huffman_value):
    # GIVEN a lossless jpg with bad huffman values
    input_file = example_numpy_lossless_photo_w_bad_huffman_value
    expected = 'No matching Huffman code was found for a lossless tile jpeg lkj'

    # WHEN attempt is made to decode it
    # THEN it raises a particular exception with particular text
    with pytest.raises(ValueError) as e:
        ljpeg.decode(input_file)
        err_msg = e.value.args[0]
        assert err_msg == expected
예제 #6
0
def test_decode_success(good_example_numpy_lossless_photo_w_decoded):
    # GIVEN a good lossless jpg that's been unpacked into a 1D numpy array of type intc
    # and what should result from decoding the jpg
    input_file, expected_array = good_example_numpy_lossless_photo_w_decoded

    # WHEN the supplied file is decoded
    test_file = ljpeg.decode(input_file)

    # THEN the test_file should math the expected_array
    assert np.array_equal(expected_array, test_file)
예제 #7
0
def test_encode_success(rgb_numpy_photo):
    # GIVEN a decoded photo in a 3D numpy array with a precision of 8

    # WHEN encode is run twice to ensure that everyting's reinitialized properly
    # and then decoded
    ljpeg.encode(rgb_numpy_photo, 8, 5)
    actual = np.asarray(ljpeg.encode(rgb_numpy_photo, 8, 5)).astype(np.intc)
    actual = ljpeg.decode(actual)

    # THEN the decoded image is the same as the input data
    assert np.array_equal(rgb_numpy_photo, actual)