Skip to content

Commit 0d4f9f3

Browse files
author
Steve Canny
committed
acpt: add tbl-style.feature
1 parent ee184a8 commit 0d4f9f3

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

features/steps/table.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from __future__ import absolute_import, print_function, unicode_literals
88

9-
from behave import given, then
9+
from behave import given, then, when
1010

1111
from docx import Document
1212
from docx.table import (
@@ -47,6 +47,18 @@ def given_a_row_collection_having_two_rows(context):
4747
context.rows = document.body.tables[0].rows
4848

4949

50+
@given('a table')
51+
def given_a_table(context):
52+
context.table_ = Document().body.add_table(rows=2, cols=2)
53+
54+
55+
@given('a table having an applied style')
56+
def given_a_table_having_an_applied_style(context):
57+
docx_path = test_docx('tbl-having-applied-style')
58+
document = Document(docx_path)
59+
context.table_ = document.body.tables[0]
60+
61+
5062
@given('a table having two columns')
5163
def given_a_table_having_two_columns(context):
5264
docx_path = test_docx('blk-containing-table')
@@ -77,6 +89,14 @@ def given_a_table_row_having_two_cells(context):
7789
context.row = document.body.tables[0].rows[0]
7890

7991

92+
# when =====================================================
93+
94+
@when('I apply a style to the table')
95+
def when_apply_style_to_table(context):
96+
table = context.table_
97+
table.style = 'LightShading-Accent1'
98+
99+
80100
# then =====================================================
81101

82102
@then('I can access a cell using its row and column indices')
@@ -162,6 +182,12 @@ def then_can_get_length_of_row_cell_collection(context):
162182
assert len(cells) == 2
163183

164184

185+
@then('I can get the table style name')
186+
def then_can_get_table_style_name(context):
187+
table = context.table_
188+
assert table.style == 'foobar', "got '%s'" % table.style
189+
190+
165191
@then('I can iterate over the column cells')
166192
def then_can_iterate_over_the_column_cells(context):
167193
cells = context.cells
@@ -212,3 +238,10 @@ def then_len_of_column_collection_is_2(context):
212238
def then_len_of_row_collection_is_2(context):
213239
rows = context.table_.rows
214240
assert len(rows) == 2
241+
242+
243+
@then('the table style matches the name I applied')
244+
def then_table_style_matches_name_applied(context):
245+
table = context.table_
246+
tmpl = "table.style doesn't match, got '%s'"
247+
assert table.style == 'LightShading-Accent1', tmpl % table.style
37.7 KB
Binary file not shown.

features/tbl-style.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: Query and apply a table style
2+
In order to maintain consistent formatting of tables
3+
As an python-docx developer
4+
I need the ability to query and apply a table style
5+
6+
@wip
7+
Scenario: Access table style
8+
Given a table having an applied style
9+
Then I can get the table style name
10+
11+
@wip
12+
Scenario: Apply table style
13+
Given a table
14+
When I apply a style to the table
15+
Then the table style matches the name I applied

0 commit comments

Comments
 (0)