def test_set_form_doc(self) -> None:
        engine: Engine = EngineOpenpyxl()
        book1: Book = engine.new_book()
        book1_sheet1: Sheet = book1.get_sheets()[0]
        book1_sheet1.get_cell(1, 1).set_value("value")
        book1_sheet1.get_cell(1, 2).set_value(10)

        factory: FormFactory = FormFactory()
        factory.register_form(
            "form1",
            {
                "item1": {
                    "cls": FormItemKeyValueCells,
                    "kwargs": {
                        "sheet_name": "Sheet1",
                        "range_arg": "A1:B1",
                        "header_value": "value",
                    },
                }
            },
        )
        form = factory.new_form("form1", book1)
        doc = form.get_form_doc()
        doc["item1"]["result"] = 20
        form.set_form_doc(doc)

        self.assertEqual(book1_sheet1.get_cell(1, 2).get_value(), 20)
    def test_get_form_doc(self) -> None:
        engine: Engine = EngineOpenpyxl()
        book1: Book = engine.new_book()
        book1_sheet1: Sheet = book1.get_sheets()[0]
        book1_sheet1.get_cell(1, 1).set_value(10)

        factory: FormFactory = FormFactory()
        factory.register_form(
            "form1",
            {
                "item1": {
                    "cls": FormItemCell,
                    "kwargs": {"sheet_name": "Sheet1", "range_arg": "A1"},
                }
            },
        )
        form: Form = factory.new_form("form1", book1)
        doc = form.get_form_doc()

        self.assertIsInstance(doc, dict)
        self.assertTrue("item1" in doc)
        self.assertIsInstance(doc["item1"], dict)
        self.assertTrue("_meta" in doc["item1"])
        self.assertTrue("result" in doc["item1"])
        self.assertEqual(doc["item1"]["result"], 10)
    def setUp(self) -> None:
        self._engine: Engine = EngineOpenpyxl()
        self._book: Book = self._engine.new_book()
        self._sheet: Sheet = self._book.get_sheets()[0]

        table: List[List[str]] = [
            ["head1", "head1", "head2"],
            ["head11", "head12", "head21"],
            ["data111", "data112", "data121"],
            ["data211", "data212", "data221"],
            ["data311", "data312", "data321"],
        ]

        for row, rows in enumerate(table, start=1):
            for col, value in enumerate(rows, start=1):
                self._sheet.get_cell(row, col).set_value(value)
Beispiel #4
0
 def test_new_form(self) -> None:
     factory: FormFactory = FormFactory()
     factory.register_form(
         "form1",
         {
             "item1": {
                 "cls": FormItemCell,
                 "kwargs": {
                     "sheet_name": "Sheet1",
                     "range_arg": "A1"
                 },
             }
         },
     )
     engine: Engine = EngineOpenpyxl()
     book1: Book = engine.new_book()
     book1_sheet1: Sheet = book1.get_sheets()[0]
     book1_sheet1.get_cell(1, 1).set_value(123)
     form: Form = factory.new_form("form1", book1)
     self.assertIsInstance(form, Form)
    def test_get_form_doc__validation(self) -> None:
        engine: Engine = EngineOpenpyxl()
        book1: Book = engine.new_book()
        book1_sheet1: Sheet = book1.get_sheets()[0]
        book1_sheet1.get_cell(1, 1).set_value("xyz")
        book1_sheet1.get_cell(1, 2).set_value(10)

        factory: FormFactory = FormFactory()
        factory.register_form(
            "form1",
            {
                "item1": {
                    "cls": FormItemKeyValueCells,
                    "kwargs": {
                        "sheet_name": "Sheet1",
                        "range_arg": "A1:B1",
                        "header_value": "value",
                    },
                }
            },
        )
        with self.assertRaises(XlFormArgumentException):
            factory.new_form("form1", book1)
 def setUp(self) -> None:
     self._engine = EngineOpenpyxl()