def it_initializes_its_rels_collection_on_first_reference( self, RelationshipCollection_ ): pkg = OpcPackage() rels = pkg.rels RelationshipCollection_.assert_called_once_with(PACKAGE_URI.baseURI) assert rels == RelationshipCollection_.return_value
def it_can_provide_a_list_of_the_parts_it_contains(self): # mockery ---------------------- parts = [Mock(name="part1"), Mock(name="part2")] pkg = OpcPackage() # verify ----------------------- with patch.object(OpcPackage, "iter_parts", return_value=parts): assert pkg.parts == [parts[0], parts[1]]
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 it_can_save_to_a_pkg_file(self, pkg_file_, PackageWriter_, parts, parts_): pkg = OpcPackage() pkg.save(pkg_file_) for part in parts_: part.before_marshal.assert_called_once_with() PackageWriter_.write.assert_called_once_with(pkg_file_, pkg._rels, parts_)
def next_partname_fixture(self, request, iter_parts_): existing_partname_numbers, next_partname_number = request.param package = OpcPackage() parts = [ instance_mock( request, Part, name="part[%d]" % idx, partname="/foo/bar/baz%d.xml" % n ) for idx, n in enumerate(existing_partname_numbers) ] iter_parts_.return_value = iter(parts) partname_template = "/foo/bar/baz%d.xml" expected_partname = PackURI("/foo/bar/baz%d.xml" % next_partname_number) return package, partname_template, expected_partname
def pkg_with_rels_(self, request, rels_): pkg = OpcPackage() pkg._rels = rels_ return pkg
def pkg(self, request): return OpcPackage()
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_