Пример #1
0
def test_parse_selector():
    assert parse_selector("Paragraph") == Paragraph
    assert parse_selector("Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector("  Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector(" Paragraph /StyledText  ") == Paragraph / StyledText
    assert parse_selector("Paragraph('aa') / StyledText('bb')") \
               == Paragraph.like('aa') / StyledText.like('bb')
    assert parse_selector("Paragraph('aa') / StyledText") \
               == Paragraph.like('aa') / StyledText
    assert parse_selector("Paragraph('aa' ,meh=5) / StyledText") \
               == Paragraph.like('aa', meh=5) / StyledText
    assert parse_selector("Paragraph /    StyledText('bb ') ") \
               == Paragraph / StyledText.like('bb ')
    assert parse_selector("Paragraph('aa') / ... / StyledText(blip ='blop')") \
               == Paragraph.like('aa') / ... / StyledText.like(blip='blop')
    assert parse_selector("  'paragraph' / StyledText")\
               == SelectorByName('paragraph') / StyledText
    assert parse_selector("Paragraph('aa') / ... / 'some style'") \
               == Paragraph.like('aa') / ... / SelectorByName('some style')
Пример #2
0
def test_parse_selector():
    assert parse_selector("Paragraph") == Paragraph
    assert parse_selector("Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector("  Paragraph / StyledText") == Paragraph / StyledText
    assert parse_selector(" Paragraph /StyledText  ") == Paragraph / StyledText
    assert parse_selector("Paragraph('aa') / StyledText('bb')") \
               == Paragraph.like('aa') / StyledText.like('bb')
    assert parse_selector("Paragraph('aa') / StyledText") \
               == Paragraph.like('aa') / StyledText
    assert parse_selector("Paragraph('aa' ,meh=5) / StyledText") \
               == Paragraph.like('aa', meh=5) / StyledText
    assert parse_selector("Paragraph /    StyledText('bb ') ") \
               == Paragraph / StyledText.like('bb ')
    assert parse_selector("Paragraph('aa') / ... / StyledText(blip ='blop')") \
               == Paragraph.like('aa') / ... / StyledText.like(blip='blop')
    assert parse_selector("  'paragraph' / StyledText")\
               == SelectorByName('paragraph') / StyledText
    assert parse_selector("Paragraph('aa') / ... / 'some style'") \
               == Paragraph.like('aa') / ... / SelectorByName('some style')
Пример #3
0
def test_parse_class_selector():
    def helper(string):
        chars = CharIterator(string)
        return parse_class_selector(chars), ''.join(chars)

    assert helper('Paragraph') == (Paragraph, '')
    assert helper('Paragraph   ') == (Paragraph, '   ')
    assert helper('  Paragraph') == (Paragraph, '')
    assert helper('  Paragraph ') == (Paragraph, ' ')
    assert helper('Paragraph()') == (Paragraph.like(), '')
    assert helper('Paragraph(   )') == (Paragraph.like(), '')
    assert helper("Paragraph('style')") == (Paragraph.like('style'), '')
    assert helper("Paragraph('style', "
                  "meh=5)") == (Paragraph.like('style', meh=5), '')
    assert helper(" StyledText('style')  ") == (StyledText.like('style'), '  ')
Пример #4
0
def test_parse_class_selector():
    def helper(string):
        chars = CharIterator(string)
        return parse_class_selector(chars), ''.join(chars)

    assert helper('Paragraph') == (Paragraph, '')
    assert helper('Paragraph   ') == (Paragraph, '   ')
    assert helper('  Paragraph') == (Paragraph, '')
    assert helper('  Paragraph ') == (Paragraph, ' ')
    assert helper('Paragraph()') == (Paragraph.like(), '')
    assert helper('Paragraph(   )') == (Paragraph.like(), '')
    assert helper("Paragraph('style')") == (Paragraph.like('style'), '')
    assert helper("Paragraph('style', "
                  "meh=5)") == (Paragraph.like('style', meh=5), '')
    assert helper(" StyledText('style')  ") == (StyledText.like('style'), '  ')
Пример #5
0
#
# Use of this source code is subject to the terms of the GNU Affero General
# Public License v3. See the LICENSE file or http://www.gnu.org/licenses/.

import pytest

from rinoh.attribute import Var
from rinoh.color import HexColor
from rinoh.dimension import PT, CM
from rinoh.document import DocumentTree, Document, FakeContainer
from rinoh.language import EN
from rinoh.paragraph import Paragraph
from rinoh.text import StyledText, SingleStyledText
from rinoh.style import StyleSheet, StyledMatcher

emphasis_selector = StyledText.like('emphasis')
emphasis2_selector = StyledText.like('emphasis2')
highlight_selector = StyledText.like('highlight')
highlight2_selector = StyledText.like('highlight2')
paragraph_selector = Paragraph
paragraph2_selector = Paragraph.like('paragraph2')
paragraph3_selector = Paragraph.like('paragraph3')
paragraph4_selector = Paragraph.like('paragraph4')
missing_selector = Paragraph.like('missing')

matcher = StyledMatcher({
    'emphasized text': emphasis_selector,
    'emphasized text 2': emphasis2_selector,
    'highlighted text': highlight_selector,
    'highlighted text 2': highlight2_selector,
    'paragraph': paragraph_selector,
Пример #6
0
#
# Copyright (c) Brecht Machiels.
#
# Use of this source code is subject to the terms of the GNU Affero General
# Public License v3. See the LICENSE file or http://www.gnu.org/licenses/.

import pytest

from rinoh.dimension import PT
from rinoh.document import DocumentTree, Document, FakeContainer
from rinoh.language import EN
from rinoh.paragraph import Paragraph
from rinoh.text import StyledText, SingleStyledText
from rinoh.style import StyleSheet, StyledMatcher, Specificity

emphasis_selector = StyledText.like('emphasis')
paragraph_selector = Paragraph

matcher = StyledMatcher({
    'emphasized text': emphasis_selector,
    'paragraph': paragraph_selector,
})

ssheet1 = StyleSheet('base', matcher)
ssheet1('emphasized text', font_slant='italic')
ssheet1('paragraph', space_above=5 * PT)

ssheet2 = StyleSheet('test', base=ssheet1)
ssheet2('paragraph', space_below=10 * PT)

emphasized = SingleStyledText('emphasized', style='emphasis')