Skip to content
Snippets Groups Projects
Commit 89024a99 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Add bulk_transcriptions unit test

parent d284bbfe
No related branches found
No related tags found
1 merge request!22Add score to transcriptions
from django.test import TestCase
from arkindex.documents.models import Page
from arkindex.images.models import ImageServer, Image, Zone, Transcription
from arkindex.images.importer import bulk_transcriptions
class TestBulkTranscriptions(TestCase):
"""Tests for bulk transcription and zone importing"""
def setUp(self):
# Create a page and an image
self.imgsrv = ImageServer.objects.create(name="Test Server", url="http://server")
self.img = Image.objects.create(path='img', width=1337, height=42, server=self.imgsrv)
self.page = Page.objects.create(name="page", folio="page")
Zone.objects.create(polygon=[[0, 0], [1337, 0], [1337, 42], [42, 0]],
image=self.img, element=self.page)
def test_bulk_transcriptions(self):
items = [
{
'x': 0,
'y': 0,
'width': 100,
'height': 100,
'line': '1',
'text': 'test 1',
'score': 0.1,
},
{
'x': 20,
'y': 20,
'width': 100,
'height': 100,
'line': '2',
'text': 'test 2',
'score': 0.2,
},
]
out = list(bulk_transcriptions(self.img, self.page, items))
out.sort(key=lambda t: t.line) # Prevent test errors by sorting
self.assertEqual(len(out), 2)
self.assertIsInstance(out[0], Transcription)
self.assertIsInstance(out[1], Transcription)
self.assertEqual(out[0].line, 1)
self.assertEqual(out[0].text, 'test 1')
self.assertEqual(out[0].score, 0.1)
self.assertEqual(out[1].line, 2)
self.assertEqual(out[1].text, 'test 2')
self.assertEqual(out[1].score, 0.2)
self.assertEqual(out[0].zones.count(), 1)
self.assertEqual(out[1].zones.count(), 1)
z1, z2 = out[0].zones.first(), out[1].zones.first()
self.assertListEqual(z1.polygon, [[0, 0], [0, 100], [100, 100], [100, 0]])
self.assertListEqual(z2.polygon, [[20, 20], [20, 120], [120, 120], [120, 20]])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment