From d320f708eeb69d35ff7faf8f7b11d49b55538cb6 Mon Sep 17 00:00:00 2001 From: Deekshu Kare Date: Fri, 21 Jun 2024 19:14:02 +0200 Subject: [PATCH] draft mcidas testing --- Tests/test_file_mcidas.py | 66 ++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/Tests/test_file_mcidas.py b/Tests/test_file_mcidas.py index 0381145a0..3a695a1c6 100644 --- a/Tests/test_file_mcidas.py +++ b/Tests/test_file_mcidas.py @@ -1,17 +1,24 @@ +from __future__ import annotations + import pytest + from PIL import Image, McIdasImagePlugin -def test_open_invalid_file(): - # Arrange +from .helper import assert_image_equal_tofile + +def test_invalid_file() -> None: invalid_file = "Tests/images/flower.jpg" - # Act & Assert with pytest.raises(SyntaxError): McIdasImagePlugin.McIdasImageFile(invalid_file) -def test_open_supported_file(): + +def test_valid_file() -> None: # 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" + saved_file = "Tests/images/cmx3g8_wv_1998.260_0745_mcidas.tiff" # Act with Image.open(test_file) as im: @@ -21,37 +28,52 @@ def test_open_supported_file(): assert im.format == "MCIDAS" assert im.mode == "I" 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: im.load() - # Assert assert im.format == "MCIDAS" 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: im.load() - # Assert assert im.format == "MCIDAS" 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 - with pytest.raises(SyntaxError, match="unsupported McIdas format"): - McIdasImagePlugin.McIdasImageFile(test_file) \ No newline at end of file +def test_open_32bit_file() -> None: + 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) +