Files
paper-atlas/tests/test_pmlr.py
codex-bot b1429cd3d8
Metadata integrity checks / metadata (push) Successful in 10m39s
Preserve the CoRL 2021 Blue Sky publication track
2026-11-22 19:31:39 +08:00

93 lines
5.8 KiB
Python

import unittest
import tempfile
import json
from pathlib import Path
from unittest.mock import patch
from paper_atlas.collectors.pmlr import load_metadata,venue_key,collect_volume
class MetadataTests(unittest.TestCase):
def test_legacy_binary_scalar_is_decoded_as_text(self):
self.assertEqual(load_metadata('title: !binary |\n SGVsbG8=\n')['title'],'Hello')
def test_trailing_empty_document_is_allowed(self):
self.assertEqual(load_metadata('---\nyear: 2024\n---\n'),{'year':2024})
def test_conflicting_documents_are_not_silently_combined(self):
with self.assertRaisesRegex(ValueError,'exactly one'):
load_metadata('year: 2024\n---\nyear: 2025\n')
def test_historical_conference_name_aliases(self):
self.assertEqual(venue_key('AISTATS 2010'),'AISTATS')
self.assertEqual(venue_key('AISTATS 2012'),'AISTATS')
self.assertEqual(venue_key('COLT 2012'),'COLT')
self.assertEqual(venue_key('ECML-PKDD'),'ECML-PKDD')
def test_missing_abstract_is_reported_as_partial_collection(self):
config=b'shortname: ICML\nyear: 2023\nbooktitle: ICML\n'
paper='---\nid: paper1\nlayout: inproceedings\ntitle: Paper\nabstract:\n---\n'
with tempfile.TemporaryDirectory() as tmp,patch('paper_atlas.collectors.pmlr.fetch',return_value=config),patch('paper_atlas.collectors.pmlr.metadata_texts',return_value=iter([('paper.md',paper)])):
result=collect_volume(999,tmp,tmp)
self.assertEqual(result['count'],1)
self.assertEqual(result['missing_abstract_count'],1)
self.assertEqual(result['status'],'partial')
def test_duplicate_publication_posts_preserve_date_evidence_once(self):
config=b'shortname: CoRL\nyear: 2023\nbooktitle: CoRL\n'
paper='---\nid: paper1\nlayout: inproceedings\ntitle: Paper\nabstract: Real abstract\ndate: {date}\n---\n'
posts=[('2023-11-13-paper1.md',paper.format(date='2023-11-13')),('2023-12-02-paper1.md',paper.format(date='2023-12-02'))]
with tempfile.TemporaryDirectory() as tmp,patch('paper_atlas.collectors.pmlr.fetch',return_value=config),patch('paper_atlas.collectors.pmlr.metadata_texts',return_value=iter(posts)):
result=collect_volume(229,tmp,tmp)
rows=[json.loads(line) for line in Path(result['file']).read_text().splitlines()]
self.assertEqual(result['count'],1)
self.assertEqual(result['metadata_post_count'],2)
self.assertEqual(result['duplicate_post_count'],1)
self.assertEqual(len(rows[0]['metadata']['source_versions']),2)
self.assertEqual(rows[0]['metadata']['date'],'2023-12-02')
def test_publisher_preface_is_not_an_accepted_paper(self):
config = b'shortname: UAI\nyear: 2024\nbooktitle: UAI\n'
accepted = '---\nid: paper1\nlayout: inproceedings\ntitle: Paper\nabstract: Abstract\n---\n'
preface = '---\nid: kiyavash24a\nlayout: inproceedings\ntitle: Volume Preface\nsection: Preface\n---\n'
posts = [('paper.md', accepted), ('preface.md', preface)]
with tempfile.TemporaryDirectory() as tmp, patch(
'paper_atlas.collectors.pmlr.fetch', return_value=config,
), patch('paper_atlas.collectors.pmlr.metadata_texts', return_value=iter(posts)):
result = collect_volume(244, tmp, tmp)
rows = [json.loads(line) for line in Path(result['file']).read_text().splitlines()]
self.assertEqual(result['excluded_preface_ids'], ['v244/kiyavash24a'])
self.assertEqual(result['files'][0]['count'], 1)
self.assertEqual([row['external_id'] for row in rows], ['v244/paper1'])
def test_corl_2021_sections_keep_blue_sky_apart_from_contributed_papers(self):
config = b'shortname: CoRL\nyear: 2021\nbooktitle: Proceedings of the 5th Conference on Robot Learning\n'
paper = '---\nid: {id}\nlayout: inproceedings\ntitle: Paper\nabstract: Abstract\nsection: {section}\n---\n'
posts = [('one.md', paper.format(id='one', section='Contributed Papers')),
('two.md', paper.format(id='two', section='Blue Sky Papers'))]
with tempfile.TemporaryDirectory() as tmp, patch('paper_atlas.collectors.pmlr.fetch', return_value=config), patch(
'paper_atlas.collectors.pmlr.metadata_texts', return_value=iter(posts),
):
result = collect_volume(164, tmp, tmp)
self.assertEqual(result['track'], 'mixed')
files = {manifest['track']: Path(manifest['file']) for manifest in result['files']}
self.assertEqual({key: path.name for key, path in files.items()},
{'main': 'pmlr-v164.jsonl', 'blue_sky': 'pmlr-v164-blue_sky.jsonl'})
rows = {track: json.loads(path.read_text()) for track, path in files.items()}
self.assertEqual([(rows[t]['external_id'], rows[t]['track'], rows[t]['metadata']['pmlr_section'])
for t in ('main', 'blue_sky')],
[('v164/one', 'main', 'Contributed Papers'), ('v164/two', 'blue_sky', 'Blue Sky Papers')])
def test_conflicting_duplicate_posts_do_not_replace_previous_collection(self):
config=b'shortname: CoRL\nyear: 2023\nbooktitle: CoRL\n'
paper='---\nid: paper1\nlayout: inproceedings\ntitle: {title}\nabstract: Abstract\n---\n'
with tempfile.TemporaryDirectory() as tmp,patch('paper_atlas.collectors.pmlr.fetch',return_value=config),patch('paper_atlas.collectors.pmlr.metadata_texts',return_value=iter([('a.md',paper.format(title='First paper')),('b.md',paper.format(title='Other paper'))])):
previous=Path(tmp)/'pmlr-v229.jsonl';previous.write_text('previous valid collection')
with self.assertRaisesRegex(ValueError,'Conflicting metadata posts'):
collect_volume(229,tmp,tmp)
self.assertEqual(previous.read_text(),'previous valid collection')
if __name__=='__main__':
unittest.main()