def test_series(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) assert s.colnames == ["Column 1", "Column 2", "Column 3"] custom_columns = ["C1", "C2", "C3"] s.colnames = custom_columns assert s.colnames == custom_columns
def test_formatter_by_named_columns(self): """Test multiple named columns""" s = Sheet(self.data, "test") s.name_columns_by_row(0) s.column.format(["Column 1", "Column 3"], str) assert s.column["Column 1"] == ["1", "4", "7"] assert s.column["Column 3"] == ["3", "6", "9"]
def test_series(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) eq_(s.colnames, ["Column 1", "Column 2", "Column 3"]) custom_columns = ["C1", "C2", "C3"] s.colnames = custom_columns eq_(s.colnames, custom_columns)
def test_add(self): s = Sheet(self.data, "test") s.name_columns_by_row(0) data = OrderedDict({"Column 4": [10, 11, 12]}) s1 = s.column + data eq_(s1.column.Column_4, [10, 11, 12]) eq_(s.column.Column_4, [10, 11, 12])
def test_add(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) data = OrderedDict({"Column 4": [10, 11, 12]}) s1 = s.column + data eq_(s1.column["Column 4"], [10, 11, 12]) assert_not_in("Column 4", s.column)
def test_set_records(): s = Sheet() test_records = [{"name": "a", "age": 11}, {"name": "b", "age": 12}] s.records = test_records expected = dedent(""" pyexcel_sheet1: +-----+------+ | age | name | +-----+------+ | 11 | a | +-----+------+ | 12 | b | +-----+------+""").strip() eq_(str(s), expected) s.name_columns_by_row(0) eq_(list(s.records), test_records)
def test_top_left_with_colnames(self): data = [ ["col 1", "col 2", "col 3", "col 4", "col 5", "col 6"], [1, 2, 3, 4, 5, 6], [11, 2, 3, 4, 5, 6], [21, 2, 3, 4, 5, 6], [31, 2, 3, 4, 5, 6], [41, 2, 3, 4, 5, 6], [51, 2, 3, 4, 5, 6], ] s = Sheet(data) s.name_columns_by_row(0) top_sheet = s.top_left() expected = [["col 1", "col 2", "col 3", "col 4", "col 5"], [1, 2, 3, 4, 5], [11, 2, 3, 4, 5], [21, 2, 3, 4, 5], [31, 2, 3, 4, 5], [41, 2, 3, 4, 5]] eq_(top_sheet.array, expected)
def test_set_dict(): s = Sheet() test_dict = {"a": [1, 2, 3], "b": [2, 3, 4]} s.dict = test_dict expected = dedent(""" pyexcel_sheet1: +---+---+ | a | b | +---+---+ | 1 | 2 | +---+---+ | 2 | 3 | +---+---+ | 3 | 4 | +---+---+""").strip() eq_(expected, str(s)) s.name_columns_by_row(0) eq_(s.dict, test_dict)
def test_top_left_with_colnames_and_rownames(self): data = [ ["", "col 1", "col 2", "col 3", "col 4", "col 5", "col 6"], ["row 1", 1, 2, 3, 4, 5, 6], ["row 2", 11, 2, 3, 4, 5, 6], ["row 3", 21, 2, 3, 4, 5, 6], ["row 4", 31, 2, 3, 4, 5, 6], ["row 5", 41, 2, 3, 4, 5, 6], ["row 6", 51, 2, 3, 4, 5, 6], ] s = Sheet(data) s.name_columns_by_row(0) s.name_rows_by_column(0) top_sheet = s.top_left() expected = [["", "col 1", "col 2", "col 3", "col 4", "col 5"], ["row 1", 1, 2, 3, 4, 5], ["row 2", 11, 2, 3, 4, 5], ["row 3", 21, 2, 3, 4, 5], ["row 4", 31, 2, 3, 4, 5], ["row 5", 41, 2, 3, 4, 5]] eq_(top_sheet.array, expected)
def test_top_with_colnames(self): data = [["column 1", "column 2"], [1, 2]] s = Sheet(copy.deepcopy(data)) s.name_columns_by_row(0) top_sheet = s.top() assert top_sheet.array == data
def test_set_indexed_row(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) s.row[0] = [10000, 1, 11] assert s.row[0] == [10000, 1, 11]
def test_delete_named_column(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) del s.column["Column 2"] assert s.number_of_columns() == 2 s.column["Column 2"] # bang
def test_add(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) data = OrderedDict({"Column 4": [10, 11, 12]}) s = s.column + data assert s.column["Column 4"] == [10, 11, 12]
def test_delete_indexed_column(self): s = Sheet(self.data, "test") s.name_columns_by_row(0) s.delete_named_column_at(1) assert s.number_of_columns() == 2 s.column["Column 2"] # access it after deletion, bang
def test_add_wrong_type(self): """Add string type""" s = Sheet(self.data, "test") s.name_columns_by_row(0) s = s.column + "string type" # bang
def test_dot_notation(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) eq_(s.column.Column_3, [3, 6, 9])
def make_summary(headers): todays_summary = Sheet() todays_summary.row += headers todays_summary.name_columns_by_row(0) return todays_summary
def test_formatter_by_named_column(self): """Test one named column""" s = Sheet(self.data, "test") s.name_columns_by_row(0) s.column.format("Column 1", str) assert s.column["Column 1"] == ["1", "4", "7"]
def test_formatter_by_named_column_2(self): s = Sheet(self.data, "test") s.name_columns_by_row(2) s.column.format("Column 1", str) assert s.column["Column 1"] == ["1", "4", "7"]
def make_summary(headers): todays_summary = Sheet() todays_summary.row += headers todays_summary.name_columns_by_row(0) return todays_summary