示例#1
0
class TestComponent(TestCase):
    def setUp(self):
        self.path = Path()
        self.index_c = Component(self.path, index=1)
        self.name_c = Component(self.path, name="name")

    def test_init_requires_index_or_name(self):
        with self.assertRaises(ValueError):
            Component(self.path)
    def test_init_requires_not_index_and_name(self):
        with self.assertRaises(ValueError):
            Component(self.path, index=1, name="haha")
    def test_is_index(self):
        self.assertTrue(self.index_c.is_index())
        self.assertFalse(self.name_c.is_index())
    def test_to_parent(self):
        p = self.index_c.to_parent()
        self.assertEqual(str(p), '^')
    def test_is_parent(self):
        p = self.index_c.to_parent()
        self.assertTrue(p.is_parent())
        self.assertFalse(self.index_c.is_parent())
    def test_eq(self):
        self.assertFalse(self.index_c == self.name_c)
        self.assertTrue(self.index_c == self.index_c)
        self.assertTrue(self.name_c == self.name_c)
        self.assertTrue(self.index_c == 1)
        self.assertFalse(self.index_c == 2)
        self.assertFalse(self.index_c == '1')
        self.assertTrue(self.name_c == 'name')
        self.assertFalse(self.name_c == 'othername')
示例#2
0
 def content_with_path_component(
         self, component: Component) -> Optional[RuntimeObject]:
     if component.is_index():
         try:
             return self.content[component.index]
         except IndexError:
             return None
     elif component.is_parent():
         return self.parent
     else:
         try:
             return self.named_content[component.name]
         except KeyError:
             raise StoryException("Content {} not found at path {}".format(
                 component.name, self.path))
示例#3
0
 def path_to_first_leaf_content(self) -> Path:
     path = Path()
     container = self
     while container is not None:
         if len(container.content) > 0:
             path.components.append(Component(0))
             container = container.content[0].as_container()
         # This check is not part of the c# source, but is needed to prevent an
         # infinite loop
         else:
             raise ValueError("Unexpectedly found empty container")
     return self.path + path
示例#4
0
 def setUp(self):
     self.empty = Path()
     self.one_path = Path([Component(name='this')])
     self.two_path = Path([Component(name='this'), Component(name='that')])
     self.three_path = Path([
         Component(name='this'),
         Component(name='that'),
         Component(name='other')
     ])
示例#5
0
 def test_init_requires_index_or_name(self):
     with self.assertRaises(ValueError):
         Component(self.path)
示例#6
0
 def setUp(self):
     self.path = Path()
     self.index_c = Component(self.path, index=1)
     self.name_c = Component(self.path, name="name")
示例#7
0
 def test_init_requires_not_index_and_name(self):
     with self.assertRaises(ValueError):
         Component(self.path, index=1, name="haha")
示例#8
0
 def test_contains_named_component(self):
     self.assertFalse(self.empty.contains_named_component())
     ixpath = Path([Component(index=1)])
     self.assertFalse(ixpath.contains_named_component())
     self.assertTrue(self.one_path.contains_named_component())
示例#9
0
 def test_content_with_path_component_for_parent(self):
     self.assertIs(self.named.content_with_path_component(Component(name="^")), self.parent)
示例#10
0
 def test_content_with_path_component_for_name(self):
     self.assertIs(self.parent.content_with_path_component(Component(name="name")), self.named)
示例#11
0
 def test_content_with_path_component_for_index(self):
     self.assertIs(self.parent.content_with_path_component(Component(index=0)), self.named)
     self.assertIs(self.parent.content_with_path_component(Component(index=1)), self.anon)