1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import unittest
-
- from lodel.leapi.datahandlers.base_classes import DataHandler
- from lodel.leapi.datahandlers.datas import Varchar
-
-
- class DataHandlerTestCase(unittest.TestCase):
-
- def test_init_abstract_class(self):
- datahandler = None
- try:
- datahandler = DataHandler()
- except NotImplementedError:
- self.assertNotIsInstance(datahandler, DataHandler)
- self.assertIsNone(datahandler)
-
- def test_register_new_handler(self):
- DataHandler.register_new_handler('testvarchar', Varchar)
- self.assertEqual(DataHandler.from_name('testvarchar'), Varchar)
-
- def test_register_nonclass_as_handler(self):
- try:
- DataHandler.register_new_handler('testvarchar', 'common string')
- except Exception as err:
- self.assertEqual(ValueError, type(err))
-
- def test_register_invalid_class_as_handler(self):
-
- try:
- DataHandler.register_new_handler('testvarchar', Exception)
- except Exception as err:
- self.assertEqual(ValueError, type(err))
-
- def test_from_name(self):
- DataHandler.register_new_handler('test_varchar', Varchar)
- self.assertEqual(DataHandler.from_name('test_varchar'), Varchar)
-
- def test_from_missing_name(self):
- DataHandler.register_new_handler('test_varchar1', Varchar)
- DataHandler.register_new_handler('test_varchar2', Varchar)
- try:
- DataHandler.from_name('test_varchar3')
- except Exception as err:
- self.assertEqual(NameError, type(err))
|