Skip to content

Commit

Permalink
comments and clarifications
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarshall committed Jul 15, 2024
1 parent beb4465 commit 0f27843
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pytest_pyodide/node_test_driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ rl.on("line", async function (line) {
return;
}
if (line !== cur_uuid) {
// each line ends with an extra $, to avoid problems with end-of-line
// translation etc.
line = line.substring(0, line.lastIndexOf('$'))
if(line === ""){
cur_code += "\n";
} else {
cur_code += line;
}
console.log("OK")
// tell runner.py that the line has been read
// so it can send the next line without worrying about
// filling buffers
console.log("{LINE_OK}")
} else {
evalCode(cur_uuid, cur_code, context);
cur_code = "";
Expand Down
15 changes: 12 additions & 3 deletions pytest_pyodide/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,20 +607,29 @@ def run_js_inner(self, code, check_code):

cmd_id = str(uuid4())
self.p.sendline(cmd_id)
# split lines into shorter buffers
# split long lines into shorter buffers
# because some ttys don't like long
# single lines
all_lines = wrapped.split("\n")
for c, line in enumerate(all_lines):
count = 0
while count < len(line):
to_read = min(128, len(line) - count)
# each sent line ends with an extra $, to avoid problems with end-of-line
# translation etc. it doesn't matter if there are $ in the string elsewhere
# because the last $ is always the one we added
self.p.sendline(line[count : count + to_read] + "$")
self.p.expect_exact("OK\r\n")
# after we send a line, we wait for a response
# before sending the next line
# this means we don't overflow input buffers
self.p.expect_exact("{LINE_OK}\r\n")
count += to_read
if c < len(all_lines) - 1:
# to insert a line break into the received code string
# we send a blank line with just the $ end-of-line character
# and await response
self.p.sendline("$")
self.p.expect_exact("OK\r\n")
self.p.expect_exact("{LINE_OK}\r\n")
self.p.sendline(cmd_id)
self.p.expect_exact(f"{cmd_id}:UUID\r\n", timeout=self.script_timeout)
self.p.expect_exact(f"{cmd_id}:UUID\r\n")
Expand Down

0 comments on commit 0f27843

Please sign in to comment.