@@ -97,3 +97,56 @@ def write_urls(self, chapter):
9797 "workId" : "work-1" ,
9898 }
9999 ]
100+
101+
102+ def test_cli_raises_clear_error_when_pages_missing (monkeypatch , tmp_path ):
103+ input_file = tmp_path / "book.pdf"
104+ output_folder = tmp_path / "output"
105+ input_file .write_bytes (b"%PDF-1.4\n " )
106+ output_folder .mkdir ()
107+
108+ class MockPdf :
109+ def __init__ (self , source , tmp_dir ):
110+ self .tmp_dir = Path (tmp_dir )
111+
112+ def merge_pdfs (self , page_range , output_file_name ):
113+ raise AssertionError ("merge_pdfs should not be called" )
114+
115+ class MockMetadata :
116+ def __init__ (self , database , doi ):
117+ pass
118+
119+ def get_chapters (self ):
120+ return [
121+ {
122+ "pages" : None ,
123+ "doi" : "10.11647/obp.0309.01" ,
124+ "workId" : "work-1" ,
125+ }
126+ ]
127+
128+ def write_metadata (self , chapter , output_file_path ):
129+ raise AssertionError ("write_metadata should not be called" )
130+
131+ def write_urls (self , chapter ):
132+ raise AssertionError ("write_urls should not be called" )
133+
134+ monkeypatch .setattr (main , "Pdf" , MockPdf )
135+ monkeypatch .setattr (main , "Metadata" , MockMetadata )
136+
137+ result = runner .invoke (
138+ main .app ,
139+ [
140+ "--input-file" ,
141+ str (input_file ),
142+ "--output-folder" ,
143+ str (output_folder ),
144+ "10.11647/obp.0309" ,
145+ ],
146+ )
147+
148+ assert result .exit_code != 0
149+ assert isinstance (result .exception , ValueError )
150+ assert str (result .exception ) == (
151+ "Missing page range for chapter 10.11647/obp.0309.01"
152+ )
0 commit comments