@@ -24,16 +24,20 @@ def absjoin(*paths):
24
24
thisdir = os .path .split (__file__ )[0 ]
25
25
scratch_dir = absjoin (thisdir , '../_scratch' )
26
26
test_file_dir = absjoin (thisdir , '../../tests/test_files' )
27
+ basic_docx_path = absjoin (test_file_dir , 'test.docx' )
27
28
basic_pptx_path = absjoin (test_file_dir , 'test.pptx' )
29
+ saved_docx_path = absjoin (scratch_dir , 'test_out.docx' )
28
30
saved_pptx_path = absjoin (scratch_dir , 'test_out.pptx' )
29
31
30
32
31
33
# given ====================================================
32
34
33
35
@given ('a clean working directory' )
34
36
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 )
37
41
38
42
39
43
@given ('a python-opc working environment' )
@@ -48,6 +52,18 @@ def step_when_open_basic_pptx(context):
48
52
context .pkg = OpcPackage .open (basic_pptx_path )
49
53
50
54
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
+
51
67
@when ('I save the presentation package' )
52
68
def step_when_save_presentation_package (context ):
53
69
if os .path .isfile (saved_pptx_path ):
@@ -192,6 +208,15 @@ def step_then_expected_parts_are_loaded(context):
192
208
(rId , partname , rel .target_part .partname ))
193
209
194
210
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
+
195
220
@then ('I see the pptx file in the working directory' )
196
221
def step_then_see_pptx_file_in_working_dir (context ):
197
222
reason = "file '%s' not found" % saved_pptx_path
0 commit comments