Skip to content

Commit 8f50382

Browse files
author
Steve Canny
committed
OpcPackage round-trips a docx file
1 parent 0f67034 commit 8f50382

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

features/save-package.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Feature: Save an OPC package
33
As a pptx developer
44
I want to see it pass a basic round-trip sanity-check
55

6+
Scenario: Round-trip a .docx file
7+
Given a clean working directory
8+
When I open a Word file
9+
And I save the document package
10+
Then I see the docx file in the working directory
11+
612
Scenario: Round-trip a .pptx file
713
Given a clean working directory
814
When I open a PowerPoint file

features/steps/opc_steps.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ def absjoin(*paths):
2424
thisdir = os.path.split(__file__)[0]
2525
scratch_dir = absjoin(thisdir, '../_scratch')
2626
test_file_dir = absjoin(thisdir, '../../tests/test_files')
27+
basic_docx_path = absjoin(test_file_dir, 'test.docx')
2728
basic_pptx_path = absjoin(test_file_dir, 'test.pptx')
29+
saved_docx_path = absjoin(scratch_dir, 'test_out.docx')
2830
saved_pptx_path = absjoin(scratch_dir, 'test_out.pptx')
2931

3032

3133
# given ====================================================
3234

3335
@given('a clean working directory')
3436
def step_given_clean_working_dir(context):
35-
if os.path.isfile(saved_pptx_path):
36-
os.remove(saved_pptx_path)
37+
files_to_clean_out = (saved_docx_path, saved_pptx_path)
38+
for path in files_to_clean_out:
39+
if os.path.isfile(path):
40+
os.remove(path)
3741

3842

3943
@given('a python-opc working environment')
@@ -48,6 +52,18 @@ def step_when_open_basic_pptx(context):
4852
context.pkg = OpcPackage.open(basic_pptx_path)
4953

5054

55+
@when('I open a Word file')
56+
def step_when_open_basic_docx(context):
57+
context.pkg = OpcPackage.open(basic_docx_path)
58+
59+
60+
@when('I save the document package')
61+
def step_when_save_document_package(context):
62+
if os.path.isfile(saved_docx_path):
63+
os.remove(saved_docx_path)
64+
context.pkg.save(saved_docx_path)
65+
66+
5167
@when('I save the presentation package')
5268
def step_when_save_presentation_package(context):
5369
if os.path.isfile(saved_pptx_path):
@@ -192,6 +208,15 @@ def step_then_expected_parts_are_loaded(context):
192208
(rId, partname, rel.target_part.partname))
193209

194210

211+
@then('I see the docx file in the working directory')
212+
def step_then_see_docx_file_in_working_dir(context):
213+
reason = "file '%s' not found" % saved_docx_path
214+
assert os.path.isfile(saved_docx_path), reason
215+
minimum = 20000
216+
filesize = os.path.getsize(saved_docx_path)
217+
assert filesize > minimum
218+
219+
195220
@then('I see the pptx file in the working directory')
196221
def step_then_see_pptx_file_in_working_dir(context):
197222
reason = "file '%s' not found" % saved_pptx_path

tests/test_files/test.docx

45.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)