114 lines
6.7 KiB
Python
114 lines
6.7 KiB
Python
import gzip
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
from paper_atlas.collectors import icdm2026 as c
|
|
|
|
|
|
class ICDM2026Tests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.fixture = json.loads(gzip.decompress((Path(__file__).parent/'fixtures/icdm2026-source.json.gz').read_bytes()))
|
|
cls.raw = cls.fixture['files'][c.SNAPSHOT+'/icdm-detailed-sessions.html'].encode()
|
|
cls.gold = cls.fixture['independent_inventory']
|
|
|
|
def snapshots(self, root):
|
|
for name, text in self.fixture['files'].items():
|
|
path = root/name; path.parent.mkdir(parents=True, exist_ok=True); path.write_bytes(text.encode())
|
|
|
|
def test_all_rows_match_separately_parsed_frozen_inventory(self):
|
|
result = c.parse_program(self.raw)
|
|
self.assertEqual(len(result), len(self.gold['entries']))
|
|
for position, (row, gold) in enumerate(zip(result, self.gold['entries']), 1):
|
|
for field in ('paper_id_literal', 'title', 'authors_literal', 'source_reported_authors', 'time_literal'):
|
|
self.assertEqual(row[field], gold[field])
|
|
self.assertEqual(row['source_position'], position)
|
|
for field, value in gold['session'].items():
|
|
self.assertEqual(row['session'][field], value)
|
|
|
|
def test_instantiable_collection_retains_scope_fields_and_source_bytes(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); self.snapshots(root/'src')
|
|
report = c.collect(root/'out', snapshots=root/'src')
|
|
self.assertEqual(report['track_counts'], self.gold['track_counts_literal'])
|
|
self.assertEqual(report['presentation_counts'], self.gold['presentation_counts_literal'])
|
|
self.assertEqual((report['records'], report['missing_abstract_count']), (324, 324))
|
|
self.assertFalse(report['database_written']); self.assertEqual(report['network_requests'], 0)
|
|
self.assertEqual(report['public_rejected_metadata'], 'unknown_no_public_export_verified')
|
|
all_rows = []
|
|
for manifest in 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(line) for line in raw.splitlines()]
|
|
self.assertEqual(len(rows), manifest['missing_abstract_count'])
|
|
for row in rows:
|
|
self.assertEqual((row['venue'], row['year'], row['track']), ('ICDM', 2026, manifest['track']))
|
|
self.assertIsNone(row['abstract']); self.assertIsNone(row['metadata']['paper_type'])
|
|
self.assertEqual(row['identifiers'], {}); self.assertEqual(row['submission_identifiers'], [])
|
|
self.assertFalse(row['metadata']['original_decision_signature_verified'])
|
|
self.assertEqual(row['external_id'], '2026/'+row['metadata']['program_fields']['paper_id_literal'])
|
|
self.assertTrue(row['url'].startswith(c.PROGRAM+'#paper-DM'))
|
|
self.assertTrue(all(t['namespace'].startswith(c.SOURCE+':') for t in row['tags']))
|
|
self.assertNotIn('doi', row['metadata']); self.assertNotIn('decision_date', row)
|
|
all_rows.extend(rows)
|
|
self.assertEqual(len({r['external_id'] for r in all_rows}), 324)
|
|
for item in report['evidence']:
|
|
raw = (root/'out'/item['output_file']).read_bytes()
|
|
self.assertEqual(raw, self.fixture['files'][c.SNAPSHOT+'/'+item['file']].encode())
|
|
self.assertTrue((root/'out/collection-report.json').is_file())
|
|
self.assertFalse((root/'out/collection-report.json.part').exists())
|
|
with self.assertRaisesRegex(ValueError, 'Output exists'):
|
|
c.collect(root/'out', snapshots=root/'src')
|
|
|
|
def test_stale_or_different_conference_rejected(self):
|
|
for old, new in [(b'IEEE ICDM 2026', b'IEEE ICDM 2025'),
|
|
(b'In-person session presentation list.', b'Workshop presentation list.')]:
|
|
with self.subTest(old=old), self.assertRaises(ValueError):
|
|
c.parse_program(self.raw.replace(old, new))
|
|
|
|
def test_track_attribute_must_agree_with_visible_label(self):
|
|
changed = self.raw.replace(b'data-track="research"', b'data-track="applied"', 1)
|
|
with self.assertRaisesRegex(ValueError, 'track'):
|
|
c.parse_program(changed)
|
|
|
|
def test_presentation_attribute_is_not_inferred_from_session_id(self):
|
|
changed = self.raw.replace(b'data-format="long"', b'data-format="short"', 1)
|
|
with self.assertRaisesRegex(ValueError, 'presentation'):
|
|
c.parse_program(changed)
|
|
|
|
def test_repeated_paper_and_source_locator_disagreement_rejected(self):
|
|
for old, new in [(b'DM1278', b'DM827'), (b'id="paper-DM827"', b'id="paper-DM99999"')]:
|
|
with self.subTest(old=old), self.assertRaises(ValueError):
|
|
c.parse_program(self.raw.replace(old, new))
|
|
|
|
def test_lost_session_or_changed_session_counts_rejected(self):
|
|
for old, new in [(b'data-session-id="L1"', b'data-session-id="L2"'),
|
|
(b'Long \xc2\xb7 7 papers', b'Long \xc2\xb7 6 papers')]:
|
|
with self.subTest(old=old), self.assertRaises(ValueError):
|
|
c.parse_program(self.raw.replace(old, new, 1))
|
|
|
|
def test_empty_author_is_not_silently_dropped(self):
|
|
changed = self.raw.replace(b'Qishuang Fu; Andreas Deppeler;', b'Qishuang Fu;;', 1)
|
|
with self.assertRaisesRegex(ValueError, 'author'):
|
|
c.parse_program(changed)
|
|
|
|
def test_snapshot_manifest_and_body_corruption_rejected_before_output(self):
|
|
for name in ('manifest.json', 'icdm-detailed-sessions.html', 'icdm-research-policy.html', 'icdm-applied-policy.html'):
|
|
with self.subTest(name=name), tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); self.snapshots(root/'src'); path = root/'src'/c.SNAPSHOT/name
|
|
path.write_bytes(path.read_bytes()+b' ')
|
|
with self.assertRaises(ValueError):
|
|
c.collect(root/'out', snapshots=root/'src')
|
|
self.assertFalse((root/'out').exists())
|
|
|
|
def test_snapshot_source_symlink_rejected(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp); self.snapshots(root/'src'); path = root/'src'/c.SNAPSHOT/'icdm-detailed-sessions.html'
|
|
real = root/'real.html'; path.rename(real); path.symlink_to(real)
|
|
with self.assertRaisesRegex(ValueError, 'Unsafe source'):
|
|
c.collect(root/'out', snapshots=root/'src')
|