def test_construct(self): b = WrapBlock() assert b.indent == 0 assert b.first_offset is None assert b.child_indent == 0 assert b.width is None assert b.top_margin == 0 assert b.bottom_margin == 0 assert b.words == [] assert b._box is None assert not b.is_box_started() assert list(b.get_lines()) == [] b = WrapBlock(1, 2, 3, 4, 5, 6) assert b.indent == 1 assert b.first_offset == 2 assert b.child_indent == 3 assert b.width == 3 assert b.top_margin == 5 assert b.bottom_margin == 6 assert b.words == [] assert b._box is None assert not b.is_box_started() assert b.is_empty()
def test_simple(self): block = WrapBlock(parent_width=20) block.add_text('This paragraph will result in an indented block of') block.add_text('Another top-level paragraph') pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will', 'result in an', 'indented block of', 'Another top-level', 'paragraph' ])
def test_oneline(self, data): block = WrapBlock(parent_width=128) for line in data[:-1]: if isinstance(line, list): block.add_boxed(line[0]) else: block.add_text(line) pytest.g.assert_lines(list(block.get_lines()), [data[-1]])
def test_first_offset(self): block = WrapBlock(first_offset=10, parent_width=30) block.add_text('This paragraph will result in an indented block of') block.add_text('Another top-level paragraph') pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will', 'result in an indented block of', 'Another top-level paragraph' ])
def test_simple_empty_words(self): block = WrapBlock(parent_width=20) # Add empty box. block.start_box() block.end_box() block.add_text('This paragraph will result \nin an indented block of') block.add_text('Another top-level paragraph') pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will', 'result in an', 'indented block of', 'Another top-level', 'paragraph' ])
def test_line_break(self): block = WrapBlock(parent_width=28) block.add_text('This paragraph will result in an indented block') block.add_text('top-') block.add_boxed('\n') # Force line break block.add_text('level paragraph') block.add_boxed('\n') # Force line break block.add_boxed('\n') # Force line break block.add_text('protected text') block.add_boxed('\n') # Force line break block.add_boxed('\n') # Force line break pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will result', 'in an indented block top-', 'level paragraph', '', 'protected text', '', '' ])
def test_box(self): block = WrapBlock(parent_width=28) block.add_text('This paragraph will result in an indented block') block.add_boxed('of Another') block.add_text('top-level paragraph') block.start_box() block.add_text('protected') block.add_text('text') block.end_box() # NOTE: words between start_box() and end_box() is joined without space. pytest.g.assert_lines(list(block.get_lines()), [ 'This paragraph will result', 'in an indented block', 'of Another top-level', 'paragraph protectedtext' ])
def test_combined(self): block = WrapBlock(parent_width=128) block.add_text('Bla (') block.add_boxed(':func:`foo`') block.add_text(').') block.add_text('After test.') block.add_boxed('\n') block.add_boxed('\n') block.add_boxed(':any:`xxx`') block.add_text(', <- must be no space!') block.add_text('...some word') pytest.g.assert_lines(list(block.get_lines()), [ 'Bla (:func:`foo`). After test.', '', ':any:`xxx`, <- must be no space! ...some word', ])
def test_box_long(self): block = WrapBlock(parent_width=8) block.add_boxed('a' * 12) pytest.g.assert_lines(list(block.get_lines()), ['a' * 12])