def it_can_iterate_over_parts_by_walking_rels_graph(self): # +----------+ +--------+ # | pkg_rels |-----> | part_1 | # +----------+ +--------+ # | | ^ # v v | # external +--------+ # | part_2 | # +--------+ part1, part2 = (Mock(name='part1'), Mock(name='part2')) part1.rels = { 1: Mock(name='rel1', is_external=False, target_part=part2) } part2.rels = { 1: Mock(name='rel2', is_external=False, target_part=part1) } pkg = OpcPackage() pkg._rels = { 1: Mock(name='rel3', is_external=False, target_part=part1), 2: Mock(name='rel4', is_external=True), } # verify ----------------------- assert part1 in pkg.iter_parts() assert part2 in pkg.iter_parts() assert len([p for p in pkg.iter_parts()]) == 2
def rels_fixture(self, request, part_1_, part_2_): """ +----------+ +--------+ | pkg_rels |-- r1 --> | part_1 | +----------+ +--------+ | | | ^ r5 | | r4 r2 | | r3 | | | | v | v | external | +--------+ +--------> | part_2 | +--------+ """ r1 = self.rel(request, False, part_1_, "r1") r2 = self.rel(request, False, part_2_, "r2") r3 = self.rel(request, False, part_1_, "r3") r4 = self.rel(request, False, part_2_, "r4") r5 = self.rel(request, True, None, "r5") package = OpcPackage() package._rels = self.rels(request, (r1, r4, r5)) part_1_.rels = self.rels(request, (r2,)) part_2_.rels = self.rels(request, (r3,)) return package, (part_1_, part_2_), (r1, r2, r3, r4, r5)
def it_can_iterate_over_parts_by_walking_rels_graph(self): # +----------+ +--------+ # | pkg_rels |-----> | part_1 | # +----------+ +--------+ # | | ^ # v v | # external +--------+ # | part_2 | # +--------+ part1, part2 = (Mock(name='part1'), Mock(name='part2')) part1.rels = { 1: Mock(name='rel1', is_external=False, target_part=part2) } part2.rels = { 1: Mock(name='rel2', is_external=False, target_part=part1) } pkg = OpcPackage() pkg._rels = { 1: Mock(name='rel3', is_external=False, target_part=part1), 2: Mock(name='rel4', is_external=True), } # verify ----------------------- assert part1 in pkg.iter_parts() assert part2 in pkg.iter_parts() assert len([p for p in pkg.iter_parts()]) == 2
def rels_fixture(self, request, part_1_, part_2_): """ +----------+ +--------+ | pkg_rels |-- r1 --> | part_1 | +----------+ +--------+ | | | ^ r5 | | r4 r2 | | r3 | | | | v | v | external | +--------+ +--------> | part_2 | +--------+ """ r1 = self.rel(request, False, part_1_, "r1") r2 = self.rel(request, False, part_2_, "r2") r3 = self.rel(request, False, part_1_, "r3") r4 = self.rel(request, False, part_2_, "r4") r5 = self.rel(request, True, None, "r5") package = OpcPackage() package._rels = self.rels(request, (r1, r4, r5)) part_1_.rels = self.rels(request, (r2,)) part_2_.rels = self.rels(request, (r3,)) return package, (part_1_, part_2_), (r1, r2, r3, r4, r5)
def related_part_fixture_(self, request, rels_, reltype): related_part_ = instance_mock(request, Part, name='related_part_') rels_.part_with_reltype.return_value = related_part_ pkg = OpcPackage() pkg._rels = rels_ return pkg, reltype, related_part_
def pkg_with_rels_(self, request, rels_): pkg = OpcPackage() pkg._rels = rels_ return pkg
def pkg_with_rels_(self, request, rels_): pkg = OpcPackage() pkg._rels = rels_ return pkg
def related_part_fixture_(self, request, rels_, reltype): related_part_ = instance_mock(request, Part, name="related_part_") rels_.part_with_reltype.return_value = related_part_ pkg = OpcPackage() pkg._rels = rels_ return pkg, reltype, related_part_