Пример #1
0
 def test_odd_row_filter(self):
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.OddRowFilter())
     assert r.number_of_rows() == 1
     assert r.number_of_columns() == 4
     result = [5, 6, 7, 8]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #2
0
 def test_even_column_filter(self):
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.EvenColumnFilter())
     assert r.number_of_rows() == 3
     assert r.number_of_columns() == 2
     result = [1, 3, 5, 7, 9, 11]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #3
0
 def test_column_filter_with_invalid_indices(self):
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.ColumnFilter([11, -1]))
     assert r.number_of_rows() == 3
     assert r.number_of_columns() == 4
     result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #4
0
 def test_even_row_filter(self):
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.EvenRowFilter())
     assert r.number_of_rows() == 2
     assert r.number_of_columns() == 4
     result = [1, 2, 3, 4, 9, 10, 11, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #5
0
 def test_odd_column_filter(self):
     r = pe.FilterableReader(self.testfile)
     r.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
Пример #6
0
 def test_remove_filter(self):
     r = pe.FilterableReader(self.testfile)
     f = pe.filters.OddRowFilter()
     r.add_filter(f)
     assert r.number_of_rows() == 1
     assert r.number_of_columns() == 4
     result = [5, 6, 7, 8]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
     r.remove_filter(f)
     result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #7
0
 def test_column_index_filter(self):
     r = pe.FilterableReader(self.testfile)
     test_func = lambda x: x in [0, 2]
     r.add_filter(pe.filters.ColumnIndexFilter(test_func))
     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
     # test removing the filter,  it prints the original one
     r.clear_filters()
     result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #8
0
 def test_column_filter(self):
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.ColumnFilter([0, 2]))
     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
     # filter out last column and first column
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.ColumnFilter([0, 3]))
     assert r.number_of_rows() == 3
     assert r.number_of_columns() == 2
     result = [2, 3, 6, 7, 10, 11]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
     # filter out all
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.ColumnFilter([0, 1, 2, 3]))
     assert r.number_of_columns() == 0
     result = []
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #9
0
 def test_row_filter(self):
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.RowFilter([1]))
     assert r.number_of_rows() == 2
     assert r.number_of_columns() == 4
     result = [1, 2, 3, 4, 9, 10, 11, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
     # filter out last column and first column
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.RowFilter([0, 2]))
     assert r.number_of_rows() == 1
     assert r.number_of_columns() == 4
     result = [5, 6, 7, 8]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
     # filter out all
     r = pe.FilterableReader(self.testfile)
     r.filter(pe.filters.RowFilter([0, 1, 2]))
     assert r.number_of_rows() == 0
     result = []
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #10
0
    def test_update_a_cell_with_a_filter(self):
        """
        Filter the sheet first and then update the filtered now

        with the filter, you can set its value. then clear
        the filters, the value stays with the cell. so if you want
        to save the change with original data, please clear the filter
        first
        """
        r = pe.FilterableReader(self.testfile)
        r.add_filter(pe.filters.ColumnFilter([0, 2]))
        r.cell_value(2, 1, "k")
        assert r[2,1] == "k"
        r.clear_filters()
        assert r[2,3] == "k"
Пример #11
0
 def test_two_filters(self):
     r = pe.FilterableReader(self.testfile)
     f1 = pe.filters.OddRowFilter()
     f2 = pe.filters.OddColumnFilter()
     r.add_filter(f1)
     r.add_filter(f2)
     assert r.number_of_columns() == 2
     assert r.number_of_rows() == 1
     result = [6, 8]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
     r.remove_filter(f1)
     #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
Пример #12
0
 def test_use_filter_reader_without_filter(self):
     r = pe.FilterableReader(self.testfile)
     result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
     actual = pe.utils.to_array(r.enumerate())
     assert result == actual
Пример #13
0
 def test_non_default_sheet_as_single_sheet_filterable_reader(self):
     r = pe.FilterableReader(self.testfile, "Sheet2")
     data = pe.utils.to_array(r.rows())
     assert data == self.content["Sheet2"]