test_links.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import unittest
  2. from . import test_samplefile as samplefile
  3. class TestLinks(unittest.TestCase):
  4. def setUp(self):
  5. self.doc = samplefile.SampleFileCreator().create_document()
  6. # for s in self.doc: xmlparser.dump_section(s)
  7. def test_link_creation(self):
  8. obj = self.doc.sections[0].sections[0]
  9. dst = self.doc.sections[1].sections[1]
  10. self.assertNotEqual(obj, dst)
  11. obj.link = "/sec 1/sec 1,1"
  12. self.assertIsNot(obj, dst)
  13. self.assertEqual(obj.sections, dst.sections)
  14. self.assertEqual(obj.properties, dst.properties)
  15. obj.clean()
  16. self.assertNotEqual(obj, dst)
  17. def no_test_circles(self):
  18. # TODO this currently just works, although, maybe it shouldn't?
  19. # we cannot allow self-referencing links
  20. obj = self.doc.sections[0].sections[0]
  21. dst = self.doc.sections[0]
  22. samplefile.dumper.dump_section(dst)
  23. obj.link = "/sec 0"
  24. # self.assertEqual(obj.sections, dst.sections) # this will FAIL
  25. # self.assertEqual(obj.properties, dst.properties)
  26. obj.clean()
  27. samplefile.dumper.dump_section(dst)
  28. def test_merge(self):
  29. obj = self.doc.sections[0].sections[0] # must be an empty section
  30. dst = self.doc.sections[1] # .sections[1]
  31. org = obj.clone()
  32. obj.link = '/sec 1'
  33. self.assertEqual(obj.sections, dst.sections)
  34. self.assertEqual(obj.properties, dst.properties)
  35. self.assertEqual(obj._merged, dst)
  36. obj.clean()
  37. self.assertIsNone(obj._merged)
  38. self.assertEqual(obj.sections, org.sections)
  39. self.assertEqual(obj.properties, org.properties)