Build Code4History Research
This commit is contained in:
+12
-13
@@ -16,13 +16,12 @@ class InteractionTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.t=tempfile.TemporaryDirectory();self.addCleanup(self.t.cleanup)
|
||||
self.root=Path(self.t.name)
|
||||
for d in ('upload','todo','todo/archive','requests','requests/archive','01_sources/records/primary','01_sources/records/secondary','01_sources/originals/primary','01_sources/originals/secondary','01_sources/provenance','10_templates'):
|
||||
for d in ('upload','todo','todo/archive','requests','requests/archive','sources/records/primary','sources/records/secondary','sources/originals/primary','sources/originals/secondary','sources/provenance','templates'):
|
||||
(self.root/d).mkdir(parents=True,exist_ok=True)
|
||||
for name in ('primary.md','secondary.md'):
|
||||
shutil.copy2(ROOT/'10_templates'/name,self.root/'10_templates'/name)
|
||||
shutil.copy2(ROOT/'templates/source.md',self.root/'templates/source.md')
|
||||
(self.root/'upload/readme.md').write_text('do not remove')
|
||||
(self.root/'01_sources/catalog.md').write_text('# Catalog\n')
|
||||
(self.root/'STATE.md').write_text('state unchanged')
|
||||
(self.root/'sources/catalog.md').write_text('# Catalog\n')
|
||||
(self.root/'findings.md').write_text('state unchanged')
|
||||
def test_intake_preserves_hash_and_meta_then_empties_upload(self):
|
||||
original=b'%PDF-1.7\nC4H original\x00\xff'
|
||||
(self.root/'upload/test.pdf').write_bytes(original)
|
||||
@@ -37,7 +36,7 @@ class InteractionTests(unittest.TestCase):
|
||||
self.assertTrue((self.root/'upload/readme.md').exists())
|
||||
record=(self.root/result['record_path']).read_text('utf-8')
|
||||
self.assertIn('sha256:',record);self.assertIn('SRC-P-0001',record)
|
||||
receipt=json.loads((self.root/'01_sources/provenance/SRC-P-0001-intake.json').read_text('utf-8'))
|
||||
receipt=json.loads((self.root/'sources/provenance/SRC-P-0001-intake.json').read_text('utf-8'))
|
||||
self.assertEqual(receipt['sha256'],it.sha256(self.root/result['original_path']))
|
||||
self.assertEqual(it.finish(self.root),0)
|
||||
def test_duplicate_same_bytes_reuses_existing_source(self):
|
||||
@@ -47,7 +46,7 @@ class InteractionTests(unittest.TestCase):
|
||||
second=it.intake(self.root,'letter.pdf','primary','second')
|
||||
self.assertEqual(second['id'],first['id'])
|
||||
self.assertTrue(second['reused'])
|
||||
self.assertEqual(len(list((self.root/'01_sources/records/primary').glob('SRC-P-*.md'))),1)
|
||||
self.assertEqual(len(list((self.root/'sources/records/primary').glob('SRC-P-*.md'))),1)
|
||||
def test_changed_source_metadata_is_not_discarded(self):
|
||||
(self.root/'upload/letter.pdf').write_bytes(b'duplicate text')
|
||||
it.intake(self.root,'letter.pdf','primary','first')
|
||||
@@ -74,12 +73,12 @@ class InteractionTests(unittest.TestCase):
|
||||
self.assertFalse((self.root/result['record_path']).exists())
|
||||
self.assertTrue((self.root/'upload/book.pdf').exists())
|
||||
def test_todo_user_answers_and_applied_before_archive(self):
|
||||
f=it.todo_new(self.root,'日期核实','verification','请核对第4页原文','01_sources/records')
|
||||
f=it.todo_new(self.root,'日期核实','verification','请核对第4页原文','sources/records')
|
||||
p=self.root/f
|
||||
with self.assertRaises(ValueError):it.archive_task(self.root,'todo',p.name,'STATE.md')
|
||||
with self.assertRaises(ValueError):it.archive_task(self.root,'todo',p.name,'findings.md')
|
||||
doc=p.read_text('utf-8').replace('status: open','status: answered').replace('(请在此填写回复;扫描器会自动识别)','原件日期为1865年。')
|
||||
p.write_text(doc,encoding='utf-8')
|
||||
result=it.archive_task(self.root,'todo',p.name,'STATE.md')
|
||||
result=it.archive_task(self.root,'todo',p.name,'findings.md')
|
||||
self.assertTrue((self.root/result).is_file())
|
||||
self.assertFalse(p.exists())
|
||||
self.assertIn('原件日期为1865年', (self.root/result).read_text('utf-8'))
|
||||
@@ -88,7 +87,7 @@ class InteractionTests(unittest.TestCase):
|
||||
p=self.root/f
|
||||
p.write_text(p.read_text('utf-8').replace('(请在此填写回复;扫描器会自动识别)','措辞正确,允许使用。'),encoding='utf-8')
|
||||
self.assertEqual(it.status(self.root)['summary']['todo_answered'],1)
|
||||
dest=it.archive_task(self.root,'todo',p.name,'STATE.md')
|
||||
dest=it.archive_task(self.root,'todo',p.name,'findings.md')
|
||||
self.assertIn('status: answered',(self.root/dest).read_text('utf-8'))
|
||||
|
||||
def test_requests_do_not_move_without_result(self):
|
||||
@@ -96,7 +95,7 @@ class InteractionTests(unittest.TestCase):
|
||||
self.assertEqual(it.status(self.root)['summary']['requests_pending'],1)
|
||||
with self.assertRaises(ValueError):it.archive_task(self.root,'requests','look.md','missing.md')
|
||||
self.assertTrue((self.root/'requests/look.md').exists())
|
||||
result=it.archive_task(self.root,'requests','look.md','STATE.md')
|
||||
result=it.archive_task(self.root,'requests','look.md','findings.md')
|
||||
self.assertTrue((self.root/result).exists())
|
||||
def test_orphan_metadata_blocks_finish(self):
|
||||
(self.root/'upload/no-pdf.pdf.source.md').write_text('元数据')
|
||||
@@ -108,6 +107,6 @@ class InteractionTests(unittest.TestCase):
|
||||
(self.root/'upload/evidence.txt.source.md').write_text(note)
|
||||
result=it.intake(self.root,'evidence.txt','primary','letter')
|
||||
self.assertEqual((self.root/result['metadata_path']).read_text(),note)
|
||||
self.assertEqual((self.root/'STATE.md').read_text(),'state unchanged')
|
||||
self.assertEqual((self.root/'findings.md').read_text(),'state unchanged')
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user