def test_get_parents_no_result(self): child = Person(1, "Name") table = Table([child]) parents = table.get_parents(child) assert len(parents) == 2 assert parents[0] == None assert parents[1] == None
def __call__(self, table: Table, target: Person) -> List[Element]: # a) single # - with parent info -> tree(father) # - no parent info -> tree(target) spouse = table.get_spouse(target) if spouse is None: parents = table.get_parents(target) if parents[0] and parents[1]: return self.tree_layout_func(table, parents[0]) else: return self.tree_layout_func(table, target) if target.gender == 'M': husband = target wife = spouse else: husband = spouse wife = target parents1 = table.get_parents(husband) parents2 = table.get_parents(wife) # b) couple, no parents info -> tree(target) if ((parents1[0] is None or parents1[1] is None) and (parents2[0] is None or parents2[1] is None)): return self.tree_layout_func(table, target) # c) couple, with parents info -> butterfly layout children1 = _get_brothers_and_sisters(table, husband) children2 = _get_brothers_and_sisters(table, wife) elements = [] # layout children x = 0 elements, x = self._layout_children(elements, x, table, children1) elements, x = self._layout_children(elements, x, table, [husband]) elements, x = self._layout_children(elements, x, table, children2) # layout parents x = 0 elements, x = self._layout_parents(elements, x, table, parents1, children1 + [husband]) elements, x = self._layout_parents(elements, x, table, parents2, [wife] + children2) return elements
def test_get_parents(self): father = Person(1, "Father") mother = Person(2, "Mother") child = Person(3, "Child", father_id=1, mother_id=2) table = Table([father, mother, child]) parents = table.get_parents(child) assert len(parents) == 2 assert parents[0] == father assert parents[1] == mother
def test_get_parents_key_error(self): child = Person(1, "Child", father_id=999) table = Table([child]) with pytest.raises(KeyError): table.get_parents(child)