@@ -32,6 +32,20 @@ def pdfs_processor(sample_property_keywords):
3232 property_keywords = sample_property_keywords ,
3333 is_sql_db = False ,
3434 csv_batch_size = 10 ,
35+ is_track_pdfs = False ,
36+ )
37+
38+
39+ @pytest .fixture
40+ def pdfs_processor_with_tracking (sample_property_keywords ):
41+ """Fixture with PDF tracking enabled for tracking-specific tests"""
42+ return PDFsProcessor (
43+ folder_path = "/test/path" ,
44+ main_property_keyword = "piezoelectric" ,
45+ property_keywords = sample_property_keywords ,
46+ is_sql_db = False ,
47+ csv_batch_size = 10 ,
48+ is_track_pdfs = True ,
3549 )
3650
3751
@@ -80,58 +94,58 @@ def test_init_custom_track_pdfs_report_path(sample_property_keywords):
8094 assert processor .track_pdfs_report_path == "/custom/tracking.txt"
8195
8296
83- def test_load_processed_pdfs_from_tracking_file (pdfs_processor ):
97+ def test_load_processed_pdfs_from_tracking_file (pdfs_processor_with_tracking ):
8498 """_load_processed_pdfs reads basename+DOI pairs from the tracking file"""
8599 tracking_content = "paper1.pdf\t 10.1234/a\n paper2.pdf\t 10.5678/b\n "
86100 with (
87101 patch ("os.path.exists" , return_value = True ),
88102 patch ("builtins.open" , mock_open (read_data = tracking_content )),
89103 ):
90- filenames , dois = pdfs_processor ._load_processed_pdfs ()
104+ filenames , dois = pdfs_processor_with_tracking ._load_processed_pdfs ()
91105 assert filenames == {"paper1.pdf" , "paper2.pdf" }
92106 assert dois == {"10.1234/a" , "10.5678/b" }
93107
94108
95- def test_load_processed_pdfs_legacy_doi_only_format (pdfs_processor ):
109+ def test_load_processed_pdfs_legacy_doi_only_format (pdfs_processor_with_tracking ):
96110 """_load_processed_pdfs handles legacy tracking files that contain only DOIs"""
97111 tracking_content = "10.1234/a\n 10.5678/b\n "
98112 with (
99113 patch ("os.path.exists" , return_value = True ),
100114 patch ("builtins.open" , mock_open (read_data = tracking_content )),
101115 ):
102- filenames , dois = pdfs_processor ._load_processed_pdfs ()
116+ filenames , dois = pdfs_processor_with_tracking ._load_processed_pdfs ()
103117 assert filenames == set ()
104118 assert dois == {"10.1234/a" , "10.5678/b" }
105119
106120
107- def test_load_processed_pdfs_fallback_to_csv (pdfs_processor ):
121+ def test_load_processed_pdfs_fallback_to_csv (pdfs_processor_with_tracking ):
108122 """_load_processed_pdfs falls back to the CSV when the tracking file is absent"""
109123 csv_data = pd .DataFrame ({"doi" : ["10.1234/a" , "10.9999/c" ]})
110124 with (
111125 patch ("os.path.exists" , side_effect = lambda p : p .endswith (".csv" )),
112126 patch ("pandas.read_csv" , return_value = csv_data ),
113127 ):
114- filenames , dois = pdfs_processor ._load_processed_pdfs ()
128+ filenames , dois = pdfs_processor_with_tracking ._load_processed_pdfs ()
115129 assert filenames == set ()
116130 assert dois == {"10.1234/a" , "10.9999/c" }
117131
118132
119- def test_load_processed_pdfs_no_sources (pdfs_processor ):
133+ def test_load_processed_pdfs_no_sources (pdfs_processor_with_tracking ):
120134 """_load_processed_pdfs returns empty sets when neither file exists"""
121135 with patch ("os.path.exists" , return_value = False ):
122- filenames , dois = pdfs_processor ._load_processed_pdfs ()
136+ filenames , dois = pdfs_processor_with_tracking ._load_processed_pdfs ()
123137 assert filenames == set ()
124138 assert dois == set ()
125139
126140
127- def test_mark_pdf_processed_writes_to_file (pdfs_processor ):
141+ def test_mark_pdf_processed_writes_to_file (pdfs_processor_with_tracking ):
128142 """_mark_pdf_processed appends basename<TAB>doi to the tracking file"""
129143 m = mock_open ()
130144 with (
131145 patch ("os.makedirs" ),
132146 patch ("builtins.open" , m ),
133147 ):
134- pdfs_processor ._mark_pdf_processed ("/some/path/paper1.pdf" , "10.1234/test" )
148+ pdfs_processor_with_tracking ._mark_pdf_processed ("/some/path/paper1.pdf" , "10.1234/test" )
135149 m ().write .assert_called_once_with ("paper1.pdf\t 10.1234/test\n " )
136150
137151
@@ -303,10 +317,11 @@ def test_process_pdfs_with_doi(mock_metadata, mock_glob, pdfs_processor):
303317
304318
305319@patch ("glob.glob" )
320+ @patch ("comproscanner.article_processors.pdfs_processor.get_doi_from_crossref" , return_value = "" )
306321@patch (
307322 "comproscanner.article_processors.pdfs_processor.get_paper_metadata_from_openalex"
308323)
309- def test_process_pdfs_no_doi (mock_metadata , mock_glob , pdfs_processor ):
324+ def test_process_pdfs_no_doi (mock_metadata , mock_crossref , mock_glob , pdfs_processor ):
310325 """Test processing PDFs with no DOI found"""
311326 mock_glob .return_value = ["/test/path/file1.pdf" ]
312327
0 commit comments