Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for non-contiguous chart ranges.
Issue #44.
- Loading branch information
Showing
6 changed files
with
187 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
############################################################################### | ||
# | ||
# Tests for XlsxWriter. | ||
# | ||
# Copyright (c), 2013, John McNamara, jmcnamara@cpan.org | ||
# | ||
|
||
import unittest | ||
import os | ||
from ...workbook import Workbook | ||
from ..helperfunctions import _compare_xlsx_files | ||
|
||
|
||
class TestCompareXLSXFiles(unittest.TestCase): | ||
""" | ||
Test file created by XlsxWriter against a file created by Excel. | ||
""" | ||
|
||
def setUp(self): | ||
self.maxDiff = None | ||
|
||
filename = 'chart_column07.xlsx' | ||
|
||
test_dir = 'xlsxwriter/test/comparison/' | ||
self.got_filename = test_dir + '_test_' + filename | ||
self.exp_filename = test_dir + 'xlsx_files/' + filename | ||
|
||
self.ignore_files = [] | ||
self.ignore_elements = {} | ||
|
||
def test_create_file(self): | ||
"""Test the creation of a simple XlsxWriter file.""" | ||
filename = self.got_filename | ||
|
||
#################################################### | ||
|
||
workbook = Workbook(filename) | ||
|
||
worksheet = workbook.add_worksheet() | ||
chart = workbook.add_chart({'type': 'column'}) | ||
|
||
chart.axis_ids = [68810240, 68811776] | ||
|
||
data = [ | ||
[1, 2, 3, 4, 5], | ||
[2, 4, 6, 8, 10], | ||
[3, 6, 9, 12, 15], | ||
|
||
] | ||
|
||
worksheet.write_column('A1', data[0]) | ||
worksheet.write_column('B1', data[1]) | ||
worksheet.write_column('C1', data[2]) | ||
|
||
chart.add_series({ | ||
'values': '=(Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5)', | ||
'values_data': [1, 2, 4, 5], | ||
}) | ||
|
||
worksheet.insert_chart('E9', chart) | ||
|
||
workbook.close() | ||
|
||
#################################################### | ||
|
||
got, exp = _compare_xlsx_files(self.got_filename, | ||
self.exp_filename, | ||
self.ignore_files, | ||
self.ignore_elements) | ||
|
||
self.assertEqual(got, exp) | ||
|
||
def tearDown(self): | ||
# Cleanup. | ||
if os.path.exists(self.got_filename): | ||
os.remove(self.got_filename) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
############################################################################### | ||
# | ||
# Tests for XlsxWriter. | ||
# | ||
# Copyright (c), 2013, John McNamara, jmcnamara@cpan.org | ||
# | ||
|
||
import unittest | ||
import os | ||
from ...workbook import Workbook | ||
from ..helperfunctions import _compare_xlsx_files | ||
|
||
|
||
class TestCompareXLSXFiles(unittest.TestCase): | ||
""" | ||
Test file created by XlsxWriter against a file created by Excel. | ||
""" | ||
|
||
def setUp(self): | ||
self.maxDiff = None | ||
|
||
filename = 'chart_column08.xlsx' | ||
|
||
test_dir = 'xlsxwriter/test/comparison/' | ||
self.got_filename = test_dir + '_test_' + filename | ||
self.exp_filename = test_dir + 'xlsx_files/' + filename | ||
|
||
self.ignore_files = [] | ||
self.ignore_elements = {} | ||
|
||
def test_create_file(self): | ||
"""Test the creation of a simple XlsxWriter file.""" | ||
filename = self.got_filename | ||
|
||
#################################################### | ||
|
||
workbook = Workbook(filename) | ||
|
||
worksheet = workbook.add_worksheet() | ||
chart = workbook.add_chart({'type': 'column'}) | ||
|
||
chart.axis_ids = [68809856, 68811392] | ||
|
||
data = [ | ||
[1, 2, 3, 4, 5], | ||
[2, 4, 6, 8, 10], | ||
[3, 6, 9, 12, 15], | ||
|
||
] | ||
|
||
worksheet.write_column('A1', data[0]) | ||
worksheet.write_column('B1', data[1]) | ||
worksheet.write_column('C1', data[2]) | ||
|
||
chart.add_series({ | ||
'categories': '=(Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5)', | ||
'values': '=(Sheet1!$B$1:$B$2,Sheet1!$B$4:$B$5)', | ||
'categories_data': [1, 2, 4, 5], | ||
'values_data': [2, 4, 8, 10], | ||
}) | ||
|
||
worksheet.insert_chart('E9', chart) | ||
|
||
workbook.close() | ||
|
||
#################################################### | ||
|
||
got, exp = _compare_xlsx_files(self.got_filename, | ||
self.exp_filename, | ||
self.ignore_files, | ||
self.ignore_elements) | ||
|
||
self.assertEqual(got, exp) | ||
|
||
def tearDown(self): | ||
# Cleanup. | ||
if os.path.exists(self.got_filename): | ||
os.remove(self.got_filename) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters