def test_insert_row_two_elements(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     assert len(sheet.cells) == 0
     sheet.insert_row(["The Test", "A Second Test"], "my_format")
     assert TestSheet.count_cells(sheet, col=0, format_name="my_format", formula="The Test") == 1
     assert TestSheet.count_cells(sheet, col=1, format_name="my_format", formula="A Second Test") == 1
     assert sheet.current_col == 2
     assert sheet.current_row == 0
 def test_quarter_heading(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     sheet.quarter_heading("My Heading")
     assert TestSheet.count_cells(sheet, row=0, format_name="bold", formula="My Heading") == 1
     assert TestSheet.count_cells(sheet, row=0, format_name="bold", formula="Total") == 1
     assert TestSheet.count_cells(sheet, row=0, format_name="bold", formula="Q1 2018") == 1
     assert TestSheet.count_cells(sheet, row=0, format_name="bold", formula="Q4 2020") == 1
     assert TestSheet.count_cells(sheet, row=0, format_name="bold", formula="Q4 2021") == 0
     assert TestSheet.count_cells(sheet, row=0, format_name="bold") == 14
     assert TestSheet.count_cells(sheet, row=1) == 0
 def test_translate_references(self):
     formula = "[a]+[b]"
     references = {
         "[a]": [0, 0, True, True],
         "[b]": [1, 0, False, False],
         "[c]": [6, 0, False, False],
     }
     translated = ExportSheet.translate_references(formula, references, 2, 3)
     assert translated == "=A1+D4"
 def test_bump_row_with_next_row(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     assert sheet.current_col == 0
     sheet.current_col = 3
     sheet.current_row = 4
     sheet.next_row = 5
     sheet.bump_row(2)
     assert sheet.current_row == 6
     assert sheet.current_col == 0
    def test_sheet_single_version(self):
        sheets = []
        model = ExportModel.from_json(ExportTestFixtures.model_1_json)
        version = model.versions[0]

        sheet = ExportSheet.from_version(model, version, sheets)
        assert TestSheet.count_cells(sheet, 0, 0, "bold", "Programs") == 1
        assert TestSheet.count_cells(sheet, 1, 0, formula=model.program_names[0]) == 1
        assert TestSheet.count_cells(sheet, 1, 1, formula=model.program_fte_rates[0]) == 1
        assert sheet.references['[fte_rate]'][0] == 1
        assert sheet.references['[fte_rate]'][1] == 1
 def test_fill_formula_overwrite(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     sheet.set_reference("a", fixed_row=True, fixed_col=True)
     sheet.current_row = 10
     sheet.current_col = 5
     sheet.set_reference("b")
     sheet.current_row = 1
     sheet.current_col = 1
     sheet.fill_formula("[a]*[b]", 3, 5, "my_number")
     sheet.current_row = 2
     sheet.current_col = 2
     sheet.fill_formula("[a]+[b]", 2, 2, "my_number", overwrite=True)
     assert TestSheet.count_cells(sheet, row=1, col=1, formula="=A1*F11") == 1
     assert TestSheet.count_cells(sheet, row=2, col=2, formula="=A1+F11") == 1
     assert TestSheet.count_cells(sheet, row=3, col=3, formula="=A1+G12") == 1
     assert TestSheet.count_cells(sheet, row=3, col=5, formula="=A1*J13") == 1
     assert TestSheet.count_cells(sheet, format_name="my_number") == 15
 def test_shift_references(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     sheet.set_reference("my_ref", fixed_row=True, fixed_col=False, offset_row=3, offset_col=4)
     sheet.shift_reference("my_ref", 3, 4)
     assert sheet.references["[my_ref]"] == [6, 8, True, False]
 def test_insert_sum_row(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     sheet.insert_row(["Label", "Col A", "Col B", "Col C", "Col D"])
     sheet.bump_row()
     sheet.insert_col(["Row A", "Row B", "Row C"])
     sheet.insert_col([1, 2, 3])
     sheet.insert_col([4, 5, 6])
     sheet.insert_col([7, 8, 9])
     sheet.insert_col([10, 11, 12])
     sheet.bump_row()
     assert sheet.current_col == 0
     sheet.insert_sum_row(3, 4, "my_format")
     assert TestSheet.count_cells(sheet, row=4, formula="=SUM(B2:B4)") == 1
     assert TestSheet.count_cells(sheet, row=4, formula="=SUM(C2:C4)") == 1
     assert TestSheet.count_cells(sheet, row=4, formula="=SUM(D2:D4)") == 1
     assert TestSheet.count_cells(sheet, row=4, formula="=SUM(E2:E4)") == 1
     assert TestSheet.count_cells(sheet, row=4) == 5
 def test_insert_sum_col(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     sheet.insert_row(["Col A", "Col B", "Col C", "Col D"])
     sheet.bump_row()
     sheet.insert_col([1, 2, 3])
     sheet.insert_col([4, 5, 6])
     sheet.insert_col([7, 8, 9])
     sheet.insert_col([10, 11, 12])
     sheet.insert_sum_col(3, 4, "my_format")
     sheet.bump_row()
     assert TestSheet.count_cells(sheet, col=4, formula="=SUM(A2:D2)") == 1
     assert TestSheet.count_cells(sheet, col=4, formula="=SUM(A3:D3)") == 1
     assert TestSheet.count_cells(sheet, col=4, formula="=SUM(A4:D4)") == 1
     assert TestSheet.count_cells(sheet, col=4) == 3
 def test_insert_single_sum_col(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     sheet.insert_row(["Heading"])
     sheet.bump_row()
     sheet.insert_col([1, 2, 3])
     sheet.bump_row()
     sheet.insert_single_sum("A2", "my_format")
     assert TestSheet.count_cells(sheet, formula="=SUM(A2:A4)") == 1
 def test_insert_single_sum_row(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     sheet.insert_row([1, 2, 3])
     sheet.insert_single_sum("A1", "my_format")
     assert TestSheet.count_cells(sheet, formula="=SUM(A1:C1)") == 1
 def test_insert_col_basic(self):
     sheet = ExportSheet(ExportModel.from_json(ExportTestFixtures.model_1_json), 0)
     assert len(sheet.cells) == 0
     sheet.insert_col(["The Test"])
     assert TestSheet.count_cells(sheet, formula="The Test") == 1
     assert sheet.current_col == 1
 def test_label_from_quarter(self):
     assert ExportSheet.label_from_quarter(1990) == "Q1 1990"
     assert ExportSheet.label_from_quarter(1991.25) == "Q2 1991"
     assert ExportSheet.label_from_quarter(1992.5) == "Q3 1992"
     assert ExportSheet.label_from_quarter(1996.75) == "Q4 1996"