Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
cptpiepmatz committed Sep 14, 2024
1 parent 45f3edf commit 37037b6
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,43 @@ def kernel():
km.shutdown_kernel()


def ok(client: BlockingKernelClient, code: str):
def ok(client: BlockingKernelClient, code: str) -> list[dict]:
# wait until client is ready, then send some code
client.wait_for_ready(timeout=120)
client.execute(code)
iopub_reply = client.get_iopub_msg(timeout=120)

# kernel should instantly reply with busy message
busy_status = client.get_iopub_msg(timeout=120)
assert busy_status["content"]["execution_state"] == "busy"

# check on the iopub channel until we receive an idle message
contents = []
while True:
iopub_reply = client.get_iopub_msg(timeout=120)
if iopub_reply["content"].get("execution_state") == "idle": break
contents.append(iopub_reply["content"])

# we should get a ok on the shell channel
shell_reply = client.get_shell_msg(timeout=120)
assert shell_reply["content"]["status"] == "ok"
return iopub_reply["content"]

return contents


def test_basic_rendering(kernel: BlockingKernelClient):
content = ok(kernel, "$nuju")
data = content["data"]
contents = ok(kernel, "$nuju")
assert len(contents) == 1
data = contents[0]["data"]
assert "application/json" in data
assert "text/plain" in data
assert "text/html" in data
assert "text/markdown" in data


def test_nuju_content(kernel: BlockingKernelClient):
content = ok(kernel, "$nuju")
data = content["data"]
contents = ok(kernel, "$nuju")
assert len(contents) == 1
data = contents[0]["data"]
nuju_constant = json.loads(data["application/json"])
with open("Cargo.toml", "rb") as cargo_toml_file:
cargo_toml = tomllib.load(cargo_toml_file)
Expand Down

0 comments on commit 37037b6

Please sign in to comment.