本文整理汇总了Python中rtfng.utils.RTFTestCase类的典型用法代码示例。如果您正苦于以下问题:Python RTFTestCase类的具体用法?Python RTFTestCase怎么用?Python RTFTestCase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RTFTestCase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_paraTabs
def make_paraTabs():
doc, section, styles = RTFTestCase.initializeDoc()
p = Paragraph()
p.append(
"The paragraph itself can also be overridden in lots of ways: "
"tabs, borders, alignment, etc., can all be modified either in "
"the style or as an override during the creation of the "
"paragraph. This is demonstrated below with custom tab widths "
"and embedded carriage returns (i.e., new line markers that do "
"not cause a paragraph break)."
)
section.append(p)
tabs = [
TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH),
TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH * 2),
TabPropertySet(width=TabPropertySet.DEFAULT_WIDTH),
]
para_props = ParagraphPropertySet(tabs=tabs)
p = Paragraph(styles.ParagraphStyles.Normal, para_props)
p.append(
"Phrase at Left Tab",
TAB,
"Middle Phrase One",
TAB,
"Right Phrase",
LINE,
"Second Left Phrase",
TAB,
"Middle Phrase Two",
TAB,
"Another Right Phrase",
)
section.append(p)
return doc
示例2: make_docCopy
def make_docCopy():
doc, section, styles = RTFTestCase.initializeDoc()
section.append('First section')
secondSection = doc.NewSection()
secondSection.append('Second section.')
copyDoc = doc.Copy()
return doc
示例3: test_CustomElementInsidePara
def test_CustomElementInsidePara(self):
# It's just too hard to write a standard test with a custom renderer.
doc, section, styles = RTFTestCase.initializeDoc()
p = Paragraph()
p.append('This is a standard paragraph with the default style.')
class CustomClass(object):
pass
p.append(CustomClass())
section.append(p)
# Define renderer with custom element support.
specialString = "ABC I'm unique"
def customElementWriter(renderer, element):
renderer._write(specialString)
r = Renderer(write_custom_element_callback=customElementWriter)
# Render with custom element.
result = StringIO()
r.Write(doc, result)
testData = result.getvalue()
result.close()
# Confirm generate result has custom rendering.
assert specialString in testData
示例4: make_pictures
def make_pictures():
doc, section, styles = RTFTestCase.initializeDoc()
# text can be added directly to the section a paragraph object is create as needed
section.append( 'Image Example 1' )
section.append( 'You can add images in one of two ways, either converting the '
'image each and every time like;' )
image = Image( 'examples/image.jpg' )
section.append( Paragraph( image ) )
section.append( 'Or you can use the image object to convert the image and then '
'save it to a raw code element that can be included later.' )
# Test RawCode -- split into separate test?
rawCodeDecl = image.ToRawCode('TEST_IMAGE')
assert rawCodeDecl.startswith('TEST_IMAGE = RawCode( """')
assert rawCodeDecl.endswith('""" )')
rawCode = RawCode(image.Data)
section.append(rawCode)
section.append('The above picture was displayed from a RawCode object without a Paragraph wrapper.')
section.append( 'Here are some png files' )
for f in [ 'examples/img1.png',
'examples/img2.png',
'examples/img3.png',
'examples/img4.png' ] :
section.append( Paragraph( Image( f ) ) )
return doc
示例5: make_charFrame
def make_charFrame():
doc, section, styles = RTFTestCase.initializeDoc()
p = Paragraph()
thinEdge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=styles.Colours.Blue)
textWithFrame = TextPropertySet(frame=thinEdge)
p.append(Text('This tests frame drawn around text.', textWithFrame))
section.append(p)
return doc
示例6: make_charTab
def make_charTab():
doc, section, styles = RTFTestCase.initializeDoc()
p = Paragraph()
p.append('Before tab')
p.append(Text(TAB))
p.append('After tab')
section.append(p)
return doc
示例7: make_sectionWithParas
def make_sectionWithParas():
doc, section, styles = RTFTestCase.initializeDoc()
section.append('Small paragraph.')
section.append('')
# a lot of useful documents can be created with little more than this
section.append(
'A lot of useful documents can be created in this way. More '
'advanced formatting is available, but a lot of users just want '
'to see their data in something other than a text file.')
return doc
示例8: make_paraNormal
def make_paraNormal():
doc, section, styles = RTFTestCase.initializeDoc()
p1 = Paragraph(styles.ParagraphStyles.Heading1)
p1.append('Heading 1')
section.append(p1)
p2 = Paragraph(styles.ParagraphStyles.Normal)
p2.append(
'In this case we have used two styles. The first paragraph is '
'marked with the Heading1 style, and this one is marked with the '
'Normal style.')
section.append(p2)
return doc
示例9: make_hyperlinks
def make_hyperlinks():
doc, section, styles = RTFTestCase.initializeDoc()
p = Paragraph()
p.append('This is a standard paragraph with the default style.')
p = Paragraph()
p.append('This is also a standard paragraph. ',
'But lets add a ',
TEXT('Washington Post', hyperlink='https://washingtonpost.com'),
' hyperlink to this paragraph. ',
)
section.append(p)
return doc
示例10: make_tableHorizontalCellMerge
def make_tableHorizontalCellMerge():
doc, section, styles = RTFTestCase.initializeDoc()
section.append( 'Table with Horizontal Cells Merged' )
table = Table( TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 )
table.AddRow( Cell( 'A-one' ), Cell( 'A-two' ), Cell( 'A-three' ) )
table.AddRow( Cell( 'A-one' ), Cell( 'A-two', span=2 ) )
table.AddRow( Cell( 'A-one', span=3 ) )
table.AddRow( Cell( 'A-one' ), Cell( 'A-two' ), Cell( 'A-three' ) )
table.AddRow( Cell( 'A-one', span=2 ), Cell( 'A-two' ) )
section.append( table )
return doc
示例11: test_documentWrite
def test_documentWrite(self):
doc, section, styles = RTFTestCase.initializeDoc()
fd, filename = tempfile.mkstemp(prefix='test-pyrtf', suffix='.rtf')
os.close(fd)
doc.write(filename)
result = StringIO.StringIO()
doc.write(result)
assert open(filename, 'r').read() == result.getvalue()
os.remove(filename)
示例12: test_ExceptionOnUnknownElement
def test_ExceptionOnUnknownElement(self):
# Create document with unknown element type.
doc, section, styles = RTFTestCase.initializeDoc()
class CustomClass(object):
pass
section.append(CustomClass())
# Try to render.
r = Renderer()
result = StringIO()
self.assertRaises(Exception, r.Write, doc, result)
示例13: make_tableFlowRightToLeft
def make_tableFlowRightToLeft():
doc, section, styles = RTFTestCase.initializeDoc()
section.append( 'Table with content flowing right to left' )
table = Table( TableTestCase.col4, TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 )
table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ),
Cell( 'This is pretty amazing', flow=Cell.FLOW_RL_TB, start_vertical_merge=True ) )
for i in range( 10 ) :
table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ),
Cell( vertical_merge=True ))
section.append( table )
return doc
示例14: make_charStyleOverride
def make_charStyleOverride():
doc, section, styles = RTFTestCase.initializeDoc()
p = Paragraph()
p.append('This is a standard paragraph with the default style.')
p = Paragraph()
p.append('It is also possible to manully override a style. ',
'This is a change of just the font ',
TEXT('size', size=48),
' an this is for just the font ',
TEXT('typeface', font=styles.Fonts.Impact) ,
'.')
section.append(p)
return doc
示例15: make_paraIndents
def make_paraIndents():
doc, section, styles = RTFTestCase.initializeDoc()
section.append(
"The paragraphs below demonstrate the flexibility , the following is all at the "
"same indent level and the one after it has the first line at a "
"different indent to the rest. The third has the first line "
"going in the other direction and is also separated by a page "
"break. Note that the FirstLineIndent is defined as being the "
"difference from the LeftIndent."
)
creditURL = "http://www.shakespeare-online.com/plots/1kh4ps.html"
section.append("(Paragraph text from %s.)" % creditURL)
sampleParagraph = """The play opens one year after the death of Richard
II, and King Henry is making plans for a crusade to the
Holy Land to cleanse himself of the guilt he feels over the
usurpation of Richard's crown. But the crusade must be postponed
when Henry learns that Welsh rebels, led by Owen Glendower, have
defeated and captured Mortimer. Although the brave Henry Percy,
nicknamed Hotspur, has quashed much of the uprising, there is still
much trouble in Scotland. King Henry has a deep admiration for
Hotspur and he longs for his own son, Prince Hal, to
display some of Hotspur's noble qualities. Hal is more comfortable
in a tavern than on the battlefield, and he spends his days
carousing with riff-raff in London. But King Henry also has his
problems with the headstrong Hotspur, who refuses to turn over his
prisoners to the state as he has been so ordered.
Westmoreland tells King Henry that Hotspur has many of
the traits of his uncle, Thomas Percy, the Earl of Worcester, and
defying authority runs in the family."""
sampleParagraph = re.sub("\s+", " ", sampleParagraph)
para_props = ParagraphPropertySet()
para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3)
p = Paragraph(styles.ParagraphStyles.Normal, para_props)
p.append(sampleParagraph)
section.append(p)
para_props = ParagraphPropertySet()
para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH * -2)
para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 3)
p = Paragraph(styles.ParagraphStyles.Normal, para_props)
p.append(sampleParagraph)
section.append(p)
para_props = ParagraphPropertySet()
para_props.SetFirstLineIndent(TabPropertySet.DEFAULT_WIDTH)
para_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH)
p = Paragraph(styles.ParagraphStyles.Normal, para_props)
p.append(sampleParagraph)
section.append(p)
return doc