Coverage for test / pubmed_process_test.py: 99%

148 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-09-09 15:50 +0000

1# SPDX-FileCopyrightText: 2023-2024 Arianna Moretti <arianna.moretti4@unibo.it> 

2# SPDX-FileCopyrightText: 2023-2026 Arcangelo Massari <arcangelo.massari@unibo.it> 

3# SPDX-FileCopyrightText: 2026 Marta Soricetti <marta.soricetti@unibo.it> 

4# 

5# SPDX-License-Identifier: ISC 

6 

7 

8import os.path 

9import shutil 

10import tempfile 

11import unittest 

12from os.path import join 

13 

14from oc_ds_converter.run.pubmed_process import ( 

15 assign_chunks, 

16 find_missing_chuncks, 

17 new_chunks_distribution, 

18 preprocess, 

19) 

20 

21 

22class PubMedProcess(unittest.TestCase): 

23 maxDiff = None 

24 def setUp(self): 

25 self.test_dir = join("test", "pubmed_process") 

26 self.output_dir = join(self.test_dir, "tmp") 

27 self.support_mat = join(self.test_dir, "support_mat") 

28 self.doi_orcid = join("test", "pubmed_processing", "iod") 

29 

30 self.publishers_file = join(self.support_mat, "publishers.json") 

31 self.journals_file = join(self.support_mat, "journals.json") 

32 

33 self.publishers_dir_todel = join(self.support_mat, "publishers") 

34 self.publishers_file_todel = join(self.publishers_dir_todel, "publishers.json") 

35 

36 self.journals_dir_todel = join(self.support_mat, "journals") 

37 self.journals_file_todel = join(self.journals_dir_todel, "journals.json") 

38 

39 self.madeup_data_dir = join(self.support_mat, "made_up_mat") 

40 self.madeup_publishers = join(self.madeup_data_dir, "publishers.json") 

41 self.madeup_journals = join(self.madeup_data_dir,"journals.json") 

42 self.madeup_input = join(self.madeup_data_dir,"input") 

43 self.madeup_iod = join(self.madeup_data_dir,"iod") 

44 

45 self.input_dirt_short= join(self.test_dir,"csv_files_short") 

46 self.input_dirt_iod= join(self.test_dir,"csv_file_iod") 

47 self.input_dirt_sample= join(self.test_dir,"csv_files_sample") 

48 self.input_dirt_compr= join(self.test_dir,"CSV_iCiteMD_zipped.zip") 

49 

50 self.processing_csv_row_base = os.path.join('test', 'pubmed_processing') 

51 self._id_orcid_data = os.path.join(self.processing_csv_row_base, 'iod') 

52 

53 self.cache1 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache1.json') 

54 self.cache2 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache2.json') 

55 self.cache3 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache3.json') 

56 self.cache4 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache4.json') 

57 self.cache5 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache5.json') 

58 self.cache6 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache6.json') 

59 self.cache7 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache7.json') 

60 self.cache8 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache8.json') 

61 self.cache9 = os.path.join('test', 'pubmed_process', 'support_mat', 'cache9.json') 

62 

63 def test_find_missing_chuncks(self): 

64 

65 output = find_missing_chuncks([(7,13)], 7) 

66 expected = ([(0, 6)], 14) 

67 

68 self.assertEqual(output, expected) 

69 

70 output = find_missing_chuncks([], 5) 

71 expected = ([], 0) 

72 

73 self.assertEqual(output, expected) 

74 

75 output = find_missing_chuncks([(0,6), (7,13)], 6) 

76 expected = (None) 

77 

78 self.assertEqual(output, expected) 

79 

80 output = find_missing_chuncks([(0,6), (7,13)], 7) 

81 expected = ([], 14) 

82 

83 self.assertEqual(output, expected) 

84 

85 output = find_missing_chuncks([(0,6), (14,20)], 7) 

86 expected = ([(7,13)], 21) 

87 

88 self.assertEqual(output, expected) 

89 

90 output = find_missing_chuncks([(0,6), (21,27)], 7) 

91 expected = ([(7,13), (14, 20)], 28) 

92 

93 self.assertTrue(all(x in output[0] for x in expected[0])) 

94 self.assertTrue(all(x in expected[0] for x in output[0])) 

95 self.assertEqual(output[1], expected[1]) 

96 

97 def test_new_chunks_distribution(self): 

