|
7 | 7 | from behave import then, when |
8 | 8 |
|
9 | 9 | from docx.shared import Inches |
| 10 | +from docx.table import Table |
10 | 11 |
|
11 | 12 | from .helpers import test_file_path |
12 | 13 |
|
13 | 14 |
|
14 | 15 | # when ==================================================== |
15 | 16 |
|
| 17 | +@when('I add a 2 x 2 table specifying only row and column count') |
| 18 | +def when_add_2x2_table_specifying_only_row_and_col_count(context): |
| 19 | + document = context.document |
| 20 | + document.add_table(rows=2, cols=2) |
| 21 | + |
| 22 | + |
| 23 | +@when('I add a 2 x 2 table specifying style \'foobar\'') |
| 24 | +def when_add_2x2_table_specifying_style_foobar(context): |
| 25 | + document = context.document |
| 26 | + document.add_table(rows=2, cols=2, style='foobar') |
| 27 | + |
| 28 | + |
16 | 29 | @when('I add a heading specifying level={level_str}') |
17 | 30 | def when_add_heading_specifying_level(context, level_str): |
18 | 31 | level = int(level_str) |
@@ -86,6 +99,16 @@ def when_add_picture_specifying_only_image_file(context): |
86 | 99 |
|
87 | 100 | # then ===================================================== |
88 | 101 |
|
| 102 | +@then('the document contains a 2 x 2 table') |
| 103 | +def then_document_contains_2x2_table(context): |
| 104 | + document = context.document |
| 105 | + table = document.tables[-1] |
| 106 | + assert isinstance(table, Table) |
| 107 | + assert len(table.rows) == 2 |
| 108 | + assert len(table.cols) == 2 |
| 109 | + context.table = table |
| 110 | + |
| 111 | + |
89 | 112 | @then('the last paragraph contains only a page break') |
90 | 113 | def then_last_paragraph_contains_only_a_page_break(context): |
91 | 114 | document = context.document |
@@ -162,3 +185,9 @@ def then_style_of_last_paragraph_is_style(context, style): |
162 | 185 | document = context.document |
163 | 186 | p = document.paragraphs[-1] |
164 | 187 | assert p.style == style |
| 188 | + |
| 189 | + |
| 190 | +@then('the table style is \'{style}\'') |
| 191 | +def then_table_style_is_style(context, style): |
| 192 | + table = context.table |
| 193 | + assert table.style == style |
0 commit comments