No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_lefactory.py 2.1KB

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