98 n_spare_processes = 5 

99 first_row_to_be_processed = 0 

100 interval = 10 

101 n_total_rows = 50 

102 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

103 expected = [(0, 9), (10, 19), (20, 29), (30, 39), (40, 49) ] 

104 self.assertEqual(result, expected) 

105 

106 n_spare_processes = 6 

107 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

108 expected = [(0, 9), (10, 19), (20, 29), (30, 39), (40, 49)] 

109 self.assertEqual(result, expected) 

110 

111 first_row_to_be_processed = 5 

112 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

113 expected = [(5, 14), (15, 24), (25, 34), (35, 44), (45, 49)] 

114 self.assertEqual(result, expected) 

115 

116 first_row_to_be_processed = 6 

117 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

118 expected = [(6, 15), (16, 25), (26, 35), (36, 45), (46, 49)] 

119 self.assertEqual(result, expected) 

120 

121 first_row_to_be_processed = 6 

122 n_spare_processes = 1 

123 interval = 3 

124 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

125 expected = [(6, 8)] 

126 self.assertEqual(result, expected) 

127 

128 n_spare_processes = 3 

129 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

130 expected = [(6, 8), (9,11), (12,14)] 

131 self.assertEqual(result, expected) 

132 

133 n_total_rows = 0 

134 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

135 expected = [] 

136 self.assertEqual(result, expected) 

137 

138 n_total_rows = 7 

139 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

140 expected = [(6, 6)] 

141 self.assertEqual(result, expected) 

142 

143 n_total_rows = 6 

144 result = new_chunks_distribution(n_spare_processes, first_row_to_be_processed, interval, n_total_rows) 

145 expected = [] 

146 self.assertEqual(result, expected) 

147 

148 def test_assign_chunks(self): 

149 

150 # CASO 0 : inizio del processo, nessuna iterazione è stata iniziata. 

151 n_processes = 5 

152 interval = 7 

153 n_total_rows = 28 

154 

155 expected = ([(0, 6), (7, 13), (14, 20), (21, 27)], True) 

156 result = assign_chunks(n_processes, interval, n_total_rows, self.cache1, lock=None) 

157 self.assertEqual(result, expected) 

158 

159 # CASO 1: risulta iniziata la seconda iterazione ma non la prima: comportamento anomalo, return None 

160 

161 expected = None 

162 result = assign_chunks(n_processes, interval, n_total_rows, self.cache2, lock=None) 

163 self.assertEqual(result, expected) 

164 

165 # CASO 2: Seconda iterazione iniziata 

166 # CASO 2.1: Seconda iterazione iniziata, nessun chunk saltato 

167 expected = ([(7, 13), (14, 20), (21, 27)], False) 

168 result = assign_chunks(n_processes, interval, n_total_rows, self.cache3, lock=None) 

169 self.assertEqual(result, expected) 

170 

171 # CASO 2.1.1 Seconda iterazione iniziata, nessun chunk saltato, non ci sono più row da processare 

172 expected = ([], False) 

173 result = assign_chunks(n_processes, interval, n_total_rows, self.cache5, lock=None) 

174 self.assertEqual(result, expected) 

175 

176 # CASO 2.1.2 Seconda iterazione iniziata, nessun chunk saltato, ci sono altre row da processare 

177 expected = ([(14, 20), (21, 27)], False) 

178 result = assign_chunks(n_processes, interval, n_total_rows, self.cache6, lock=None) 

179 self.assertEqual(result, expected) 

180 

181 # CASO 2.2: Seconda iterazione iniziata, con chunk saltati 

182 expected = ([(0, 6), (14, 20), (21, 27)], False) 

183 result = assign_chunks(n_processes, interval, n_total_rows, self.cache4, lock=None) 

184 self.assertEqual(result, expected) 

185 

186 

187 # CASO 3: Prima iterazione iniziata 

188 # CASO 3.1: Prima iterazione iniziata, nessun chunk saltato 

189 # CASO 3.1.1 Prima iterazione iniziata, nessun chunk saltato, non ci sono più row da processare 

190 expected = ([], True) 

191 result = assign_chunks(n_processes, interval, n_total_rows, self.cache8, lock=None) 

192 self.assertEqual(result, expected) 

193 

194 # CASO 3.1.2 Prima iterazione iniziata, nessun chunk saltato, ci sono altre row da processare 

195 expected = ([(14, 20), (21, 27)], True) 

