Skip to content

Commit 8ce1905

Browse files
committed
Add instructions on os.dupterm support and a test for exec
1 parent 2504b71 commit 8ce1905

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v2
2626
- name: Build micropython
27+
env:
28+
CFLAGS_EXTRA: "-DMICROPY_PY_OS_DUPTERM=2" # os.dupterm support on unix
2729
run: |
28-
git clone --depth 1 https://github.com/micropython/micropython.git
30+
git clone -b v1.24-release --single-branch https://github.com/micropython/micropython.git
2931
cd micropython
3032
git submodule update --init
3133
make -C mpy-cross

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TODO
2727

2828
## Developing
2929

30-
You need python and a build of micropython with `asyncio` support. Follow the steps in the CI workflow to get a `micropython` binary and add it to your `PATH`.
30+
You need python and a build of micropython with `asyncio` and `os.dupterm` support. Follow the steps in the CI workflow to get a `micropython` binary and add it to your `PATH`.
3131

3232
Before making changes, install the development (CPython) dependencies:
3333

mqterm/jobs.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
from binascii import hexlify
44
from hashlib import sha256
55
from io import BytesIO
6-
7-
try:
8-
from os import dupterm
9-
except ImportError:
10-
# unix mpy doesn't have dupterm; define a no-op version
11-
def dupterm(stream_object, index=0):
12-
return stream_object
13-
6+
from os import dupterm
147

158
from micropython import const
169

tests/test_jobs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,13 @@ def test_exec(self):
272272
self.assertEqual(job_output, "") # No output expected
273273
self.assertEqual(file_output, "Hello, World!")
274274
os.remove("output.txt")
275+
276+
# NOTE: on unix micropython you need to compile with MICROPY_PY_OS_DUPTERM
277+
# to capture output. If this fails, see:
278+
# https://forum.micropython.org/viewtopic.php?t=7055
279+
def test_exec_output(self):
280+
"""RunPyJob should capture output from executed script"""
281+
cmd = 'import sys; sys.stdout.write("Hello, World!")'
282+
job = RunPyJob("exec", [cmd])
283+
output = job.output().read().decode("utf-8").strip()
284+
self.assertEqual(output, "Hello, World!")

0 commit comments

Comments
 (0)