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_translator_picklefile.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #-*- coding: utf-8 -*-
  2. import unittest
  3. import tempfile
  4. import os
  5. import tests.loader_utils
  6. from lodel.editorial_model.translator import picklefile
  7. from lodel.editorial_model.model import EditorialModel
  8. from lodel.editorial_model.components import *
  9. from lodel.editorial_model.exceptions import *
  10. class PickleFileTestCase(unittest.TestCase):
  11. def test_save(self):
  12. model = EditorialModel("test model", description = "Test EM")
  13. cls1 = model.new_class('testclass1', display_name = 'Classe de test 1', help_text = 'super aide')
  14. c1f1 = cls1.new_field('testfield1', data_handler = 'varchar')
  15. c1f2 = cls1.new_field('testfield2', data_handler = 'varchar')
  16. cls2 = model.new_class('testclass2')
  17. c2f1 = cls2.new_field('testfield1', data_handler = 'varchar')
  18. c2f2 = cls2.new_field('testfield2', data_handler = 'varchar')
  19. grp1 = model.new_group('testgroup1')
  20. grp1.add_components((cls1, c1f1))
  21. grp2 = model.new_group('testgroup2')
  22. grp2.add_components((cls2, c1f2, c2f1, c2f2))
  23. grp2.add_dependencie(grp1)
  24. tmpfd, temp_file = tempfile.mkstemp()
  25. os.close(tmpfd)
  26. os.unlink(temp_file)
  27. model.save(picklefile, filename=temp_file)
  28. new_model = model.load(picklefile, filename=temp_file)
  29. self.assertNotEqual(id(new_model), id(model))
  30. self.assertEqual(new_model.d_hash(), model.d_hash())
  31. os.unlink(temp_file)