196 result = assign_chunks(n_processes, interval, n_total_rows, self.cache7, lock=None) 

197 self.assertEqual(result, expected) 

198 

199 # CASO 3.2: Prima iterazione iniziata, con chunk saltati 

200 expected = ([(0, 6), (21, 27)], True) 

201 result = assign_chunks(n_processes, interval, n_total_rows, self.cache9, lock=None) 

202 self.assertEqual(result, expected) 

203 

204 def test_preprocess_creates_entities(self): 

205 """Test that preprocess produces entity CSV files for META from the short input.""" 

206 with tempfile.TemporaryDirectory() as tmpdir: 

207 out_dir = os.path.join(tmpdir, "out") 

208 cache_path = os.path.join(tmpdir, "test_cache.json") 

209 

210 preprocess( 

211 pubmed_csv_dir=self.input_dirt_short, 

212 publishers_filepath=self.publishers_file, 

213 journals_filepath=self.journals_file, 

214 csv_dir=out_dir, 

215 orcid_doi_filepath=self.doi_orcid, 

216 interval=5, 

217 testing=True, 

218 cache=cache_path, 

219 max_workers=1, 

220 ) 

221 

222 entity_files = [f for f in os.listdir(out_dir) if f.endswith('.csv')] 

223 self.assertGreater(len(entity_files), 0, "Expected at least one entity CSV output file") 

224 

225 total_entities = 0 

226 for fname in entity_files: 

227 with open(os.path.join(out_dir, fname), 'r', encoding='utf-8') as f: 

228 total_entities += sum(1 for _ in f) - 1 

229 self.assertGreater(total_entities, 0, "Expected at least one processed entity row") 

230 

231 self.assertFalse( 

232 os.path.exists(out_dir + "_citations"), 

233 "No citations directory should be created for PubMed" 

234 ) 

235 

236 # def test_preprocess_base(self): 

237 # """Test base functionalities of the POCI processor for producing META csv tables. 

238 # NOTE: output files are now named {input_basename}_{chunk_num}.csv instead of CSVFile_N.csv. 

239 # The assertion uses assertCountEqual on content (not on filenames), so it is compatible as-is. 

240 # Requires real NIH/CrossRef API access — not suitable for CI. 

241 # """ 

242 # if os.path.exists(self.output_dir): 

243 # shutil.rmtree(self.output_dir) 

244 # preprocess(pubmed_csv_dir=self.input_dirt_sample, publishers_filepath=self.publishers_file, journals_filepath= self.journals_file, csv_dir=self.output_dir, orcid_doi_filepath=self.doi_orcid) 

245 # 

246 # output = dict() 

247 # for file in os.listdir(self.output_dir): 

248 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

249 # output[file] = list(csv.DictReader(f)) 

250 # expected_output= { 

251 # 'CSVFile_1.csv': # filename key is not checked — only values are used in assertCountEqual below 

252 # [ 

253 # {'id': 'pmid:118', 

254 # 'title': 'Proceedings: Comparison of the effects of selective alpha and beta-receptor agonists on intracellular cyclic AMP levels and glycogen phosphorylase activity in guinea-pig liver.', 

255 # 'author': 'D Osborn; D H Jenkinson', 

256 # 'pub_date': '1975', 

257 # 'venue': 'British journal of pharmacology [issn:0007-1188]', 

258 # 'volume': '', 

259 # 'issue': '', 

260 # 'page': '', 

261 # 'type': 'journal article', 

262 # 'publisher': '', 

263 # 'editor': ''}, 

264 # {'id': 'pmid:120', 

265 # 'title': 'Proceedings: Do anti-psychotic drugs act by dopamine receptor blockade in the nucleus accumbens.', 

266 # 'author': 'T J Crow; J F Deakin; A Longden', 

267 # 'pub_date': '1975', 

268 # 'venue': 'British journal of pharmacology [issn:0007-1188]', 

269 # 'volume': '', 

270 # 'issue': '', 

271 # 'page': '', 

272 # 'type': 'journal article', 

273 # 'publisher': '', 

274 # 'editor': ''}, 

275 # {'id': 'pmid:351 doi:10.2527/jas1975.4151249x', 

276 # 'title': 'Analyses of rumen fluid from "sudden death", lactic acidotic and healthy cattle fed high concentrate ration.', 

277 # 'author': 'J R Wilson; E E Bartley; H D Anthony; B E Brent; D A Sapienza; T E Chapman; A D Dayton; R J Milleret; R A Frey; R M Meyer', 

278 # 'pub_date': '1975', 

279 # 'venue': 'Journal of animal science [issn:0021-8812]', 

280 # 'volume': '', 

281 # 'issue': '', 

282 # 'page': '', 

283 # 'type': 'journal article', 

284 # 'publisher': 'American Society of Animal Science (ASAS)', 

285 # 'editor': ''}, 

286 # {'id': 'pmid:352 doi:10.2527/jas1975.4151314x', 

287 # 'title': 'Mitochondrial traits of muscle from stress-susceptible pigs.', 

288 # 'author': 'D R Campion; J C Olson; D G Topel; L L Christian; D L Kuhlers', 

289 # 'pub_date': '1975', 

290 # 'venue': 'Journal of animal science [issn:0021-8812]', 

291 # 'volume': '', 

292 # 'issue': '', 

293 # 'page': '', 

294 # 'type': 'journal article', 

295 # 'publisher': 'American Society of Animal Science (ASAS)', 

296 # 'editor': ''}, 

297 # {'id': 'pmid:353 doi:10.1152/jappl.1975.39.4.580', 

298 # 'title': 'Local control of pulmonary resistance and lung compliance in the canine lung.', 

299 # 'author': 'R L Coon; C C Rattenborg; J P Kampine', 

300 # 'pub_date': '1975', 

301 # 'venue': 'Journal of applied physiology [issn:0021-8987]', 

302 # 'volume': '', 

303 # 'issue': '', 

304 # 'page': '', 

305 # 'type': 'journal article', 

306 # 'publisher': 'American Physiological Society', 

307 # 'editor': ''} 

308 # ] 

309 # } 

310 # 

311 # elements_in_output = list() 

312 # for l in output.values(): 

313 # for e in l: 

314 # elements_in_output.append(e) 

315 # 

316 # elements_expected = list() 

317 # for l in expected_output.values(): 

318 # for e in l: 

319 # elements_expected.append(e) 

320 # 

321 # self.assertCountEqual(elements_in_output, elements_expected) 

322 # shutil.rmtree(self.output_dir) 

323 

324 # def test_preprocess_interval_number(self): 

325 # """Test that the processed rows are correctly distributed in output files. 

326 # NOTE: interval now controls ROW RANGE per chunk, not entity count per file. 

327 # The old test expected exactly N entities per file (entity-count batching). 

328 # In the new design, each file contains entities from up to <interval> rows, 

329 # which may be fewer than <interval> entities if some rows are filtered out 

330 # (no references or cited_by). Assertions on exact entity counts per file 

331 # need to be revised to assert on total entity count and total file count instead. 

332 # Requires real NIH/CrossRef API access — not suitable for CI. 

333 # """ 

334 # 

335 # if os.path.exists(self.output_dir): 

336 # shutil.rmtree(self.output_dir) 

337 # preprocess(pubmed_csv_dir=self.input_dirt_sample, publishers_filepath=self.publishers_file, journals_filepath= self.journals_file, csv_dir=self.output_dir, orcid_doi_filepath=self.doi_orcid, interval=2) 

338 # 

339 # output = dict() 

340 # n_files = 0 

341 # for file in os.listdir(self.output_dir): 

342 # n_files += 1 

343 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

344 # output[n_files] = len(list(csv.DictReader(f))) 

345 # 

346 # # UPDATE NEEDED: assertions below assumed entity-count batching (old behaviour). 

347 # # With row-range batching, replace with: total entities == 5, files <= ceil(n_rows/interval) 

348 # expected_files = 3 

349 # expected_ents_per_file = 2 

350 # last_file_ents = 1 

351 # n_files_full = len([x for x in output.values() if x == 2]) 

352 # n_files_rem= len([x for x in output.values() if x == 1]) 

353 # self.assertEqual(expected_files, len(output.keys())) 

354 # self.assertEqual(n_files_full, 2) 

355 # self.assertEqual(n_files_rem, 1) 

356 # self.assertTrue(max(output.values())==expected_ents_per_file) 

357 # self.assertTrue(min(output.values())==last_file_ents) 

358 # shutil.rmtree(self.output_dir) 

359 # 

360 # def test_preprocess_save_recovered_publishers(self): 

