Page MenuHomec4science

test_faksimile_image.py
No OneTemporary

File Metadata

Created
Fri, Nov 1, 00:14

test_faksimile_image.py

import unittest
from os import sep, path
from os.path import isdir, dirname, basename
import lxml.etree as ET
import sys
import sys
sys.path.append('svgscripts')
from datatypes.faksimile_image import FaksimileImage
from datatypes.image import Image
from datatypes.text_field import TextField
class TestFaksimileImage(unittest.TestCase):
def setUp(self):
DATADIR = dirname(__file__) + sep + 'test_data'
if not isdir(DATADIR):
DATADIR = dirname(dirname(__file__)) + sep + 'test_data'
self.svg_file = DATADIR + sep + 'W-II-1,49et50.svg'
def test_init(self):
image = FaksimileImage(file_name='test.jpg', height=10, width=10)
self.assertEqual(image.tag, FaksimileImage.XML_TAG)
self.assertEqual(image.width, 10)
def test_attach_object_to_tree(self):
image = FaksimileImage(file_name='test.jpg', height=10, width=10, x=-100, y=-200)
empty_tree = ET.ElementTree(ET.Element('faksimile'))
image.attach_object_to_tree(empty_tree)
self.assertEqual(image.tag, FaksimileImage.XML_TAG)
for node in empty_tree.getroot().xpath('//' + image.tag):
self.assertEqual(node.get('file-name'), 'test.jpg')
self.assertEqual(node.get('height'), '10')
self.assertEqual(node.get('width'), '10')
def test_CREATE_IMAGE(self):
svg_tree = ET.parse(self.svg_file)
image_node = svg_tree.getroot().find('.//image', svg_tree.getroot().nsmap)
image = FaksimileImage.CREATE_IMAGE(image_node, self.svg_file)
self.assertEqual(image.file_name, 'W-II-1,49et50.jpg')
image_node = ET.Element('image')
file_name = 'W-II-1,49et50.jpg'
width = 10
height = 10
image_node.set('href', file_name)
image_node.set('height', str(height))
image_node.set('width', str(width))
image = FaksimileImage.CREATE_IMAGE(image_node)
self.assertEqual(image.height, height)
self.assertEqual(image.width, width)
self.assertEqual(image.file_name, file_name)
def test_get_semantic_dict(self):
image = FaksimileImage(file_name='test.jpg', URL=FaksimileImage.NIETZSCHE_SOURCES_URL + "N-II-1,2et3", height=10, width=10)
self.assertEqual(FaksimileImage.get_semantic_dictionary()['class'].get('this'), FaksimileImage)
#print(FaksimileImage.get_semantic_dictionary())
def text_get_image_joined_with_text_field(self):
tf = TextField()
orig_image = FaksimileImage(file_name='test.jpg', URL=FaksimileImage.NIETZSCHE_SOURCES_URL + "N-II-1,2et3", height=10, width=10)
copy_image = orig_image.get_image_joined_with_text_field(tf)
self.assertEqual(copy_image.text_field.width, tf.width)
self.assertEqual(copy_image.id, orig_image.id)
self.assertEqual(copy_image.file_name, orig_image.file_name)
if __name__ == "__main__":
unittest.main()

Event Timeline