96 lines
6.1 KiB
Python
96 lines
6.1 KiB
Python
import base64
|
|
import copy
|
|
import gzip
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
from paper_atlas.collectors import icassp2026 as c
|
|
|
|
|
|
class ICASSP2026Test(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.fixture = json.loads(gzip.decompress((Path(__file__).parent/'fixtures/icassp2026-source.json.gz').read_bytes()))
|
|
cls.files = {name: base64.b64decode(body) for name, body in cls.fixture['files'].items()}
|
|
cls.items = []
|
|
cls.manifest = json.loads(cls.files[c.SNAPSHOT+'/manifest.json'])
|
|
for receipt in cls.manifest['pages']:
|
|
cls.items.extend((r, receipt) for r in json.loads(cls.files[c.SNAPSHOT+'/'+receipt['file']])['message']['items'])
|
|
|
|
def materialize(self, root):
|
|
for name, body in self.files.items():
|
|
path = root/name; path.parent.mkdir(parents=True, exist_ok=True); path.write_bytes(body)
|
|
|
|
def test_full_census_matches_independent_gold_and_preserves_source(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); src = root/'src'; self.materialize(src)
|
|
report = c.collect(root/'out', snapshots=src)
|
|
self.assertEqual((report['records'],report['missing_abstract_count'],report['single_name_author_fields']), (4582,4582,23))
|
|
self.assertEqual(len(report['excluded_nonpaper_items']),7); self.assertEqual(len(report['excluded_other_conference_dois']),56)
|
|
self.assertFalse(report['database_written']); self.assertFalse(report['pdfs_downloaded']); self.assertEqual(report['network_requests'],0)
|
|
self.assertEqual(report['approved_for_import'],0); self.assertEqual(report['public_rejected_availability'],'unknown')
|
|
manifest, = report['files']; path = Path(manifest['file']); raw = path.read_bytes()
|
|
self.assertEqual(hashlib.sha256(raw).hexdigest(),manifest['file_sha256']); self.assertEqual(manifest['status'],'partial')
|
|
rows = [json.loads(l) for l in raw.splitlines()]
|
|
actual = [{'doi':r['external_id'],'title':r['title'],'authors':r['authors']} for r in rows]
|
|
gold = sorted(self.fixture['independent_gold'],key=lambda r:r['doi'])
|
|
self.assertEqual(actual,gold)
|
|
original = {r['DOI']:r for r,_ in self.items}
|
|
evidence_hashes = {str(p.relative_to(root/'out')):hashlib.sha256(p.read_bytes()).hexdigest() for p in (root/'out/evidence').iterdir()}
|
|
for r in rows:
|
|
doi = r['external_id']; self.assertEqual(r['metadata']['registry_fields'],original[doi])
|
|
self.assertEqual(r['identifiers'],{'doi':doi}); self.assertEqual(r['submission_identifiers'],[{'scheme':'publication_doi','value':doi}])
|
|
self.assertEqual(r['track'],'proceedings_unclassified'); self.assertFalse(r['tags']); self.assertFalse(r['abstract'])
|
|
self.assertFalse(r['metadata']['original_decision_signature_verified'])
|
|
evidence = r['metadata']['source_evidence']
|
|
self.assertEqual(evidence_hashes[evidence['file']],evidence['sha256'])
|
|
self.assertIn('Fareedha',next(r for r in rows if r['external_id'].endswith('.11461474'))['authors'])
|
|
with self.assertRaisesRegex(ValueError,'Output exists'):
|
|
c.collect(root/'out',snapshots=src)
|
|
|
|
def test_wrong_conference_doi_date_and_unexpected_abstract_rejected(self):
|
|
for kind in ('container','event','doi','date','author','sequence','abstract'):
|
|
with self.subTest(kind=kind):
|
|
items = copy.deepcopy(self.items); r = next(r for r,_ in items if r.get('author') and r['DOI'].startswith(c.PREFIX))
|
|
if kind=='container': r['container-title']=['Foreign']
|
|
if kind=='event': r['event']['name']='Other'
|
|
if kind=='doi': r['DOI']='10.1109/foreign.2026.1'
|
|
if kind=='date': r['published']['date-parts']=[[2025,5,3]]
|
|
if kind=='author': r['author']=[]
|
|
if kind=='sequence': r['author'][0]['sequence']='additional'
|
|
if kind=='abstract': r['abstract']='new source version'
|
|
with self.assertRaises(ValueError): c.registry_papers(items)
|
|
|
|
def test_nonpaper_exclusion_requires_exact_reviewed_evidence(self):
|
|
for kind in ('title','page','author'):
|
|
items = copy.deepcopy(self.items); r = next(r for r,_ in items if r['DOI'] in c.NONPAPERS)
|
|
if kind=='title': r['title']=['A research paper']
|
|
if kind=='page': r['page']='1-5'
|
|
if kind=='author': r['author']=[{'family':'Smith'}]
|
|
with self.assertRaisesRegex(ValueError,'nonpaper'): c.registry_papers(items)
|
|
|
|
def test_duplicate_and_incomplete_census_rejected(self):
|
|
with self.assertRaisesRegex(ValueError,'repeated'): c.registry_papers(self.items+[self.items[0]])
|
|
with self.assertRaisesRegex(ValueError,'partition'): c.registry_papers(self.items[:-1])
|
|
|
|
def test_corruption_and_partial_input_preserve_failure_without_success(self):
|
|
for kind in ('manifest','body','missing'):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp); src=root/'src'; self.materialize(src)
|
|
path=src/c.SNAPSHOT/('manifest.json' if kind=='manifest' else 'page-002.json')
|
|
if kind=='missing': path.unlink()
|
|
else: path.write_bytes(path.read_bytes()+b' ')
|
|
with self.assertRaises((ValueError,FileNotFoundError)): c.collect(root/'out',snapshots=src)
|
|
self.assertTrue((root/'out/failed.json').exists()); self.assertFalse((root/'out/collection-report.json').exists())
|
|
|
|
def test_symlink_page_and_snapshot_rejected(self):
|
|
for kind in ('page','directory'):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp); src=root/'src'; self.materialize(src)
|
|
path=src/c.SNAPSHOT/('page-001.json' if kind=='page' else '')
|
|
renamed=path.with_name(path.name+'-original'); path.rename(renamed); path.symlink_to(renamed,target_is_directory=kind=='directory')
|
|
with self.assertRaisesRegex(ValueError,'Unsafe'): c.collect(root/'out',snapshots=src)
|