File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import shutil
66import string
77import subprocess
8+ import sys
89from io import BytesIO
910from itertools import product as cartesian_product
1011from pathlib import Path
@@ -92,6 +93,20 @@ def test_brotli_missing_installation_mocked():
9293 decode_stream_data (stream )
9394 assert "Brotli library not installed" in str (exc_info_stream .value )
9495
96+ def test_brotli_import_handling ():
97+ """Verify the try-except block for brotli import in pypdf.filters."""
98+ # Simulate brotli import failure
99+ if "brotli" in sys .modules :
100+ del sys .modules ["brotli" ]
101+ with patch .dict (sys .modules , {"brotli" : None }):
102+ import pypdf .filters
103+ importlib .reload (pypdf .filters ) # Re-evaluate module-level try-except
104+ assert pypdf .filters .brotli is None , "brotli should be None when import fails"
105+
106+ # Test successful import if brotli is installed
107+ if importlib .util .find_spec ("brotli" ):
108+ importlib .reload (pypdf .filters ) # Re-evaluate with brotli available
109+ assert pypdf .filters .brotli is not None , "brotli should be imported when available"
95110
96111def test_flatedecode_unsupported_predictor ():
97112 """
You can’t perform that action at this time.
0 commit comments