diff options
Diffstat (limited to 'packages/meshbay-hub/tests/test_transfers.py')
| -rw-r--r-- | packages/meshbay-hub/tests/test_transfers.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/packages/meshbay-hub/tests/test_transfers.py b/packages/meshbay-hub/tests/test_transfers.py index b1bac4a..1d0c0f0 100644 --- a/packages/meshbay-hub/tests/test_transfers.py +++ b/packages/meshbay-hub/tests/test_transfers.py @@ -26,15 +26,15 @@ pytestmark = pytest.mark.skipif( def _run(body, tmp_path): module = tmp_path / "transfers.mjs" - module.write_text(TRANSFERS.read_text()) + module.write_text(TRANSFERS.read_text(encoding="utf-8"), encoding="utf-8") script = tmp_path / "case.mjs" script.write_text( - f"import {{ TransferStore, formatSpeed }} from '{module.as_posix()}';\n" + f"import {{ TransferStore, formatSpeed }} from '{module.as_uri()}';\n" "const out = [];\n" "const say = (...a) => out.push(...a);\n" f"{body}\n" - "console.log(JSON.stringify(out));\n") - proc = subprocess.run(["node", str(script)], capture_output=True, text=True) + "console.log(JSON.stringify(out));\n", encoding="utf-8") + proc = subprocess.run(["node", str(script)], capture_output=True, text=True, encoding="utf-8") assert proc.returncode == 0, proc.stderr return json.loads(proc.stdout) @@ -388,11 +388,11 @@ def test_asking_for_a_slot_on_a_dead_channel_does_not_throw(tmp_path): # first time it arms its watchdog. start = src.index("const LEASE_WATCHDOG_MS") end = src.index("\nclass MeshBayTransport") - module.write_text(src[start:end] + "\nexport { Lease };\n") + module.write_text(src[start:end] + "\nexport { Lease };\n", encoding="utf-8") script = tmp_path / "case.mjs" script.write_text(f""" -import {{ Lease }} from '{module.as_posix()}'; +import {{ Lease }} from '{module.as_uri()}'; const out = []; const transport = {{ supportsTransferSlots: true, @@ -409,8 +409,8 @@ try {{ lease.release('cancelled'); out.push('release ok'); }} catch (e) {{ out.push('release threw: ' + e.message); }} clearTimeout(lease._watchdog); console.log(JSON.stringify(out)); -""") - proc = subprocess.run(["node", str(script)], capture_output=True, text=True) +""", encoding="utf-8") + proc = subprocess.run(["node", str(script)], capture_output=True, text=True, encoding="utf-8") assert proc.returncode == 0, proc.stderr out = json.loads(proc.stdout) assert out[0] is None, f"asking for a slot threw: {out[0]}" @@ -433,7 +433,7 @@ def test_the_slot_is_asked_for_after_there_is_somewhere_to_write(): Source-reading, because the ordering is the whole property and it has no behaviour of its own to drive: what matters is which call comes first. """ - src = (STATIC / "file-utils.js").read_text() + src = (STATIC / "file-utils.js").read_text(encoding="utf-8") fn = src[src.index("async function downloadEntry"):] fn = fn[:fn.index("\n}\n")] # `_openTargetInTurn` since target openings were serialised — same call, @@ -832,7 +832,7 @@ def test_a_paused_transfer_is_not_filed_under_finished(tmp_path): here: a copy of them in this file would agree with a broken version by construction. """ - src = (STATIC / "app.js").read_text() + src = (STATIC / "app.js").read_text(encoding="utf-8") start = src.index(" const running = items.filter(") block = src[start:src.index("const active =", start)] @@ -851,8 +851,8 @@ const items = [ const seen = { running, waiting, paused, finished }; console.log(JSON.stringify(Object.fromEntries( Object.entries(seen).map(([k, v]) => [k, v.map(i => i.id)])))); -""") - proc = subprocess.run(["node", str(script)], capture_output=True, text=True) +""", encoding="utf-8") + proc = subprocess.run(["node", str(script)], capture_output=True, text=True, encoding="utf-8") assert proc.returncode == 0, proc.stderr groups = json.loads(proc.stdout) @@ -870,7 +870,7 @@ def test_a_paused_transfer_still_counts_as_active(tmp_path): """The badge says how much is going on. A paused transfer is not over — the person means to come back to it — so counting it as nothing would be a panel that says "0" over work that is still there.""" - src = (STATIC / "app.js").read_text() + src = (STATIC / "app.js").read_text(encoding="utf-8") start = src.index(" const running = items.filter(") block = src[start:src.index("\n\n", src.index("const active =", start))] @@ -879,8 +879,8 @@ def test_a_paused_transfer_still_counts_as_active(tmp_path): const items = [{ id: 1, status: 'paused' }, { id: 2, status: 'done' }]; """ + block + """ console.log(JSON.stringify({ active })); -""") - proc = subprocess.run(["node", str(script)], capture_output=True, text=True) +""", encoding="utf-8") + proc = subprocess.run(["node", str(script)], capture_output=True, text=True, encoding="utf-8") assert proc.returncode == 0, proc.stderr assert json.loads(proc.stdout)["active"] == 1 @@ -897,7 +897,7 @@ def test_a_row_that_cannot_pause_says_so_where_the_button_would_be(): Shown only where a folder can actually be chosen: Firefox and Safari have none to choose, and "choose a folder" would be advice that cannot be taken. """ - src = (STATIC / "app.js").read_text() + src = (STATIC / "app.js").read_text(encoding="utf-8") row = src[src.index("function TransferRow"):] row = row[:row.index("\n}\n")] @@ -917,4 +917,4 @@ def test_the_reason_is_translated_everywhere(): """`t()` falls back to the key, so a missing catalogue entry shows `transfers.not_pausable` in a tooltip rather than a sentence.""" for path in sorted((STATIC / "locales").glob("*.js")): - assert "'transfers.not_pausable'" in path.read_text(), path.name + assert "'transfers.not_pausable'" in path.read_text(encoding="utf-8"), path.name |