@@ -46,9 +46,9 @@ class MockThumbFormat(Enum):
4646 mock .ThumbFormat = MockThumbFormat
4747 sys .modules ['rawpy' ] = mock
4848 yield mock
49- # Clean up
50- if 'rawpy' in sys . modules :
51- del sys .modules ['rawpy' ]
49+ # Remove all rawpy submodules so real rawpy can re-import cleanly in later tests
50+ for key in [ k for k in sys . modules if k == 'rawpy' or k . startswith ( 'rawpy.' )] :
51+ del sys .modules [key ]
5252
5353
5454def _setup_rawpy_mock (mock_rawpy , thumb_data , thumb_format_enum ):
@@ -122,6 +122,25 @@ def test_open_raw_image_imread_error(mock_rawpy):
122122 _open_raw_image (Path ('test.ORF' ))
123123
124124
125+ def test_open_raw_image_no_thumbnail (mock_rawpy ):
126+ """Test that LibRawNoThumbnailError is converted to a friendly ValueError"""
127+
128+ # Define a real exception class so it can be raised as a side_effect
129+ class FakeLibRawNoThumbnailError (Exception ):
130+ pass
131+
132+ mock_rawpy .LibRawNoThumbnailError = FakeLibRawNoThumbnailError
133+
134+ mock_raw = MagicMock ()
135+ mock_raw .__enter__ = MagicMock (return_value = mock_raw )
136+ mock_raw .__exit__ = MagicMock (return_value = False )
137+ mock_raw .extract_thumb .side_effect = FakeLibRawNoThumbnailError
138+ mock_rawpy .imread .return_value = mock_raw
139+
140+ with pytest .raises (ValueError , match = 'No embedded thumbnail found in RAW file' ):
141+ _open_raw_image (Path ('test.ORF' ))
142+
143+
125144def test_open_raw_image_unsupported_format (mock_rawpy ):
126145 """Test that an unsupported ThumbFormat enum value raises ValueError"""
127146 _setup_rawpy_mock (mock_rawpy , b'' , mock_rawpy .ThumbFormat .UNKNOWN )
@@ -158,7 +177,6 @@ def test_generate_thumbnail__mock_raw(sample_image, mock_rawpy):
158177 mock_rawpy .imread .assert_called_once_with (str (raw_path ))
159178
160179
161- @pytest .mark .integration
162180@pytest .mark .parametrize ('raw_path' , SAMPLE_RAW_FILES )
163181def test_generate_thumbnail__real_raw (raw_path ):
164182 """RAW file -> rawpy extraction -> PIL -> Qt QImage"""
0 commit comments