File: block.py

package info (click to toggle)
python-docx 0.8.11%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,640 kB
  • sloc: xml: 25,311; python: 21,911; makefile: 168
file content (53 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# encoding: utf-8

"""
Step implementations for block content containers
"""

from behave import given, then, when

from docx import Document
from docx.table import Table

from helpers import test_docx


# given ===================================================

@given('a document containing a table')
def given_a_document_containing_a_table(context):
    context.document = Document(test_docx('blk-containing-table'))


@given('a paragraph')
def given_a_paragraph(context):
    context.document = Document()
    context.paragraph = context.document.add_paragraph()


# when ====================================================

@when('I add a paragraph')
def when_add_paragraph(context):
    document = context.document
    context.p = document.add_paragraph()


@when('I add a table')
def when_add_table(context):
    rows, cols = 2, 2
    context.document.add_table(rows, cols)


# then =====================================================

@then('I can access the table')
def then_can_access_table(context):
    table = context.document.tables[-1]
    assert isinstance(table, Table)


@then('the new table appears in the document')
def then_new_table_appears_in_document(context):
    table = context.document.tables[-1]
    assert isinstance(table, Table)