Beispiel #1
0
 def setUp(self):
     file_type = "xlsx"
     io = BytesIO()
     self.content = [["X", "Y", "Z"], [1, 11, 12], [2, 21, 22], [3, 31, 32], [4, 41, 42], [5, 51, 52]]
     sheet = pe.Sheet(pe.transpose(self.content), name_rows_by_column=0)
     sheet.save_to_memory(file_type, io)
     self.test_tuple = (file_type, io.getvalue())
Beispiel #2
0
 def setUp(self):
     file_type = "xlsx"
     io = BytesIO()
     self.content = [["X", "Y", "Z"], [1, 11, 12], [2, 21, 22], [3, 31, 32],
                     [4, 41, 42], [5, 51, 52]]
     sheet = pe.Sheet(pe.transpose(self.content), name_rows_by_column=0)
     sheet.save_to_memory(file_type, io)
     self.test_tuple = (file_type, io.getvalue())
Beispiel #3
0
 def test_add_rows_odd_column_filter_2(self):
     r = pe.Reader(self.testfile)
     #             5     6    7
     rows = [['c1', 'c2', 'c3'], ['x1', 'x2', 'x4']]
     r.extend_columns(pe.transpose(rows))
     r.add_filter(pe.sheets.filters.OddColumnFilter())
     assert r.row[0] == [2, 4, 'c2']
     assert r.row[1] == [6, 8, 'x2']
     assert r.row[2] == [10, 12, '']
Beispiel #4
0
 def test_add_rows_odd_column_filter_2(self):
     r = pe.Reader(self.testfile)
     #             5     6    7
     rows = [['c1', 'c2', 'c3'],
             ['x1', 'x2', 'x4']]
     r.extend_columns(pe.transpose(rows))
     r.add_filter(pe.filters.OddColumnFilter())
     assert r.row[0] == [2, 4, 'c2']
     assert r.row[1] == [6, 8, 'x2']
     assert r.row[2] == [10, 12, '']
Beispiel #5
0
 def test_even_row_filter(self):
     r = pe.ColumnSeriesReader(self.test_tuple)
     r.add_filter(pe.filters.EvenRowFilter())
     actual = pe.utils.to_dict(r)
     result = {"X": [1, 2, 3, 4, 5], "Z": [12, 22, 32, 42, 52]}
     assert result == actual
     # test removing the filter, it prints the original one
     r.clear_filters()
     actual = pe.utils.to_array(r.rows())
     assert actual == pe.transpose(self.content[1:])
Beispiel #6
0
 def test_odd_row_filter(self):
     r = pe.ColumnSeriesReader(self.test_tuple)
     f = pe.filters.OddRowFilter()
     r.add_filter(f)
     actual = pe.utils.to_dict(r)
     result = {"Y": [11, 21, 31, 41, 51]}
     assert result == actual
     r.remove_filter(f)
     actual = pe.utils.to_array(r.rows())
     assert actual == pe.transpose(self.content[1:])
Beispiel #7
0
 def test_empty_series_reader(self):
     # debug this further
     s = pe.Sheet()  # seriesreader is gone since v0.0.7
     assert s.name == "pyexcel"
     test_data = [[1, 2, 3], [4, 5, 6], ["Column 1", "Column 2", "Column 3"]]
     s.column += pe.transpose(test_data)
     actual = pe.to_array(s)
     assert test_data == actual
     s.name_columns_by_row(2)
     assert s.colnames == test_data[2]
Beispiel #8
0
 def test_even_row_filter(self):
     r = pe.ColumnSeriesReader(self.test_tuple)
     r.add_filter(pe.filters.EvenRowFilter())
     actual = pe.utils.to_dict(r)
     result = {"X": [1, 2, 3, 4, 5], "Z": [12, 22, 32, 42, 52]}
     assert result == actual
     # test removing the filter, it prints the original one
     r.clear_filters()
     actual = pe.utils.to_array(r.rows())
     assert actual == pe.transpose(self.content[1:])
Beispiel #9
0
 def test_odd_row_filter(self):
     r = pe.ColumnSeriesReader(self.test_tuple)
     f = pe.filters.OddRowFilter()
     r.add_filter(f)
     actual = pe.utils.to_dict(r)
     result = {"Y": [11, 21, 31, 41, 51]}
     assert result == actual
     r.remove_filter(f)
     actual = pe.utils.to_array(r.rows())
     assert actual == pe.transpose(self.content[1:])
Beispiel #10
0
 def test_orthogonality(self):
     r = pe.ColumnSeriesReader(self.test_tuple)
     r.add_filter(pe.filters.EvenRowFilter())
     r.add_filter(pe.filters.OddColumnFilter())
     actual = pe.to_dict(r)
     result = {"X": [2, 4], "Z": [22, 42]}
     assert result == actual
     # test removing the filter, it prints the original one
     r.clear_filters()
     actual = pe.utils.to_array(r.rows())
     assert actual == pe.transpose(self.content[1:])
Beispiel #11
0
 def test_empty_series_reader(self):
     # debug this further
     s = pe.Sheet()  # seriesreader is gone since v0.0.7
     assert s.name == "pyexcel sheet"
     test_data = [[1, 2, 3], [4, 5, 6],
                  ["Column 1", "Column 2", "Column 3"]]
     s.column += pe.transpose(test_data)
     actual = pe.to_array(s)
     assert test_data == actual
     s.name_columns_by_row(2)
     assert s.colnames == test_data[2]
Beispiel #12
0
 def test_orthogonality(self):
     r = pe.ColumnSeriesReader(self.test_tuple)
     r.add_filter(pe.filters.EvenRowFilter())
     r.add_filter(pe.filters.OddColumnFilter())
     actual = pe.to_dict(r)
     result = {"X": [2, 4], "Z": [22, 42]}
     assert result == actual
     # test removing the filter, it prints the original one
     r.clear_filters()
     actual = pe.utils.to_array(r.rows())
     assert actual == pe.transpose(self.content[1:])
Beispiel #13
0
 def test_add_rows_odd_column_filter(self):
     r = pe.Reader(self.testfile)
     r.add_filter(pe.filters.OddColumnFilter())
     assert r.number_of_rows() == 3
     assert r.number_of_columns() == 2
     result = [2, 4, 6, 8, 10, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
     #             5     6    7
     rows = [['c1', 'c2', 'c3'], ['x1', 'x2', 'x4']]
     r.extend_columns(pe.transpose(rows))
     assert r.row[0] == [2, 4, 'c2']
     assert r.row[1] == [6, 8, 'x2']
     assert r.row[2] == [10, 12, '']
 def test_add_rows_odd_column_filter(self):
     r = pe.Reader(self.testfile)
     r.add_filter(pe.filters.OddColumnFilter())
     assert r.number_of_rows() == 3
     assert r.number_of_columns() == 2
     result = [2, 4, 6, 8, 10, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
     #             5     6    7
     rows = [['c1', 'c2', 'c3'],
             ['x1', 'x2', 'x4']]
     r.extend_columns(pe.transpose(rows))
     assert r.row[0] == [2, 4, 'c2']
     assert r.row[1] == [6, 8, 'x2']
     assert r.row[2] == [10, 12, '']