61 lines
3.3 KiB
Python
61 lines
3.3 KiB
Python
import unittest
|
|
import tempfile
|
|
import json
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from collect_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: 2025\nbooktitle: ICML\n'
|
|
paper='---\nid: paper1\nlayout: inproceedings\ntitle: Paper\nabstract:\n---\n'
|
|
with tempfile.TemporaryDirectory() as tmp,patch('collect_pmlr.fetch',return_value=config),patch('collect_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('collect_pmlr.fetch',return_value=config),patch('collect_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_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('collect_pmlr.fetch',return_value=config),patch('collect_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()
|