예제 #1
0
    def test_dict_writer_wc_restval(self):
        # prepare
        oSheet = Mock()
        cells = [Mock() for _ in range(6)]
        oSheet.getCellByPosition.side_effect = cells

        # play
        def wc(oCell: UnoCell, value: Any):
            oCell.t = value

        w = dict_writer(oSheet, ['a', 'b', 'c'], restval="foo", write_cell=wc)

        w.writeheader()
        w.writerow({"a": 1, "b": 2})

        #
        self.assertEqual([
            call.getCellByPosition(0, 0),
            call.getCellByPosition(1, 0),
            call.getCellByPosition(2, 0),
            call.getCellByPosition(0, 1),
            call.getCellByPosition(1, 1),
            call.getCellByPosition(2, 1),
        ], oSheet.mock_calls)
        self.assertEqual(['a', 'b', 'c', 1, 2, 'foo'], [c.t for c in cells])
예제 #2
0
    def test_writer_no_formats(self):
        # prepare
        oSheet = Mock()
        cells = [Mock() for _ in range(6)]
        oSheet.getCellByPosition.side_effect = cells
        oLocale = Mock()

        # play
        w = writer(oSheet, CellTyping.Accurate)
        w.writerows([
            ("a", "b", "c"),
            (1, 2, 3),
        ])

        # verify
        self.assertEqual([
            call.DrawPage.Forms.Parent.NumberFormats.getStandardFormat(2, ANY),
            call.DrawPage.Forms.Parent.NumberFormats.getStandardFormat(6, ANY),
            call.DrawPage.Forms.Parent.NumberFormats.getStandardFormat(
                1024, ANY),
            call.getCellByPosition(0, 0),
            call.getCellByPosition(1, 0),
            call.getCellByPosition(2, 0),
            call.getCellByPosition(0, 1),
            call.getCellByPosition(1, 1),
            call.getCellByPosition(2, 1)
        ], oSheet.mock_calls)
        self.assertEqual(['a', 'b', 'c'], [c.String for c in cells[:3]])
        self.assertEqual([1, 2, 3], [c.Value for c in cells[3:]])
예제 #3
0
    def test_writer_formats(self):
        # prepare
        oSheet = Mock()
        cells = [Mock() for _ in range(6)]
        oSheet.getCellByPosition.side_effect = cells
        oFormats = Mock()

        # play
        w = writer(oSheet, CellTyping.Accurate, oFormats=oFormats)
        w.writerows([
            ("a", "b", "c"),
            (1, 2, 3),
        ])

        #
        self.assertEqual([
            call.getCellByPosition(0, 0),
            call.getCellByPosition(1, 0),
            call.getCellByPosition(2, 0),
            call.getCellByPosition(0, 1),
            call.getCellByPosition(1, 1),
            call.getCellByPosition(2, 1)
        ], oSheet.mock_calls)
        self.assertEqual(['a', 'b', 'c'], [c.String for c in cells[:3]])
        self.assertEqual([1, 2, 3], [c.Value for c in cells[3:]])
예제 #4
0
    def test_writer_wc(self):
        # prepare
        oSheet = Mock()
        cells = [Mock() for _ in range(6)]
        oSheet.getCellByPosition.side_effect = cells

        # play
        def wc(oCell: UnoCell, value: Any):
            oCell.t = value

        w = writer(oSheet, write_cell=wc)
        w.writerows([
            ("a", "b", "c"),
            (1, 2, 3),
        ])

        #
        self.assertEqual([
            call.getCellByPosition(0, 0),
            call.getCellByPosition(1, 0),
            call.getCellByPosition(2, 0),
            call.getCellByPosition(0, 1),
            call.getCellByPosition(1, 1),
            call.getCellByPosition(2, 1)
        ], oSheet.mock_calls)
        self.assertEqual(['a', 'b', 'c', 1, 2, 3], [c.t for c in cells])
예제 #5
0
    def test_dict_writer_wc_raise(self):
        # prepare
        oSheet = Mock()
        cells = [Mock() for _ in range(3)]
        oSheet.getCellByPosition.side_effect = cells

        # play
        def wc(oCell: UnoCell, value: Any):
            oCell.t = value

        w = dict_writer(oSheet, ['a', 'b', 'c'], write_cell=wc)

        w.writeheader()
        with self.assertRaises(ValueError):
            w.writerow({"a": 1, "b": 2, "d": 3})

        #
        self.assertEqual([
            call.getCellByPosition(0, 0),
            call.getCellByPosition(1, 0),
            call.getCellByPosition(2, 0),
        ], oSheet.mock_calls)
        self.assertEqual(['a', 'b', 'c'], [c.t for c in cells])
예제 #6
0
    def test_dict_writer_wc(self):
        # prepare
        oSheet = Mock()
        cells = [Mock() for _ in range(9)]
        oSheet.getCellByPosition.side_effect = cells

        # play
        def wc(oCell: UnoCell, value: Any):
            oCell.t = value

        w = dict_writer(oSheet, ['a', 'b', 'c'], write_cell=wc)

        w.writeheader()
        w.writerows([
            {
                "a": 1,
                "b": 2,
                "c": 3
            },
            {
                "a": 4,
                "b": 5,
                "c": 6
            },
        ])

        #
        self.assertEqual([
            call.getCellByPosition(0, 0),
            call.getCellByPosition(1, 0),
            call.getCellByPosition(2, 0),
            call.getCellByPosition(0, 1),
            call.getCellByPosition(1, 1),
            call.getCellByPosition(2, 1),
            call.getCellByPosition(0, 2),
            call.getCellByPosition(1, 2),
            call.getCellByPosition(2, 2)
        ], oSheet.mock_calls)
        self.assertEqual(['a', 'b', 'c', 1, 2, 3, 4, 5, 6],
                         [c.t for c in cells])