draft mcidas testing

This commit is contained in:
Deekshu Kare 2024-06-21 19:14:02 +02:00
parent 61107fc29d
commit d320f708ee

View File

@ -1,17 +1,24 @@
from __future__ import annotations
import pytest import pytest
from PIL import Image, McIdasImagePlugin from PIL import Image, McIdasImagePlugin
def test_open_invalid_file(): from .helper import assert_image_equal_tofile
# Arrange
def test_invalid_file() -> None:
invalid_file = "Tests/images/flower.jpg" invalid_file = "Tests/images/flower.jpg"
# Act & Assert
with pytest.raises(SyntaxError): with pytest.raises(SyntaxError):
McIdasImagePlugin.McIdasImageFile(invalid_file) McIdasImagePlugin.McIdasImageFile(invalid_file)
def test_open_supported_file():
def test_valid_file() -> None:
# Arrange # Arrange
# https://ghrc.nsstc.nasa.gov/hydro/details/cmx3g8
# https://ghrc.nsstc.nasa.gov/pub/fieldCampaigns/camex3/cmx3g8/browse/
test_file = "Tests/images/cmx3g8_wv_1998.260_0745_mcidas.ara" test_file = "Tests/images/cmx3g8_wv_1998.260_0745_mcidas.ara"
saved_file = "Tests/images/cmx3g8_wv_1998.260_0745_mcidas.tiff"
# Act # Act
with Image.open(test_file) as im: with Image.open(test_file) as im:
@ -21,37 +28,52 @@ def test_open_supported_file():
assert im.format == "MCIDAS" assert im.format == "MCIDAS"
assert im.mode == "I" assert im.mode == "I"
assert im.size == (1800, 400) assert im.size == (1800, 400)
assert_image_equal_tofile(im, saved_file)
def test_open_mode_L():
# Arrange
test_file = "Tests/images/mcidas_mode_L.ara"
# Act def test_open_invalid_file() -> None:
invalid_file = "Tests/images/drawing_wmf_ref_144.png"
with pytest.raises(SyntaxError):
McIdasImagePlugin.McIdasImageFile(invalid_file)
def test_open_8bit_file() -> None:
test_file = "Tests/images/8bit.s.tif"
with Image.open(test_file) as im: with Image.open(test_file) as im:
im.load() im.load()
# Assert
assert im.format == "MCIDAS" assert im.format == "MCIDAS"
assert im.mode == "L" assert im.mode == "L"
assert im.size == (100, 100) assert im.size == (800, 600)
def test_open_mode_I_32B():
# Arrange
test_file = "Tests/images/mcidas_mode_I_32B.ara"
# Act def test_open_16bit_file() -> None:
test_file = "Tests/images/16_bit_binary_pgm.tiff"
with Image.open(test_file) as im: with Image.open(test_file) as im:
im.load() im.load()
# Assert
assert im.format == "MCIDAS" assert im.format == "MCIDAS"
assert im.mode == "I" assert im.mode == "I"
assert im.size == (100, 100) assert im.size == (1024, 768)
def test_open_unsupported_format():
# Arrange
test_file = "Tests/images/mcidas_unsupported.ara"
# Act & Assert def test_open_32bit_file() -> None:
with pytest.raises(SyntaxError, match="unsupported McIdas format"): test_file = "Tests/images/10ct_32bit_128.tiff"
with Image.open(test_file) as im:
im.load()
assert im.format == "MCIDAS"
assert im.mode == "I"
assert im.size == (1280, 1024)
def test_open_unsupported_format() -> None:
test_file = "Tests/images/standard_embedded.png"
with pytest.raises(SyntaxError):
McIdasImagePlugin.McIdasImageFile(test_file) McIdasImagePlugin.McIdasImageFile(test_file)