Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable test_history #73

Open
romainfrancois opened this issue Dec 14, 2023 · 0 comments
Open

enable test_history #73

romainfrancois opened this issue Dec 14, 2023 · 0 comments

Comments

@romainfrancois
Copy link
Contributor

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 = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant