Page MenuHomec4science

test_class_spec.py
No OneTemporary

File Metadata

Created
Sat, Nov 23, 23:11

test_class_spec.py

import unittest
from os import sep, path
import inspect
from datatypes.class_spec import SemanticClass
from datatypes.image import Image
class TestSemanticClassFail(SemanticClass):
def __init__(self):
pass
class TestSemanticClassOK(SemanticClass):
def __init__(self):
self.msg = 'Hello World!'
@staticmethod
def get_semantic_dictionary():
return {'class': { 'this': TestSemanticClassOK}, 'properties': { 'msg': (str, SemanticClass.SINGLE_VALUE) }}
class TestSemanticClassB(SemanticClass):
def __init__(self):
self.data = [ 1, 2, 3, 4 ]
self.test = [ TestSemanticClassOK(), TestSemanticClassOK() ]
@staticmethod
def get_semantic_dictionary():
return { 'class': {'this': TestSemanticClassB }, 'properties': { 'data': (int, SemanticClass.LIST), 'test': (TestSemanticClassOK, SemanticClass.LIST) }}
def get_super(self):
return inspect.getclasstree([self.__class__],unique=True)[0][0]
class TestSemanticClassC(TestSemanticClassB):
pass
class TestSemanticClass(unittest.TestCase):
def test_fail(self):
with self.assertRaises(TypeError):
TestSemanticClassFail()
def test_success(self):
test = TestSemanticClassOK()
self.assertEqual(TestSemanticClassOK.get_semantic_dictionary()['properties'], { 'msg': (str, 1) })
#self.assertEqual(test.get_data_dictionary()['body'], { 'msg': 'Hello World!'})
test = TestSemanticClassB()
self.assertEqual(TestSemanticClassB.get_semantic_dictionary()['properties'], { 'data': (int, SemanticClass.LIST), 'test': (TestSemanticClassOK, SemanticClass.LIST) })
self.assertEqual(test.get_semantic_dictionary()['class'].get('this'), TestSemanticClassB)
def test_get_class_dictionary(self):
test = TestSemanticClassC()
self.assertEqual(test.get_class_dictionary().get('type') is not None, True)
self.assertEqual(test.get_class_dictionary().get('type'), TestSemanticClassB)
if __name__ == "__main__":
unittest.main()

Event Timeline