Пример #1
0
def test_edit_cell_values(tmp_path):
    doc = Document("tests/data/test-save-1.numbers")
    sheets = doc.sheets
    tables = sheets[0].tables
    table = tables[0]
    table.write("B2", "new_b2")
    table.write(1, 2, "new_c2")
    table.write(2, 0, True)
    table.write(2, 1, 7890)
    table.write(2, 2, 78.90)
    table.write(5, 3, datetime(2020, 12, 25))
    table.write(5, 4, timedelta(seconds=7890))
    table.write(5, 5, "7890")

    assert isinstance(table.cell(3, 4), EmptyCell)
    assert isinstance(table.cell(4, 4), EmptyCell)

    new_filename = tmp_path / "test-save-1-new.numbers"
    doc.save(new_filename)

    doc = Document(new_filename)
    sheets = doc.sheets
    tables = sheets[0].tables
    table = tables[0]

    assert table.cell(1, 1).value == "new_b2"
    assert table.cell("C2").value == "new_c2"
    assert table.cell(2, 0).value == True
    assert table.cell(2, 1).value == 7890
    assert table.cell(2, 2).value == 78.90
    assert table.cell(5, 3).value == datetime(2020, 12, 25)
    assert table.cell(5, 4).value == timedelta(seconds=7890)
    assert table.cell(5, 5).value == "7890"
Пример #2
0
def test_create_sheet(tmp_path, pytestconfig):
    _EXPERIMENTAL_NUMBERS_PARSER = True
    doc = Document()
    sheets = doc.sheets
    sheets[0].tables[0].write("B2", "data")
    sheets[0].tables[0].write("G2", "data")

    with pytest.raises(IndexError) as e:
        _ = sheets[0].add_table("TablE 1")
    assert "table 'TablE 1' already exists" in str(e.value)

    # sheets[0].modify_table()
    # table = sheets[0].tables[0]

    table = sheets[0].add_table()
    assert table.name == "Table 2"
    table.write("B1", "Column B")
    table.write("C1", "Column C")
    table.write("D1", "Column D")
    table.write("B2", "Mary had")
    table.write("C2", "a little")
    table.write("D2", "lamb")

    # with pytest.raises(IndexError) as e:
    #     _ = doc.add_sheet("SheeT 1")
    # assert "sheet 'SheeT 1' already exists" in str(e.value)

    # doc.add_sheet("New Sheet", "New Table")
    # sheet = doc.sheets["New Sheet"]
    # table = sheet.tables["New Table"]
    # table.write(0, 1, "Column 1")
    # table.write(0, 2, "Column 2")
    # table.write(0, 3, "Column 3")
    # table.write(1, 1, 1000)
    # table.write(1, 2, 2000)
    # table.write(1, 3, 3000)

    if pytestconfig.getoption("save_file") is not None:
        new_filename = pytestconfig.getoption("save_file")
    else:
        new_filename = tmp_path / "test-1-new.numbers"
    doc.save(new_filename)

    doc = Document(new_filename)
    sheets = doc.sheets

    table = sheets[0].tables[0]
    # table = sheets[0].tables[1]
    # assert sheets[0].tables[1].name == "Table 2"
    assert table.cell("B1").value == "Column B"
    assert table.cell("C1").value == "Column C"
    assert table.cell("D1").value == "Column D"
    assert table.cell("B2").value == "Mary had"
    assert table.cell("C2").value == "a little"
    assert table.cell("D2").value == "lamb"
Пример #3
0
def test_save_document(tmp_path):
    doc = Document("tests/data/test-1.numbers")
    sheets = doc.sheets
    tables = sheets[0].tables
    cell_values = tables["ZZZ_Table_1"].rows(values_only=True)

    sheets["ZZZ_Sheet_1"].name = "ZZZ_Sheet_1 NEW"
    tables["ZZZ_Table_1"].name = "ZZZ_Table_1 NEW"

    new_filename = tmp_path / "test-1-new.numbers"
    doc.save(new_filename)

    new_doc = Document(new_filename)
    new_sheets = new_doc.sheets
    new_tables = new_sheets["ZZZ_Sheet_1 NEW"].tables
    new_cell_values = new_tables["ZZZ_Table_1 NEW"].rows(values_only=True)

    assert cell_values == new_cell_values
Пример #4
0
def test_save_merges(tmp_path):
    doc = Document("tests/data/test-save-1.numbers")
    sheets = doc.sheets
    table = sheets[0].tables[0]
    table.add_column(2)
    table.add_row(3)
    table.write("B2", "merge_1")
    table.write("B5", "merge_2")
    table.write("D2", "merge_3")
    table.merge_cells("B2:C2")
    table.merge_cells(["B5:E5", "D2:D4"])

    new_filename = tmp_path / "test-1-new.numbers"
    doc.save(new_filename)

    doc = Document(new_filename)
    sheets = doc.sheets
    table = sheets[0].tables[0]
    assert table.merge_ranges == ["B2:C2", "B5:E5", "D2:D4"]
Пример #5
0
def test_large_table(tmp_path):
    doc = Document()
    sheets = doc.sheets
    tables = sheets[0].tables
    table = tables[0]
    for i in range(0, 300):
        table.write(i, i, "wide")

    new_filename = tmp_path / "save-large.numbers"
    doc.save(new_filename)

    doc = Document(new_filename)
    sheets = doc.sheets
    tables = sheets[0].tables
    table = tables[0]

    data = table.rows()
    assert len(data) == 300
    assert len(data[299]) == 300
    assert table.cell(0, 0).value == "wide"
    assert table.cell(299, 299).value == "wide"