Skip to content

Commit

Permalink
🔬 more tests on merged cell detection #22
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Dec 18, 2017
1 parent ab1a806 commit ab074c0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pyexcel_xlsx/xlsxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def row_iterator(self):
if self.max_row > self.__sheet_max_row:
for i in range(self.__sheet_max_row, self.max_row):
data = [None] * self.__sheet_max_column
yield (data, i)
yield (data, i+1)

def column_iterator(self, row_struct):
"""
Expand All @@ -109,12 +109,14 @@ def column_iterator(self, row_struct):
if cell:
value = cell.value
else:
value = None
value = ''
if value is None:
value = ''
value = self._merged_cells(row_index, column_index, value)
yield value
if self.max_column > self.__sheet_max_column:
for i in range(self.__sheet_max_column, self.max_column):
value = self._merged_cells(row_index, column_index, None)
value = self._merged_cells(row_index, i+1, '')
yield value

def _merged_cells(self, row, column, value):
Expand Down
Binary file added tests/fixtures/merged-sheet-exploration.xlsx
Binary file not shown.
49 changes: 45 additions & 4 deletions tests/test_merged_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def test_merged_cells():
data = get_data(
os.path.join("tests", "fixtures", "merged-cell-sheet.xlsx"),
get_fixture("merged-cell-sheet.xlsx"),
detect_merged_cells=True,
library="pyexcel-xlsx")
expected = [[1, 2, 3], [1, 5, 6], [1, 8, 9], [10, 11, 11]]
Expand All @@ -15,7 +15,7 @@ def test_merged_cells():

def test_complex_merged_cells():
data = get_data(
os.path.join("tests", "fixtures", "complex-merged-cells-sheet.xlsx"),
get_fixture("complex-merged-cells-sheet.xlsx"),
detect_merged_cells=True,
library="pyexcel-xlsx")
expected = [
Expand All @@ -28,11 +28,48 @@ def test_complex_merged_cells():
[25, 25, 25, 25, 25, 25, 25, 25, 25, 25],
[25, 25, 25, 25, 25, 25, 25, 25, 25, 25]
]
import pprint
pprint.pprint(data['Sheet1'])
eq_(data['Sheet1'], expected)


def test_exploration():
data = get_data(
get_fixture("merged-sheet-exploration.xlsx"),
detect_merged_cells=True,
library="pyexcel-xlsx")
expected_sheet1 = [
[1, 1, 1, 1, 1, 1],
[2],
[2],
[2],
[2],
[2],
[2],
[2],
[2],
[2]]
eq_(data['Sheet1'], expected_sheet1)
expected_sheet2 = [
[3],
[3],
[3],
[3, 4, 4, 4, 4, 4, 4],
[3],
[3],
[3]]
eq_(data['Sheet2'], expected_sheet2)
expected_sheet3 = [
['', '', '', '', '', 2, 2, 2],
[],
[],
[],
['', '', '', 5],
['', '', '', 5],
['', '', '', 5],
['', '', '', 5],
['', '', '', 5]]
eq_(data['Sheet3'], expected_sheet3)


def test_merged_cell_class():
test_dict = {}
merged_cell = MergedCell("A7:J8")
Expand All @@ -44,3 +81,7 @@ def test_merged_cell_class():
'8-8', '8-9']
eq_(keys, expected)
eq_(merged_cell, test_dict['7-1'])


def get_fixture(file_name):
return os.path.join("tests", "fixtures", file_name)

0 comments on commit ab074c0

Please sign in to comment.