本文整理汇总了Python中pydocx.test.utils.WordprocessingDocumentFactory类的典型用法代码示例。如果您正苦于以下问题:Python WordprocessingDocumentFactory类的具体用法?Python WordprocessingDocumentFactory怎么用?Python WordprocessingDocumentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WordprocessingDocumentFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_global_run_paragraph_and_character_styles
def test_global_run_paragraph_and_character_styles(self):
style_xml = '''
<style styleId="foo" type="paragraph">
<rPr>
<b val="on"/>
</rPr>
</style>
<style styleId="bar" type="character">
<rPr>
<i val="on"/>
</rPr>
</style>
'''
document_xml = '''
<p>
<pPr>
<pStyle val="foo"/>
</pPr>
<r>
<rPr>
<rStyle val="bar"/>
</rPr>
<t>aaa</t>
</r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '<p><em><strong>aaa</strong></em></p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:34,代码来源:test_property_hierarchy.py
示例2: test_unsupported_instr_content_is_not_ignored
def test_unsupported_instr_content_is_not_ignored(self):
document_xml = '''
<p>
<r><t>AAA</t></r>
<r>
<fldChar fldCharType="begin"/>
</r>
<r>
<instrText> FOOBAR baz</instrText>
</r>
<r>
<fldChar fldCharType="separate"/>
</r>
<r>
<t>BBB</t>
</r>
<r>
<fldChar fldCharType="end"/>
</r>
<r><t>CCC</t></r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '<p>AAABBBCCC</p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:27,代码来源:test_field_code.py
示例3: test_textbox_with_content
def test_textbox_with_content(self):
document_xml = '''
<p>
<r>
<pict>
<shape>
<textbox>
<txbxContent>
<p>
<r>
<t>AAA</t>
</r>
</p>
</txbxContent>
</textbox>
</shape>
</pict>
</r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '''
<p>
<p>
AAA
</p>
</p>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:CenterForOpenScience,项目名称:pydocx,代码行数:32,代码来源:test_textbox.py
示例4: test_spanning_single_paragraph
def test_spanning_single_paragraph(self):
document_xml = '''
<p>
<r><t>Link: </t></r>
<r>
<fldChar fldCharType="begin"/>
</r>
<r>
<instrText> HYPERLINK "http://www.google.com/"</instrText>
</r>
<r>
<fldChar fldCharType="separate"/>
</r>
<r>
<t>AAA</t>
</r>
<r>
<fldChar fldCharType="end"/>
</r>
<r><t>.</t></r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '<p>Link: <a href="http://www.google.com/">AAA</a>.</p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:27,代码来源:test_field_code.py
示例5: test_instr_missing_target
def test_instr_missing_target(self):
document_xml = '''
<p>
<r><t>Link: </t></r>
<r>
<fldChar fldCharType="begin"/>
</r>
<r>
<instrText> HYPERLINK </instrText>
</r>
<r>
<fldChar fldCharType="separate"/>
</r>
<r>
<t>AAA</t>
</r>
<r>
<fldChar fldCharType="end"/>
</r>
<r><t>.</t></r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '<p>Link: AAA.</p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:27,代码来源:test_field_code.py
示例6: test_cell_with_character_styles_applied
def test_cell_with_character_styles_applied(self):
document_xml = '''
<tbl>
<tr>
<tc>
<p>
<r>
<rPr>
<b />
<i />
</rPr>
<t>Foo</t>
</r>
</p>
</tc>
</tr>
</tbl>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '''
<table border="1">
<tr>
<td><em><strong>Foo</strong></em></td>
</tr>
</table>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:30,代码来源:test_tables.py
示例7: test_one_row_one_cell_with_whitespace_after_other_paragraph
def test_one_row_one_cell_with_whitespace_after_other_paragraph(self):
document_xml = '''
<tbl>
<tr>
<tc>
<p>
<r><t>Foo</t></r>
</p>
<p>
<r><t> </t></r>
</p>
</tc>
</tr>
</tbl>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '''
<table border="1">
<tr>
<td>Foo</td>
</tr>
</table>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:27,代码来源:test_tables.py
示例8: test_heading_with_bookmark
def test_heading_with_bookmark(self):
document_xml = '''
<p>
<pPr>
<pStyle val="heading1"/>
</pPr>
<bookmarkStart name="testing"/>
<bookmarkEnd/>
<r>
<t>aaa</t>
</r>
</p>
'''
style_xml = '''
<style styleId="heading1" type="paragraph">
<name val="Heading 1"/>
</style>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '<h1 id="testing">aaa</h1>'
self.assert_document_generates_html(document, expected_html)
开发者ID:CenterForOpenScience,项目名称:pydocx,代码行数:26,代码来源:test_heading.py
示例9: test_style_chain_ends_when_loop_is_detected
def test_style_chain_ends_when_loop_is_detected(self):
style_xml = '''
<style styleId="one">
<basedOn val="three"/>
<rPr>
<b val="on"/>
</rPr>
</style>
<style styleId="two">
<basedOn val="one"/>
</style>
<style styleId="three">
<basedOn val="two"/>
</style>
'''
document_xml = '''
<p>
<pPr>
<pStyle val="three"/>
</pPr>
<r>
<t>aaa</t>
</r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '<p><strong>aaa</strong></p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:33,代码来源:test_style_based_on.py
示例10: test_styles_are_ignored
def test_styles_are_ignored(self):
style_xml = '''
<style styleId="heading1" type="paragraph">
<name val="Heading 1"/>
<rPr>
<b val="on"/>
<caps val="on"/>
<smallCaps val="on"/>
<strike val="on"/>
<dstrike val="on"/>
</rPr>
</style>
'''
document_xml = '''
<p>
<pPr>
<pStyle val="heading1"/>
</pPr>
<fldSimple instr="FOO bar">
<r>
<t>AAA</t>
</r>
</fldSimple>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '''
<h1>AAA</h1>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:34,代码来源:test_simple_field.py
示例11: test_multiple_runs
def test_multiple_runs(self):
document_xml = '''
<p>
<fldSimple instr="HYPERLINK http://www.google.com">
<r>
<rPr>
<b />
</rPr>
<t>AAA</t>
</r>
<r>
<rPr>
<i />
</rPr>
<t>BBB</t>
</r>
</fldSimple>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '''
<p>
<a href="http://www.google.com">
<strong>AAA</strong>
<em>BBB</em>
</a>
</p>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:31,代码来源:test_simple_field.py
示例12: test_entity_blowup
def test_entity_blowup(self):
try:
import defusedxml
except ImportError:
defusedxml = None
if defusedxml is None:
raise SkipTest('This test case only applies when using defusedxml')
document_xml = '''
<p>
<r>
<t>&a;</t>
</r>
</p>
'''
xml_header = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml [
<!ENTITY a "123">
]>
'''
document = WordprocessingDocumentFactory(xml_header=xml_header)
document.add(MainDocumentPart, document_xml)
expected_html = '<p>123</p>'
try:
self.assert_document_generates_html(document, expected_html)
raise AssertionError(
'Expected "EntitiesForbidden" exception did not occur',
)
except defusedxml.EntitiesForbidden:
pass
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:32,代码来源:test_xml_vulnerabilities.py
示例13: test_character_stylings_are_ignored
def test_character_stylings_are_ignored(self):
# Even though the heading1 style has bold enabled, it's being ignored
# because the style is for a header
style_xml = '''
<style styleId="heading1" type="paragraph">
<name val="Heading 1"/>
<rPr>
<b val="on"/>
</rPr>
</style>
'''
document_xml = '''
<p>
<pPr>
<pStyle val="heading1"/>
</pPr>
<r>
<t>aaa</t>
</r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '''
<h1>aaa</h1>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:swiperthefox,项目名称:pydocx,代码行数:31,代码来源:test_heading.py
示例14: test_with_line_break
def test_with_line_break(self):
document_xml = """
<p>
<hyperlink id="foobar">
<r>
<t>li</t>
<br />
<t>nk</t>
</r>
</hyperlink>
<r>
<t>.</t>
</r>
</p>
"""
document = WordprocessingDocumentFactory()
document_rels = document.relationship_format.format(
id="foobar", type="foo/hyperlink", target="http://google.com", target_mode="External"
)
document.add(MainDocumentPart, document_xml, document_rels)
expected_html = '<p><a href="http://google.com">li<br />nk</a>.</p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:IuryAlves,项目名称:pydocx,代码行数:25,代码来源:test_hyperlink.py
示例15: test_sub_detected_pStyle_has_smaller_size_and_negative_position
def test_sub_detected_pStyle_has_smaller_size_and_negative_position(self):
document_xml = '''
<p>
<pPr>
<pStyle val="faked_subscript"/>
</pPr>
<r>
<t>H</t>
</r>
<r>
<rPr>
<position val="-8"/>
<sz val="19"/>
</rPr>
<t>2</t>
</r>
<r>
<t>O</t>
</r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, self.style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '<p>H<sub>2</sub>O</p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:CenterForOpenScience,项目名称:pydocx,代码行数:28,代码来源:test_faked_superscript_and_subscript.py
示例16: test_basedon_ignored_for_character_based_on_paragraph
def test_basedon_ignored_for_character_based_on_paragraph(self):
# character styles may only be based on other character styles
# otherwise, the based on specification should be ignored
style_xml = '''
<style styleId="one" type="paragraph">
<rPr>
<b val="on"/>
</rPr>
</style>
<style styleId="two" type="character">
<basedOn val="one"/>
<rPr>
<i val="on"/>
</rPr>
</style>
'''
document_xml = '''
<p>
<r>
<rPr>
<rStyle val="two"/>
</rPr>
<t>aaa</t>
</r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '<p><em>aaa</em></p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:34,代码来源:test_style_based_on.py
示例17: test_no_sub_detected_because_local_size_larger_than_pStyle_size
def test_no_sub_detected_because_local_size_larger_than_pStyle_size(self):
document_xml = '''
<p>
<pPr>
<pStyle val="faked_subscript"/>
</pPr>
<r>
<t>H</t>
</r>
<r>
<rPr>
<position val="-8"/>
<sz val="30"/>
</rPr>
<t>2</t>
</r>
<r>
<t>O</t>
</r>
</p>
'''
document = WordprocessingDocumentFactory()
document.add(StyleDefinitionsPart, self.style_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '<p>H2O</p>'
self.assert_document_generates_html(document, expected_html)
开发者ID:CenterForOpenScience,项目名称:pydocx,代码行数:28,代码来源:test_faked_superscript_and_subscript.py
示例18: test_root_level_upperRoman_list_not_converted_to_heading
def test_root_level_upperRoman_list_not_converted_to_heading(self):
document_xml = ''.join([
self.list_item.format(
content='AAA',
num_id=1,
level=0,
),
])
numbering_xml = '''
<num numId="1">
<abstractNumId val="1"/>
</num>
<abstractNum abstractNumId="1">
<lvl ilvl="0">
<numFmt val="upperRoman"/>
</lvl>
</abstractNum>
'''
document = WordprocessingDocumentFactory()
document.add(NumberingDefinitionsPart, numbering_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '<h2>AAA</h2>'
self.assert_document_generates_html(document, expected_html)
开发者ID:swiperthefox,项目名称:pydocx,代码行数:26,代码来源:test_convert_root_upper_roman_list_to_heading.py
示例19: test_one_row_one_cell_multiple_paragraphs
def test_one_row_one_cell_multiple_paragraphs(self):
document_xml = '''
<tbl>
<tr>
<tc>
<p>
<r>
<t>Foo</t>
</r>
</p>
<p>
<r>
<t>Bar</t>
</r>
</p>
</tc>
</tr>
</tbl>
'''
document = WordprocessingDocumentFactory()
document.add(MainDocumentPart, document_xml)
expected_html = '''
<table border="1">
<tr>
<td>Foo<br />Bar</td>
</tr>
</table>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:AndrewSallans,项目名称:pydocx,代码行数:31,代码来源:test_tables.py
示例20: test_root_level_decimal_list_not_converted_to_heading
def test_root_level_decimal_list_not_converted_to_heading(self):
document_xml = ''.join([
self.list_item.format(
content='AAA',
num_id=1,
level=0,
),
])
numbering_xml = '''
<num numId="1">
<abstractNumId val="1"/>
</num>
<abstractNum abstractNumId="1">
<lvl ilvl="0">
<numFmt val="decimal"/>
</lvl>
</abstractNum>
'''
document = WordprocessingDocumentFactory()
document.add(NumberingDefinitionsPart, numbering_xml)
document.add(MainDocumentPart, document_xml)
expected_html = '''
<ol class="pydocx-list-style-type-decimal">
<li>AAA</li>
</ol>
'''
self.assert_document_generates_html(document, expected_html)
开发者ID:swiperthefox,项目名称:pydocx,代码行数:30,代码来源:test_convert_root_upper_roman_list_to_heading.py
注:本文中的pydocx.test.utils.WordprocessingDocumentFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论