File tree Expand file tree Collapse file tree 4 files changed +68
-1
lines changed
Expand file tree Collapse file tree 4 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -25,3 +25,13 @@ def get_prop_value(obj):
2525 return value
2626
2727 return property (get_prop_value , doc = docstring )
28+
29+
30+ def write_only_property (f ):
31+ """
32+ @write_only_property decorator. Creates a property (descriptor attribute)
33+ that accepts assignment, but not getattr (use in an expression).
34+ """
35+ docstring = f .__doc__
36+
37+ return property (fset = f , doc = docstring )
Original file line number Diff line number Diff line change 66
77from __future__ import absolute_import , print_function , unicode_literals
88
9- from .shared import lazyproperty
9+ from .shared import lazyproperty , write_only_property
1010from .text import Paragraph
1111
1212
@@ -66,6 +66,14 @@ def __init__(self, tc):
6666 def paragraphs (self ):
6767 return [Paragraph (p ) for p in self ._tc .p_lst ]
6868
69+ @write_only_property
70+ def text (self , text ):
71+ """
72+ Write-only. Set entire contents of cell to the string *text*. Any
73+ existing content or revisions are replaced.
74+ """
75+ raise NotImplementedError
76+
6977
7078class _Column (object ):
7179 """
Original file line number Diff line number Diff line change 1+ Feature : Set table cell text
2+ In order to quickly populate a table cell with regular text
3+ As an python-docx developer working with a table
4+ I need the ability to set the text of a table cell
5+
6+ @wip
7+ Scenario : Set table cell text
8+ Given a table cell
9+ When I assign a string to the cell text attribute
10+ Then the cell contains the string I assigned
Original file line number Diff line number Diff line change 1+ # encoding: utf-8
2+
3+ """
4+ Step implementations for table cell-related features
5+ """
6+
7+ from __future__ import absolute_import , print_function , unicode_literals
8+
9+ from behave import given , then , when
10+
11+ from docx import Document
12+
13+
14+ # given ===================================================
15+
16+ @given ('a table cell' )
17+ def given_a_table_cell (context ):
18+ table = Document ().body .add_table (rows = 2 , cols = 2 )
19+ context .cell = table .cell (0 , 0 )
20+
21+
22+ # when =====================================================
23+
24+ @when ('I assign a string to the cell text attribute' )
25+ def when_assign_string_to_cell_text_attribute (context ):
26+ cell = context .cell
27+ text = 'foobar'
28+ cell .text = text
29+ context .expected_text = text
30+
31+
32+ # then =====================================================
33+
34+ @then ('the cell contains the string I assigned' )
35+ def then_cell_contains_string_assigned (context ):
36+ cell , expected_text = context .cell , context .expected_text
37+ text = cell .paragraphs [0 ].runs [0 ].text
38+ msg = "expected '%s', got '%s'" % (expected_text , text )
39+ assert text == expected_text , msg
You can’t perform that action at this time.
0 commit comments