def it_can_construct_a_default_styles_part_to_help(self): package = OpcPackage() styles_part = StylesPart.default(package) assert isinstance(styles_part, StylesPart) assert styles_part.partname == '/word/styles.xml' assert styles_part.content_type == CT.WML_STYLES assert styles_part.package is package assert len(styles_part.element) == 6
def styles_part(self): """ Instance of |StylesPart| for this document. Creates an empty styles part if one is not present. """ try: return self._document_part.part_related_by(RT.STYLES) except KeyError: styles_part = StylesPart.new() self._document_part.relate_to(styles_part, RT.STYLES) return styles_part
def it_can_be_constructed_by_opc_part_factory(self, construct_fixture): (partname_, content_type_, blob_, package_, parse_xml_, init__, styles_elm_) = construct_fixture # exercise --------------------- styles_part = StylesPart.load(partname_, content_type_, blob_, package_) # verify ----------------------- parse_xml_.assert_called_once_with(blob_) init__.assert_called_once_with(partname_, content_type_, styles_elm_, package_) assert isinstance(styles_part, StylesPart)
def styles_part(self): """ Instance of |StylesPart| for this document. Creates an empty styles part if one is not present. """ try: return self._document_part.part_related_by(RT.STYLES) except KeyError: styles_part = StylesPart.new() self._document_part.relate_to(styles_part, RT.STYLES) return styles_part @lazyproperty def header_part(self, section=None): """ Instance of |HeaderPart| for this document. Takes a section argument. If none is passed, assumes default (sentinel) Section. Creates an empty header part if one is not present. """ if not section: section = self.sections()[0] try: return self._document_part.part_related_by(RT.HEADER) except KeyError: header_part = HeaderPart.new() self._document_part.relate_to(header_part, RT.HEADER) return header_part @property def tables(self): """ A list of |Table| instances corresponding to the tables in the document, in document order. Note that tables within revision marks such as ``<w:ins>`` or ``<w:del>`` do not appear in this list. """ return self._document_part.tables @staticmethod def _open(docx): """ Return a (document_part, package) 2-tuple loaded from *docx*, where *docx* can be either a path to a ``.docx`` file (a string) or a file-like object. If *docx* is ``None``, the built-in default document "template" is loaded. """ docx = _default_docx_path if docx is None else docx package = Package.open(docx) document_part = package.main_document if document_part.content_type != CT.WML_DOCUMENT_MAIN: tmpl = "file '%s' is not a Word file, content type is '%s'" raise ValueError(tmpl % (docx, document_part.content_type)) return document_part, package
def it_can_be_constructed_by_opc_part_factory(self, construct_fixture): (partname_, content_type_, blob_, package_, parse_xml_, init__, styles_elm_) = construct_fixture # exercise --------------------- styles_part = StylesPart.load( partname_, content_type_, blob_, package_ ) # verify ----------------------- parse_xml_.assert_called_once_with(blob_) init__.assert_called_once_with( partname_, content_type_, styles_elm_, package_ ) assert isinstance(styles_part, StylesPart)
def styles_fixture(self, Styles_, styles_elm_, styles_): styles_part = StylesPart(None, None, styles_elm_, None) return styles_part, Styles_, styles_