jupyter-xeus / xeus-r

Jupyter kernel for the R programming language
Other
42 stars 5 forks source link

enable `test_history` #73

Open romainfrancois opened 9 months ago

romainfrancois commented 9 months ago

https://github.com/jupyter/jupyter_kernel_test/blob/55e33601f4ab3ca4c7ac45ddc4c538b2769c3f68/jupyter_kernel_test/__init__.py#L308

def test_history(self) -> None:
        if not self.code_execute_result:
            raise SkipTest("No code execute result")  # noqa

        codes = [s["code"] for s in self.code_execute_result]
        _ = [s.get("result", "") for s in self.code_execute_result]
        n = len(codes)

        session = start = None

        with self.subTest(hist_access_type="tail"):
            if "tail" not in self.supported_history_operations:
                raise SkipTest("History tail not supported")  # noqa
            reply = self.history_helper(codes, output=False, raw=True, hist_access_type="tail", n=n)
            self.assertEqual(len(reply["content"]["history"]), n)
            self.assertEqual(len(reply["content"]["history"][0]), 3)
            self.assertEqual(codes, [h[2] for h in reply["content"]["history"]])

            session, start = reply["content"]["history"][0][0:2]
            with self.subTest(output=True):
                reply = self.history_helper(
                    codes, output=True, raw=True, hist_access_type="tail", n=n
                )
                self.assertEqual(len(reply["content"]["history"][0][2]), 2)

        with self.subTest(hist_access_type="range"):
            if "range" not in self.supported_history_operations:
                raise SkipTest("History range not supported")  # noqa
            if session is None:
                raise SkipTest("No session")  # noqa
            reply = self.history_helper(
                codes,
                output=False,
                raw=True,
                hist_access_type="range",
                session=session,
                start=start,
                stop=start + 1,
            )
            self.assertEqual(len(reply["content"]["history"]), 1)
            self.assertEqual(reply["content"]["history"][0][0], session)
            self.assertEqual(reply["content"]["history"][0][1], start)

        with self.subTest(hist_access_type="search"):
            if not self.code_history_pattern:
                raise SkipTest("No code history pattern")  # noqa
            if "search" not in self.supported_history_operations:
                raise SkipTest("History search not supported")  # noqa
            with self.subTest(subsearch="normal"):
                reply = self.history_helper(
                    codes,
                    output=False,
                    raw=True,
                    hist_access_type="search",
                    pattern=self.code_history_pattern,
                )
                self.assertGreaterEqual(len(reply["content"]["history"]), 1)
            with self.subTest(subsearch="unique"):
                reply = self.history_helper(
                    codes,
                    output=False,
                    raw=True,
                    hist_access_type="search",
                    pattern=self.code_history_pattern,
                    unique=True,
                )
                self.assertEqual(len(reply["content"]["history"]), 1)
            with self.subTest(subsearch="n"):
                reply = self.history_helper(
                    codes,
                    output=False,
                    raw=True,
                    hist_access_type="search",
                    pattern=self.code_history_pattern,
                    n=3,
                )
                self.assertEqual(len(reply["content"]["history"]), 3)

    code_inspect_sample = ""