361 # """Test that data is correctly recovered using API and stored in new support file, if no support material was provided in input""" 

362 # if not os.path.exists(self.publishers_dir_todel): 

363 # os.makedirs(self.publishers_dir_todel) 

364 # if os.path.exists(self.output_dir): 

365 # shutil.rmtree(self.output_dir) 

366 # preprocess(pubmed_csv_dir=self.input_dirt_sample, publishers_filepath=self.publishers_file_todel, journals_filepath= self.journals_file, csv_dir=self.output_dir, orcid_doi_filepath=self.doi_orcid, interval=1) 

367 # #test that the information processed was successfully saved each <interval> number of rows. 

368 # prefixes_encountered = set() 

369 # self.assertTrue(os.path.exists(self.publishers_file_todel)) 

370 # for file in os.listdir(self.output_dir): 

371 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

372 # ent_list = list(csv.DictReader(f)) 

373 # for e in ent_list: 

374 # if e.get("id"): 

375 # doi = [x for x in e.get("id").split(" ") if x.startswith("doi")] 

376 # if doi: 

377 # for d in doi: 

378 # pref = d.split('/')[0] 

379 # if pref: 

380 # lenpref = len("doi:") 

381 # pref = pref[lenpref:] 

382 # prefixes_encountered.add(pref) 

383 # 

384 # with open(self.publishers_file_todel, "r") as dobj: 

385 # pref_pub_dict = json.load(dobj) 

386 # self.assertCountEqual(prefixes_encountered, pref_pub_dict.keys()) 

387 # 

388 # shutil.rmtree(self.output_dir) 

389 # shutil.rmtree(self.publishers_dir_todel) 

390 # 

391 # def test_preprocess_zip_input(self): 

392 # """Test that the processed on zip compressed input""" 

393 # 

394 # if os.path.exists(self.output_dir): 

395 # shutil.rmtree(self.output_dir) 

396 # preprocess(pubmed_csv_dir=self.input_dirt_compr, publishers_filepath=self.publishers_file, journals_filepath= self.journals_file, csv_dir=self.output_dir, orcid_doi_filepath=self.doi_orcid, interval=200) 

397 # 

398 # output = dict() 

399 # for file in os.listdir(self.output_dir): 

400 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

401 # output[file] = list(csv.DictReader(f)) 

402 # processed_lines = 0 

403 # for k,v in output.items(): 

404 # processed_lines += len(v) 

405 # self.assertEqual(processed_lines, 29) 

406 # 

407 # todel_path = ".".join(self.input_dirt_compr.split(".")[:-1])+"_decompr_zip_dir" 

408 # shutil.rmtree(todel_path) 

409 # shutil.rmtree(self.output_dir) 

410 # 

411 # 

412 # def test_preprocess_save_recovered_journals(self): 

413 # """Test that data is correctly recovered using API and stored in new support file, if no support material was provided in input""" 

414 # if not os.path.exists(self.journals_dir_todel): 

415 # os.makedirs(self.journals_dir_todel) 

416 # if os.path.exists(self.output_dir): 

417 # shutil.rmtree(self.output_dir) 

418 # preprocess(pubmed_csv_dir=self.input_dirt_sample, publishers_filepath=self.publishers_file, journals_filepath= self.journals_file_todel, csv_dir=self.output_dir, orcid_doi_filepath=self.doi_orcid, interval=1) 

419 # #test that the information processed was successfully saved at each <interval> number of rows. 

420 # issns_encountered = set() 

421 # self.assertTrue(os.path.exists(self.journals_file_todel)) 

422 # 

423 # for file in os.listdir(self.output_dir): 

424 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

425 # ent_list = list(csv.DictReader(f)) 

426 # for e in ent_list: 

427 # if e.get("venue"): 

428 # if "[" in e.get("venue") and "]" in e.get("venue"): 

429 # split_venue_ids = e.get("venue").split("[") 

430 # keep_ids=split_venue_ids[1] 

431 # keep_ids = keep_ids.split("]")[0] 

432 # split_issn = keep_ids.split(" ") 

433 # issn = [x for x in split_issn if x.startswith("issn")] 

434 # if issn: 

435 # for i in issn: 

436 # issns_encountered.add(i) 

437 # 

438 # with open(self.journals_file_todel, "r") as dobj: 

439 # jour_issns_dict = json.load(dobj) 

440 # issn_in_map_file = set() 

