def test_styledtext_from_string_field(): assert StyledText.from_string("'{SECTION_NUMBER(7)}' (style)") \ == Field(SECTION_NUMBER(7), style='style') assert StyledText.from_string("'abc {NUMBER_OF_PAGES}' (style)") \ == MixedStyledText([SingleStyledText('abc '), Field(NUMBER_OF_PAGES)], style='style') assert StyledText.from_string("'{PAGE_NUMBER}abc' (style)") \ == MixedStyledText([Field(PAGE_NUMBER), SingleStyledText('abc')], style='style') assert StyledText.from_string("'one{nbsp}two{SECTION_TITLE(1)}'") \ == MixedStyledText([SingleStyledText('one\N{NO-BREAK SPACE}two'), Field(SECTION_TITLE(1))]) assert StyledText.from_string("'one{PAGE_NUMBER}'(style1) 'moh'(style2)") \ == MixedStyledText([MixedStyledText([SingleStyledText('one'), Field(PAGE_NUMBER)], style='style1'), SingleStyledText('moh', style='style2')]) assert StyledText.from_string("'{SectionTitles.chapter}abc' (style)") \ == MixedStyledText([StringField(SectionTitles, 'chapter'), SingleStyledText('abc')], style='style') assert StyledText.from_string("'1{AdmonitionTitles.warning}2' (style)") \ == MixedStyledText([SingleStyledText('1'), StringField(AdmonitionTitles, 'warning'), SingleStyledText('2')], style='style') assert StyledText.from_string("'{UserStrings.my_string}abc' (style)") \ == MixedStyledText([StringField(UserStrings, 'my_string'), SingleStyledText('abc')], style='style')
def test_styledtext_from_string_inline_image(): assert StyledText.from_string("IMAGE('images/image.pdf')") \ == InlineImage('images/image.pdf') assert StyledText.from_string("image('images/image.pdf', scale = 2.3)") \ == InlineImage('images/image.pdf', scale=2.3) assert StyledText.from_string("iMAGe('images/image.pdf' ,baseline=10 %)") \ == InlineImage('images/image.pdf', baseline=10*PERCENT) assert StyledText.from_string("Image('space image.pdf',baseline=10 %, " " scale=0.8 , width= 5 in, rotate=45)") \ == InlineImage('space image.pdf', scale=0.8, baseline=10*PERCENT, width=5*INCH, rotate=45) assert StyledText.from_string("'Text with an ' (a) IMAGE('image.png') " "' in the middle.'(b)") \ == MixedStyledText([SingleStyledText('Text with an ', style='a'), InlineImage('image.png'), SingleStyledText(' in the middle.', style='b')])
def test_styledtext_from_string(): assert StyledText.from_string("'one'") \ == MixedStyledText([SingleStyledText('one')]) assert StyledText.from_string("'on\\'e'") \ == MixedStyledText([SingleStyledText("on'e")]) assert StyledText.from_string("'one' 'two'") \ == MixedStyledText([SingleStyledText('one'), SingleStyledText('two')]) assert StyledText.from_string("'one'(style1)") \ == MixedStyledText([SingleStyledText('one', style='style1')]) assert StyledText.from_string("'one' (style1)") \ == MixedStyledText([SingleStyledText('one', style='style1')]) assert StyledText.from_string("'one'(style1) 'two'") \ == MixedStyledText([SingleStyledText('one', style='style1'), SingleStyledText('two')]) assert StyledText.from_string("'one'\t(style1) 'two'(style2)") \ == MixedStyledText([SingleStyledText('one', style='style1'), SingleStyledText('two', style='style2')]) assert StyledText.from_string("'one{nbsp}two'") \ == MixedStyledText([SingleStyledText('one\N{NO-BREAK SPACE}two')]) assert StyledText.from_string("'one' '{gt}two'(style2)") \ == MixedStyledText([SingleStyledText('one'), SingleStyledText('>two', style='style2')])
def test_styledtext_from_string_field(): assert StyledText.from_string("'{SECTION_NUMBER(7)}' (style)") \ == Field(SECTION_NUMBER(7), style='style') assert StyledText.from_string("'abc {NUMBER_OF_PAGES}' (style)") \ == MixedStyledText([SingleStyledText('abc '), Field(NUMBER_OF_PAGES)], style='style') assert StyledText.from_string("'{PAGE_NUMBER}abc' (style)") \ == MixedStyledText([Field(PAGE_NUMBER), SingleStyledText('abc')], style='style') assert StyledText.from_string("'one{nbsp}two{SECTION_TITLE(1)}'") \ == MixedStyledText([SingleStyledText('one\N{NO-BREAK SPACE}two'), Field(SECTION_TITLE(1))]) assert StyledText.from_string("'one{PAGE_NUMBER}'(style1) 'moh'(style2)") \ == MixedStyledText([MixedStyledText([SingleStyledText('one'), Field(PAGE_NUMBER)], style='style1'), SingleStyledText('moh', style='style2')]) assert StyledText.from_string("'{SectionTitles.chapter}abc' (style)") \ == MixedStyledText([StringField(SectionTitles, 'chapter'), SingleStyledText('abc')], style='style') assert StyledText.from_string("'1{AdmonitionTitles.warning}2' (style)") \ == MixedStyledText([SingleStyledText('1'), StringField(AdmonitionTitles, 'warning'), SingleStyledText('2')], style='style')
def test_styledtext_from_string(): assert StyledText.from_string("'one'") == SingleStyledText('one') assert StyledText.from_string("'on\\'e'") == SingleStyledText("on'e") assert StyledText.from_string("'''with\nnewline'''") \ == SingleStyledText('with\nnewline') assert StyledText.from_string("'one' 'two'") \ == MixedStyledText([SingleStyledText('one'), SingleStyledText('two')]) assert StyledText.from_string("'one''two'") \ == MixedStyledText([SingleStyledText('one'), SingleStyledText('two')]) assert StyledText.from_string("'one'\n'two'") \ == MixedStyledText([SingleStyledText('one'), SingleStyledText('two')]) assert StyledText.from_string("'one'(style1)") \ == SingleStyledText('one', style='style1') assert StyledText.from_string("'one' (style1)") \ == SingleStyledText('one', style='style1') assert StyledText.from_string("'one'(style 1)") \ == SingleStyledText('one', style='style 1') assert StyledText.from_string("'one'(style 1)") \ == SingleStyledText('one', style='style 1') assert StyledText.from_string("'one'( style 1 )") \ == SingleStyledText('one', style='style 1') assert StyledText.from_string("'one'(style1) 'two'") \ == MixedStyledText([SingleStyledText('one', style='style1'), SingleStyledText('two')]) assert StyledText.from_string("'one'\t(style1) 'two'(style2)") \ == MixedStyledText([SingleStyledText('one', style='style1'), SingleStyledText('two', style='style2')]) assert StyledText.from_string("'one{nbsp}two'") \ == SingleStyledText('one\N{NO-BREAK SPACE}two') assert StyledText.from_string("'one' '{gt}two'(style2)") \ == MixedStyledText([SingleStyledText('one'), SingleStyledText('>two', style='style2')])