@@ -24,16 +24,20 @@ def absjoin(*paths):
2424thisdir = os .path .split (__file__ )[0 ]
2525scratch_dir = absjoin (thisdir , '../_scratch' )
2626test_file_dir = absjoin (thisdir , '../../tests/test_files' )
27+ basic_docx_path = absjoin (test_file_dir , 'test.docx' )
2728basic_pptx_path = absjoin (test_file_dir , 'test.pptx' )
29+ saved_docx_path = absjoin (scratch_dir , 'test_out.docx' )
2830saved_pptx_path = absjoin (scratch_dir , 'test_out.pptx' )
2931
3032
3133# given ====================================================
3234
3335@given ('a clean working directory' )
3436def 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' )
5268def 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' )
196221def step_then_see_pptx_file_in_working_dir (context ):
197222 reason = "file '%s' not found" % saved_pptx_path
0 commit comments