Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

test_lefactory.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #-*- coding: utf-8 -*-
  2. import unittest
  3. import random
  4. import tests.loader_utils
  5. from lodel.editorial_model.model import EditorialModel
  6. from lodel.leapi import lefactory
  7. class LeFactoryTestCase(unittest.TestCase):
  8. model = None
  9. @classmethod
  10. def setUpClass(cls):
  11. """ Generate an example model for this TestCase """
  12. model = EditorialModel(
  13. "test_model",
  14. description = "Model for LeFactoryTestCase"
  15. )
  16. cls1 = model.new_class('testclass1')
  17. cls2 = model.new_class('testclass2')
  18. cls3 = model.new_class('testclass3', parents = [cls2])
  19. cls4 = model.new_class('testclass4', parents = [cls1, cls3])
  20. cls5 = model.new_class('testclass5', parents = [cls4])
  21. cls6 = model.new_class('testclass6', parents = [cls5])
  22. cls1.new_field('testfield1', data_handler='varchar')
  23. cls1.new_field('testfield2', data_handler='varchar', nullable = True)
  24. cls1.new_field('testfield3', data_handler='varchar', max_length=64)
  25. cls1.new_field('testfield4', data_handler='varchar', max_length=64, nullable=False, uniq=True)
  26. cls1.new_field('id', data_handler='integer', primary_key = True)
  27. cls5.new_field('id2', data_handler='varchar', primary_key = True)
  28. cls.model = model
  29. def test_emclass_sorted_by_deps(self):
  30. """ Test the function that sort EmClass by dependencies """
  31. cls_list = self.model.classes()
  32. for _ in range(100): #Bad sorts algorithm can have random behavior
  33. random.shuffle(cls_list)
  34. sorted_cls = lefactory.emclass_sorted_by_deps(cls_list)
  35. seen = set() # Stores the EmClass allready seen will walking through array
  36. for emclass in sorted_cls:
  37. for parent in emclass.parents_recc:
  38. self.assertIn(parent, seen)
  39. seen |= set((emclass,))
  40. def test_generated_code_syntax(self):
  41. """ Test the function that generate LeObject childs classes code"""
  42. pycode = lefactory.dyncode_from_em(self.model)
  43. pycomp_code = compile(pycode, "dyn.py", 'exec')
  44. exec(pycomp_code, globals())