Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build micropython
env:
CFLAGS_EXTRA: "-DMICROPY_PY_OS_DUPTERM=2" # os.dupterm support on unix
run: |
git clone --depth 1 https://github.com/micropython/micropython.git
git clone -b v1.24-release --depth=1 --single-branch https://github.com/micropython/micropython.git
cd micropython
git submodule update --init
make -C mpy-cross
cp mpy-cross/build/mpy-cross /usr/local/bin/
make -C ports/unix
cp ports/unix/build-standard/micropython /usr/local/bin/
cd ..
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TODO

## Developing

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`.
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`.

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

Expand Down
9 changes: 1 addition & 8 deletions mqterm/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
from binascii import hexlify
from hashlib import sha256
from io import BytesIO

try:
from os import dupterm
except ImportError:
# unix mpy doesn't have dupterm; define a no-op version
def dupterm(stream_object, index=0):
return stream_object

from os import dupterm

from micropython import const

Expand Down
10 changes: 10 additions & 0 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,13 @@ def test_exec(self):
self.assertEqual(job_output, "") # No output expected
self.assertEqual(file_output, "Hello, World!")
os.remove("output.txt")

# NOTE: on unix micropython you need to compile with MICROPY_PY_OS_DUPTERM
# to capture output. If this fails, see:
# https://forum.micropython.org/viewtopic.php?t=7055
def test_exec_output(self):
"""RunPyJob should capture output from executed script"""
cmd = 'import sys; sys.stdout.write("Hello, World!")'
job = RunPyJob("exec", [cmd])
output = job.output().read().decode("utf-8").strip()
self.assertEqual(output, "Hello, World!")
Loading