441 # for k,v in jour_issns_dict.items(): 

442 # for e in v["issn"]: 

443 # issn_in_map_file.add(e) 

444 # 

445 # self.assertCountEqual(issns_encountered, issn_in_map_file) 

446 # 

447 # shutil.rmtree(self.output_dir) 

448 # shutil.rmtree(self.journals_dir_todel) 

449 # 

450 # def test_preprocess_support_data(self): 

451 # """Test that the support material is correctly used, if provided. In particular, fake data is used in this test, in order to check that the information provided in support material is preferred to the use of API, when possible""" 

452 # if os.path.exists(self.output_dir): 

453 # shutil.rmtree(self.output_dir) 

454 # preprocess(pubmed_csv_dir=self.input_dirt_short, publishers_filepath=self.madeup_publishers, journals_filepath= self.madeup_journals, csv_dir=self.output_dir, orcid_doi_filepath=self.doi_orcid, interval=1) 

455 # #test that the information processed was successfully saved after each <interval> number of rows. 

456 # for file in os.listdir(self.output_dir): 

457 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

458 # ent_list = list(csv.DictReader(f)) 

459 # for e in ent_list: 

460 # if "pmid:1" in e.get("id").split(" ") and "doi:10.1016/0006-2944(75)90147-7" in e.get("id").split(" "): 

461 # self.assertEqual(e.get("venue"), "Made Up Title 1 [issn:0001-000X]") 

462 # self.assertEqual(e.get("publisher"), "Made Up Publisher") 

463 # if "pmid:324" in e.get("id").split(" ") and "doi:10.1016/0019-2791(75)90174-3" in e.get("id").split(" "): 

464 # self.assertEqual(e.get("venue"), "Made Up Title 2 [issn:0000-0000]") 

465 # self.assertEqual(e.get("publisher"), "Made Up Publisher") 

466 # 

467 # 

468 # shutil.rmtree(self.output_dir) 

469 # 

470 # def test_preprocess_id_orcid_map(self): 

471 # """Test the id-orcid mapping information is correctly used to associate the RA name to its ORCID id, if provided. """ 

472 # if os.path.exists(self.output_dir): 

473 # shutil.rmtree(self.output_dir) 

474 # preprocess(pubmed_csv_dir=self.input_dirt_iod, publishers_filepath=self.publishers_file, journals_filepath= self.journals_file, csv_dir=self.output_dir, orcid_doi_filepath=self.doi_orcid, interval=1) 

475 # #test that the information processed was successfully saved each <interval> number of rows. 

476 # for file in os.listdir(self.output_dir): 

477 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

478 # ent_list = list(csv.DictReader(f)) 

479 # for e in ent_list: 

480 # if e.get("id") == "pmid:2 doi:10.1016/0006-291x(75)90482-9": 

481 # self.assertIn("Sarma, R H [orcid:0000-0000-0000-0000]", e.get("author")) 

482 # shutil.rmtree(self.output_dir) 

483 # 

484 # def test_preprocess_id_orcid_map_with_homonyms(self): 

485 # """Test the id-orcid mapping information is correctly used to associate the RA name to its ORCID id, if provided. """ 

486 # 

487 # if os.path.exists(self.output_dir): 

488 # shutil.rmtree(self.output_dir) 

489 # preprocess(pubmed_csv_dir=self.madeup_input, publishers_filepath=self.publishers_file, journals_filepath= self.journals_file, csv_dir=self.output_dir, orcid_doi_filepath=self.madeup_iod, interval=1) 

490 # #test that the information processed was successfully saved at each <interval> number of rows. 

491 # processed_ents = [] 

492 # for file in os.listdir(self.output_dir): 

493 # with open(os.path.join(self.output_dir, file), 'r', encoding='utf-8') as f: 

494 # ent_list = list(csv.DictReader(f)) 

495 # for e in ent_list: 

496 # processed_ents.append(e) 

497 # ent = processed_ents[0] 

498 # expected_aut_cont = "K S Bose; R H Sarma; Sarma, Harold R. [orcid:0000-0000-0000-0005]; Sarma R. Henry Jack; Sarma, Roy Henry [orcid:0000-0000-0000-0000]" 

499 # self.assertEqual(expected_aut_cont, ent.get("author")) 

500 # 

501 # shutil.rmtree(self.output_dir) 

502 

503if __name__ == '__main__': 

504 unittest.main()