Page MenuHomec4science

test_color.py
No OneTemporary

File Metadata

Created
Wed, May 15, 18:54

test_color.py

import unittest
from os import sep, path
from os.path import dirname, basename, isfile, isdir
import lxml.etree as ET
import sys
sys.path.append('svgscripts')
from datatypes.color import Color
from datatypes.archival_manuscript import ArchivalManuscriptUnity
class GColor: # Gnome supported
END = "\x1b[0m"
# If Foreground is False that means color effect on Background
def RGB(R, G, B): # R: 0-255 , G: 0-255 , B: 0-255
FB_G = 38 # Effect on foreground
return "\x1b[" + str(FB_G) + ";2;" + str(R) + ";" + str(G) + ";" + str(B) + "m"
class TestColor(unittest.TestCase):
def setUp(self):
DATADIR = dirname(__file__) + sep + 'test_data'
if not isdir(DATADIR):
DATADIR = dirname(dirname(__file__)) + sep + 'test_data'
self.test_file = DATADIR + sep + 'test.xml'
self.test_svg_file = DATADIR + sep + 'test421.svg'
self.pdf_xml = DATADIR + sep + 'W_I_8_page125.xml'
self.xml_file = DATADIR + sep + 'N_VII_1_page005.xml'
self.xml_fileB = DATADIR + sep + 'N_VII_1_page006.xml'
self.pdf_xml_source = DATADIR + sep + 'W_I_8_neu_125-01.svg'
self.test_page = DATADIR + sep + 'N_VII_1_page001.xml'
self.test_manuscript = DATADIR + sep + 'N_VII_1.xml'
def test_attach_object_to_tree(self):
color = Color(color_name='blue', hex_color='#009CDE')
empty_tree = ET.ElementTree(ET.Element('page'))
color.attach_object_to_tree(empty_tree)
color_nodes = empty_tree.xpath('.//' + Color.XML_TAG)
self.assertEqual(len(color_nodes), 1)
color = Color.create_cls(node=color_nodes[0])
self.assertEqual(color.hex_color, '#009CDE')
def test_create_cls(self):
manuscript = ArchivalManuscriptUnity.create_cls(self.test_manuscript)
manuscript.UNITTESTING = True
color = Color.create_cls()
self.assertEqual(color.name, 'black')
color = Color.create_cls(hex_color='#009CDE', manuscript=manuscript)
self.assertEqual(color.name, 'blue')
self.assertEqual(color in manuscript.colors, True)
self.assertEqual(manuscript.get_color(color.hex_color), color)
color = Color.create_cls(hex_color='#009CDE', manuscript=manuscript)
self.assertEqual(color.name, 'blue')
"""
color_string = "#000000, #009CDE, #1D1D1B, #4CA32F, #93CDF1, #9D9D9C, #ADD8F5, #B2B2B2, #C6C6C6, #CD1719, #CED5CE, #DADADA, #DC0714, #DC0814, #F0977A, #F0F0F0, #F8F9F8, #FF6600, #FFFFFF".replace(',','')
color_list = color_string.split(' ')
for hex_color in color_list:
color = Color.create_cls(hex_color=hex_color)
print(GColor.RGB(*color.rgb_color), color.name, GColor.END)
"""
def test_get_semantic_dictionary(self):
dictionary = Color.get_semantic_dictionary()
#print(dictionary)
def test_eq(self):
colorA = Color.create_cls()
colorB = Color()
self.assertEqual(colorA == colorB, True)
colorC = Color.create_cls(hex_color="#FFFFFF")
self.assertEqual(colorC.name, 'white')
self.assertEqual(colorA != colorC, True)
def test_create_cls_from_style_object(self):
color = Color.create_cls_from_style_object({'clip-path': 'url(#SVGID_1750_)', 'fill': 'none', 'stroke': '#F0F0F0', 'stroke-miterlimit': '10', 'stroke-width': '0.4'})
self.assertEqual(color.name, 'white')
if __name__ == "__main__":
unittest.main()

Event Timeline