Skip to content

Commit 6636d01

Browse files
author
Steve Canny
committed
OpcPackage round-trips an xlsx file
1 parent 8f50382 commit 6636d01

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

features/save-package.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ Feature: Save an OPC package
1414
When I open a PowerPoint file
1515
And I save the presentation package
1616
Then I see the pptx file in the working directory
17+
18+
Scenario: Round-trip an .xlsx file
19+
Given a clean working directory
20+
When I open an Excel file
21+
And I save the spreadsheet package
22+
Then I see the xlsx file in the working directory

features/steps/opc_steps.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ def absjoin(*paths):
2626
test_file_dir = absjoin(thisdir, '../../tests/test_files')
2727
basic_docx_path = absjoin(test_file_dir, 'test.docx')
2828
basic_pptx_path = absjoin(test_file_dir, 'test.pptx')
29+
basic_xlsx_path = absjoin(test_file_dir, 'test.xlsx')
2930
saved_docx_path = absjoin(scratch_dir, 'test_out.docx')
3031
saved_pptx_path = absjoin(scratch_dir, 'test_out.pptx')
32+
saved_xlsx_path = absjoin(scratch_dir, 'test_out.xlsx')
3133

3234

3335
# given ====================================================
3436

3537
@given('a clean working directory')
3638
def step_given_clean_working_dir(context):
37-
files_to_clean_out = (saved_docx_path, saved_pptx_path)
39+
files_to_clean_out = (saved_docx_path, saved_pptx_path, saved_xlsx_path)
3840
for path in files_to_clean_out:
3941
if os.path.isfile(path):
4042
os.remove(path)
@@ -47,6 +49,11 @@ def step_given_python_opc_working_environment(context):
4749

4850
# when =====================================================
4951

52+
@when('I open an Excel file')
53+
def step_when_open_basic_xlsx(context):
54+
context.pkg = OpcPackage.open(basic_xlsx_path)
55+
56+
5057
@when('I open a PowerPoint file')
5158
def step_when_open_basic_pptx(context):
5259
context.pkg = OpcPackage.open(basic_pptx_path)
@@ -71,6 +78,13 @@ def step_when_save_presentation_package(context):
7178
context.pkg.save(saved_pptx_path)
7279

7380

81+
@when('I save the spreadsheet package')
82+
def step_when_save_spreadsheet_package(context):
83+
if os.path.isfile(saved_xlsx_path):
84+
os.remove(saved_xlsx_path)
85+
context.pkg.save(saved_xlsx_path)
86+
87+
7488
# then =====================================================
7589

7690
@then('the expected package rels are loaded')
@@ -224,3 +238,12 @@ def step_then_see_pptx_file_in_working_dir(context):
224238
minimum = 20000
225239
filesize = os.path.getsize(saved_pptx_path)
226240
assert filesize > minimum
241+
242+
243+
@then('I see the xlsx file in the working directory')
244+
def step_then_see_xlsx_file_in_working_dir(context):
245+
reason = "file '%s' not found" % saved_xlsx_path
246+
assert os.path.isfile(saved_xlsx_path), reason
247+
minimum = 30000
248+
filesize = os.path.getsize(saved_xlsx_path)
249+
assert filesize > minimum

tests/test_files/test.xlsx

41.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy