Пример #1
0
    def test_simple_enqueue(self):
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(INIT_MSG)

        self.assertFalse(rq.is_empty())
        queue = rq.flush()
        self.assertTrue(rq.is_empty())
        self.assertEqual(len(queue), 1)
        self.assertTrue(queue[0].initialize.config.sharing_enabled)
Пример #2
0
    def test_simple_enqueue(self):
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(NEW_REPORT_MSG)

        self.assertFalse(rq.is_empty())
        queue = rq.flush()
        self.assertTrue(rq.is_empty())
        self.assertEqual(len(queue), 1)
        self.assertTrue(queue[0].new_report.config.sharing_enabled)
        self.assertTrue(queue[0].new_report.config.allow_run_on_save)
Пример #3
0
    def test_add_rows_rerun(self):
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(INIT_MSG)

        # Simulate rerun
        for i in range(2):
            TEXT_DELTA_MSG1.metadata.delta_id = 0
            rq.enqueue(TEXT_DELTA_MSG1)

            DF_DELTA_MSG.metadata.delta_id = 1
            rq.enqueue(DF_DELTA_MSG)

            ADD_ROWS_MSG.metadata.delta_id = 1
            rq.enqueue(ADD_ROWS_MSG)

        queue = rq.flush()
        self.assertEqual(len(queue), 3)
        self.assertTrue(queue[0].initialize.config.sharing_enabled)
        self.assertEqual(queue[1].metadata.delta_id, 0)
        self.assertEqual(queue[1].delta.new_element.text.body, "text1")
        self.assertEqual(queue[2].metadata.delta_id, 1)
        col0 = queue[2].delta.new_element.data_frame.data.cols[0].int64s.data
        col1 = queue[2].delta.new_element.data_frame.data.cols[1].int64s.data
        self.assertEqual(col0, [0, 1, 2, 3, 4, 5])
        self.assertEqual(col1, [10, 11, 12, 13, 14, 15])
Пример #4
0
    def test_enqueue_three(self):
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(NEW_REPORT_MSG)

        TEXT_DELTA_MSG1.metadata.delta_path[:] = make_delta_path(
            RootContainer.MAIN, (), 0
        )
        rq.enqueue(TEXT_DELTA_MSG1)

        TEXT_DELTA_MSG2.metadata.delta_path[:] = make_delta_path(
            RootContainer.MAIN, (), 1
        )
        rq.enqueue(TEXT_DELTA_MSG2)

        queue = rq.flush()
        self.assertEqual(len(queue), 3)
        self.assertTrue(queue[0].new_report.config.sharing_enabled)
        self.assertEqual(
            make_delta_path(RootContainer.MAIN, (), 0), queue[1].metadata.delta_path
        )
        self.assertEqual(queue[1].delta.new_element.text.body, "text1")
        self.assertEqual(
            make_delta_path(RootContainer.MAIN, (), 1), queue[2].metadata.delta_path
        )
        self.assertEqual(queue[2].delta.new_element.text.body, "text2")
Пример #5
0
    def test_simple_add_rows(self):
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(NEW_REPORT_MSG)

        TEXT_DELTA_MSG1.metadata.delta_path[:] = make_delta_path(
            RootContainer.MAIN, (), 0
        )
        rq.enqueue(TEXT_DELTA_MSG1)

        DF_DELTA_MSG.metadata.delta_path[:] = make_delta_path(RootContainer.MAIN, (), 1)
        rq.enqueue(DF_DELTA_MSG)

        ADD_ROWS_MSG.metadata.delta_path[:] = make_delta_path(RootContainer.MAIN, (), 1)
        rq.enqueue(ADD_ROWS_MSG)

        queue = rq.flush()
        self.assertEqual(len(queue), 3)
        self.assertTrue(queue[0].new_report.config.sharing_enabled)
        self.assertEqual(
            make_delta_path(RootContainer.MAIN, (), 0), queue[1].metadata.delta_path
        )
        self.assertEqual(queue[1].delta.new_element.text.body, "text1")
        self.assertEqual(
            make_delta_path(RootContainer.MAIN, (), 1), queue[2].metadata.delta_path
        )
        col0 = queue[2].delta.new_element.data_frame.data.cols[0].int64s.data
        col1 = queue[2].delta.new_element.data_frame.data.cols[1].int64s.data
        self.assertEqual(col0, [0, 1, 2, 3, 4, 5])
        self.assertEqual(col1, [10, 11, 12, 13, 14, 15])
Пример #6
0
    def test_multiple_containers(self):
        """Deltas should only be coalesced if they're in the same container"""
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(INIT_MSG)

        def enqueue_deltas(container, path):
            # We deep-copy the protos because we mutate each one
            # multiple times.
            msg = copy.deepcopy(TEXT_DELTA_MSG1)
            msg.metadata.delta_id = 0
            msg.metadata.parent_block.container = container
            msg.metadata.parent_block.path[:] = path
            rq.enqueue(msg)

            msg = copy.deepcopy(DF_DELTA_MSG)
            msg.metadata.delta_id = 1
            msg.metadata.parent_block.container = container
            msg.metadata.parent_block.path[:] = path
            rq.enqueue(msg)

            msg = copy.deepcopy(ADD_ROWS_MSG)
            msg.metadata.delta_id = 1
            msg.metadata.parent_block.container = container
            msg.metadata.parent_block.path[:] = path
            rq.enqueue(msg)

        enqueue_deltas(BlockPath.MAIN, [])
        enqueue_deltas(BlockPath.SIDEBAR, [0, 0, 1])

        def assert_deltas(container, path, idx):
            self.assertEqual(0, queue[idx].metadata.delta_id)
            self.assertEqual(container,
                             queue[idx].metadata.parent_block.container)
            self.assertEqual(path, queue[idx].metadata.parent_block.path)
            self.assertEqual("text1", queue[idx].delta.new_element.text.body)

            self.assertEqual(1, queue[idx + 1].metadata.delta_id)
            self.assertEqual(container,
                             queue[idx + 1].metadata.parent_block.container)
            self.assertEqual(path, queue[idx + 1].metadata.parent_block.path)
            col0 = queue[
                idx + 1].delta.new_element.data_frame.data.cols[0].int64s.data
            col1 = queue[
                idx + 1].delta.new_element.data_frame.data.cols[1].int64s.data
            self.assertEqual([0, 1, 2, 3, 4, 5], col0)
            self.assertEqual([10, 11, 12, 13, 14, 15], col1)

        queue = rq.flush()
        self.assertEqual(5, len(queue))
        self.assertTrue(queue[0].initialize.config.sharing_enabled)

        assert_deltas(BlockPath.MAIN, [], 1)
        assert_deltas(BlockPath.SIDEBAR, [0, 0, 1], 3)
Пример #7
0
    def test_enqueue_two(self):
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(INIT_MSG)

        TEXT_DELTA_MSG1.metadata.delta_id = 0
        rq.enqueue(TEXT_DELTA_MSG1)

        queue = rq.flush()
        self.assertEqual(len(queue), 2)
        self.assertTrue(queue[0].initialize.config.sharing_enabled)
        self.assertEqual(queue[1].metadata.delta_id, 0)
        self.assertEqual(queue[1].delta.new_element.text.body, "text1")
Пример #8
0
    def test_enqueue_two(self):
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(INIT_MSG)

        TEXT_DELTA_MSG1.metadata.delta_path[:] = make_delta_path(
            RootContainer.MAIN, (), 0)
        rq.enqueue(TEXT_DELTA_MSG1)

        queue = rq.flush()
        self.assertEqual(len(queue), 2)
        self.assertTrue(queue[0].initialize.config.sharing_enabled)
        self.assertEqual(make_delta_path(RootContainer.MAIN, (), 0),
                         queue[1].metadata.delta_path)
        self.assertEqual(queue[1].delta.new_element.text.body, "text1")
Пример #9
0
    def test_multiple_containers(self):
        """Deltas should only be coalesced if they're in the same container"""
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        rq.enqueue(NEW_REPORT_MSG)

        def enqueue_deltas(container: RootContainer, path: Tuple[int, ...]):
            # We deep-copy the protos because we mutate each one
            # multiple times.
            msg = copy.deepcopy(TEXT_DELTA_MSG1)
            msg.metadata.delta_path[:] = make_delta_path(container, path, 0)
            rq.enqueue(msg)

            msg = copy.deepcopy(DF_DELTA_MSG)
            msg.metadata.delta_path[:] = make_delta_path(container, path, 1)
            rq.enqueue(msg)

            msg = copy.deepcopy(ADD_ROWS_MSG)
            msg.metadata.delta_path[:] = make_delta_path(container, path, 1)
            rq.enqueue(msg)

        enqueue_deltas(RootContainer.MAIN, ())
        enqueue_deltas(RootContainer.SIDEBAR, (0, 0, 1))

        def assert_deltas(container: RootContainer, path: Tuple[int, ...],
                          idx: int):
            self.assertEqual(make_delta_path(container, path, 0),
                             queue[idx].metadata.delta_path)
            self.assertEqual("text1", queue[idx].delta.new_element.text.body)

            self.assertEqual(make_delta_path(container, path, 1),
                             queue[idx + 1].metadata.delta_path)
            col0 = queue[
                idx + 1].delta.new_element.data_frame.data.cols[0].int64s.data
            col1 = queue[
                idx + 1].delta.new_element.data_frame.data.cols[1].int64s.data
            self.assertEqual([0, 1, 2, 3, 4, 5], col0)
            self.assertEqual([10, 11, 12, 13, 14, 15], col1)

        queue = rq.flush()
        self.assertEqual(5, len(queue))
        self.assertTrue(queue[0].new_report.config.sharing_enabled)

        assert_deltas(RootContainer.MAIN, (), 1)
        assert_deltas(RootContainer.SIDEBAR, (0, 0, 1), 3)
Пример #10
0
    def test_dont_replace_block(self, other_msg: ForwardMsg):
        """add_block deltas should never be replaced/composed because they can
        have dependent deltas later in the queue."""
        rq = ReportQueue()
        self.assertTrue(rq.is_empty())

        ADD_BLOCK_MSG.metadata.delta_path[:] = make_delta_path(
            RootContainer.MAIN, (), 0)

        other_msg.metadata.delta_path[:] = make_delta_path(
            RootContainer.MAIN, (), 0)

        # Delta messages should not replace `add_block` deltas with the
        # same delta_path.
        rq.enqueue(ADD_BLOCK_MSG)
        rq.enqueue(other_msg)
        queue = rq.flush()
        self.assertEqual(len(queue), 2)
        self.assertEqual(queue[0], ADD_BLOCK_MSG)
        self.assertEqual(queue[1], other_msg)