test_find_section.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import unittest
  2. from odml import Section
  3. class TestFindSections(unittest.TestCase):
  4. def setUp(self):
  5. self.root_section = Section("Type test", "test")
  6. self.root_section.append(Section("sub_1", "sub_1"))
  7. self.root_section.append(Section("sub_2", "sub_2"))
  8. self.root_section.append(Section("sub_2_b", "sub_2"))
  9. self.root_section.append(Section("sub_3", "sub_2/sub_3"))
  10. def test_find_by_name(self):
  11. ret = self.root_section.find("sub_1")
  12. self.assertTrue(ret.name == "sub_1")
  13. ret = self.root_section.find("unknown_type")
  14. self.assertIsNone(ret)
  15. def test_find_by_type(self):
  16. ret = self.root_section.find(type="sub_1")
  17. self.assertTrue(ret is not None and ret.type == "sub_1")
  18. ret = self.root_section.find(type="sub_2", findAll=True)
  19. self.assertTrue(len(ret) == 2)
  20. ret = self.root_section.find(key=None, type="sub_2", findAll=True,
  21. include_subtype=True)
  22. self.assertTrue(len(ret) == 3)
  23. def test_find_by_name_and_type(self):
  24. ret = self.root_section.find(key="sub_1", type="sub_1")
  25. self.assertTrue(ret.name == "sub_1")
  26. ret = self.root_section.find(key="sub_1", type="sub_2")
  27. self.assertIsNone(ret)