97 lines
5.7 KiB
Python
97 lines
5.7 KiB
Python
import copy
|
|
import gzip
|
|
import json
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
from paper_atlas.collectors import icaps_registry2026 as c
|
|
|
|
|
|
class ICAPSRegistry2026Test(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.raw = gzip.decompress((Path(__file__).parent/'fixtures/icaps2026-crossref.json.gz').read_bytes())
|
|
cls.snapshot = json.loads(cls.raw)
|
|
|
|
def test_exact_edition_not_publication_year_alone(self):
|
|
papers, excluded = c.registry_papers(self.snapshot)
|
|
self.assertEqual(len(papers), 90); self.assertEqual(len(excluded), 1)
|
|
self.assertTrue(all(p['original']['volume'] == '36' for p in papers))
|
|
self.assertEqual(excluded, [r['DOI'] for r in self.snapshot['records'] if r['volume'] == '35'])
|
|
self.assertTrue(all(p['abstract'] and p['authors'] for p in papers))
|
|
|
|
def test_full_collection_keeps_registered_versions_and_publication_identity(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); src = root/'src'; src.mkdir(); (src/'crossref-filtered.json').write_bytes(self.raw)
|
|
report = c.collect(root/'out', snapshots=src)
|
|
self.assertEqual((report['records'], report['missing_abstract_count']), (90, 0))
|
|
self.assertFalse(report['database_written']); self.assertFalse(report['pdfs_downloaded'])
|
|
self.assertEqual(report['public_rejected_availability'], 'unknown')
|
|
manifest, = report['files']; self.assertEqual(manifest['status'], 'partial')
|
|
rows = [json.loads(l) for l in Path(manifest['file']).read_text().splitlines()]
|
|
original = {r['DOI']: r for r in self.snapshot['records'] if r['volume'] == '36'}
|
|
self.assertEqual({r['external_id'] for r in rows}, set(original))
|
|
for r in rows:
|
|
doi = r['external_id']; o = original[doi]
|
|
self.assertEqual(r['metadata']['registry_fields'], o)
|
|
self.assertEqual(r['title'], o['title'][0])
|
|
self.assertEqual(r['authors'], [a['given']+' '+a['family'] for a in o['authors']])
|
|
self.assertEqual(r['identifiers'], {'doi': doi})
|
|
self.assertEqual(r['submission_identifiers'], [{'scheme': 'publication_doi', 'value': doi}])
|
|
self.assertFalse(r['tags']); self.assertFalse(r['metadata']['original_decision_signature_verified'])
|
|
self.assertEqual(r['track'], 'main_tracks_unclassified')
|
|
self.assertEqual(r['metadata']['publication_date'], '2026-06-08')
|
|
changed = next(r for r in rows if r['external_id'] == '10.1609/icaps.v36i1.42860')
|
|
self.assertEqual(changed['title'], 'Analyzing Planner Design Trade-Offs for MAPF Under ADG-Based Realistic Execution')
|
|
self.assertIn('Stephen F. Smith', changed['authors'])
|
|
with self.assertRaisesRegex(ValueError, 'Output exists'):
|
|
c.collect(root/'out', snapshots=src)
|
|
|
|
def test_math_markup_is_not_flattened_as_plain_numbers(self):
|
|
self.assertEqual(c.abstract_text('<jats:p>A < B and C & D.\n Next line.</jats:p>'), 'A < B and C & D. Next line.')
|
|
for raw in ['<jats:p>10<sup>6</sup></jats:p>', '<jats:p>x</jats:p><jats:p>y</jats:p>', '<jats:p> </jats:p>', None]:
|
|
with self.assertRaises(ValueError):
|
|
c.abstract_text(raw)
|
|
|
|
def test_invalid_or_repeated_doi_and_edition_rejected(self):
|
|
for kind in ('doi', 'repeat', 'volume', 'container', 'year'):
|
|
with self.subTest(kind=kind):
|
|
s = copy.deepcopy(self.snapshot); rows = [r for r in s['records'] if r['volume'] == '36']; r = rows[0]
|
|
if kind == 'doi': r['DOI'] = '10.9999/foreign'
|
|
if kind == 'repeat': rows[1]['DOI'] = r['DOI']
|
|
if kind == 'volume': r['volume'] = '37'
|
|
if kind == 'container': r['container-title'] = ['Other Conference']
|
|
if kind == 'year': r['published']['date-parts'] = [[2025, 6, 8]]
|
|
with self.assertRaises(ValueError):
|
|
c.registry_papers(s)
|
|
|
|
def test_missing_authors_and_changed_order_evidence_rejected(self):
|
|
for kind in ('missing', 'sequence', 'profile'):
|
|
s = copy.deepcopy(self.snapshot); r = next(r for r in s['records'] if r['volume'] == '36')
|
|
if kind == 'missing': r['authors'][0].pop('family')
|
|
if kind == 'sequence': r['authors'][0]['sequence'] = 'additional'
|
|
if kind == 'profile': r['authors'][0]['ORCID'] = 'unreviewed-profile'
|
|
with self.assertRaises(ValueError):
|
|
c.registry_papers(s)
|
|
|
|
def test_receipt_scope_and_timezone_rejected(self):
|
|
for key, value in [('at', '2026-11-17T00:00:00'), ('url', 'https://example.org/works'), ('raw_response_sha256', 'other')]:
|
|
s = copy.deepcopy(self.snapshot); s[key] = value
|
|
with self.assertRaises(ValueError):
|
|
c.registry_papers(s)
|
|
|
|
def test_tamper_failure_retained_and_success_not_published(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); src = root/'src'; src.mkdir(); (src/'crossref-filtered.json').write_bytes(self.raw+b' ')
|
|
with self.assertRaisesRegex(ValueError, 'hash changed'):
|
|
c.collect(root/'out', snapshots=src)
|
|
self.assertTrue((root/'out/failed.json').exists())
|
|
self.assertFalse((root/'out/collection-report.json').exists())
|
|
|
|
def test_symlink_rejected(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); src = root/'src'; src.mkdir(); (root/'data.json').write_bytes(self.raw); (src/'crossref-filtered.json').symlink_to(root/'data.json')
|
|
with self.assertRaisesRegex(ValueError, 'Unsafe'):
|
|
c.collect(root/'out', snapshots=src)
|