support/testing: micropython: add micropython-lib test
PATCH 1/1 support/testing: micropython: add micropython-lib test
Commit 8f403f0 "package/micropython-lib: merge with, and install as part of micropython" brought micropython library within the package.
This commit improves the micropython runtime test by enabling the micropython-lib and by also adding a runtime test using one of its module.
--- support/testing/tests/package/test_micropython.py | 13 ++++++++++++- .../test_micropython/rootfs-overlay/root/zcat.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 support/testing/tests/package/test_micropython/rootfs-overlay/root/zcat.py
support/testing/tests/package/test_micropython.py +12 -1
@@ -7,6 +7,7 @@ class TestMicroPython(infra.basetest.BRTest): config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ f""" BR2_PACKAGE_MICROPYTHON=y + BR2_PACKAGE_MICROPYTHON_LIB=y BR2_ROOTFS_OVERLAY="{infra.filepath("tests/package/test_micropython/rootfs-overlay")}" BR2_TARGET_ROOTFS_CPIO=y # BR2_TARGET_ROOTFS_TAR is not set
@@ -64,5 +65,15 @@ class TestMicroPython(infra.basetest.BRTest): output = self.run_upy_code(py_code) self.assertEqual(output[0], expected_output) - # Finally, Check a small script can execute. + # Check a small script can execute. self.assertRunOk("/root/mandel.py", timeout=10) + + # Check we can use a micropython-lib module. + msg = "Hello Buildroot!" + filename = "file.txt" + gz_filename = f"{filename}.gz" + self.assertRunOk(f"echo '{msg}' > {filename}") + self.assertRunOk(f"gzip {filename}") + out, ret = self.emulator.run(f"/root/zcat.py {gz_filename}") + self.assertEqual(ret, 0) + self.assertEqual(out[0], msg)
support/testing/tests/package/test_micropython/rootfs-overlay/root/zcat.py new file +15 -0
@@ -0,0 +1,15 @@ +#! /usr/bin/env micropython + +import gzip +import sys + + +def main(fname): + with open(fname, "rb") as f: + with gzip.GzipFile(fileobj=f) as g: + s = g.read() + print(s.decode("UTF-8"), end="") + + +if __name__ == "__main__": + main(sys.argv[1])
Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Yann E. MORIN
AppliedJulien, All,
On 2024-02-04 10:31 +0100, Julien Olivain spake thusly:
Quoted 7 lines
Commit 8f403f0 "package/micropython-lib: merge with, and install as part of micropython" brought micropython library within the package.
This commit improves the micropython runtime test by enabling the micropython-lib and by also adding a runtime test using one of its module.
I added a little blurb explaining why we can't use the gzip module itself to generate the compressed file.
Quoted 1 line
Signed-off-by Julien Olivain <[email protected]>
Applied to master, thanks.
Regards,
Yann E. MORIN.
Quoted 63 lines
--- support/testing/tests/package/test_micropython.py | 13 ++++++++++++- .../test_micropython/rootfs-overlay/root/zcat.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 support/testing/tests/package/test_micropython/rootfs-overlay/root/zcat.pysupport/testing/tests/package/test_micropython.py +12
-1@@ -7,6 +7,7 @@ class TestMicroPython(infra.basetest.BRTest): config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ f""" BR2_PACKAGE_MICROPYTHON=y + BR2_PACKAGE_MICROPYTHON_LIB=y BR2_ROOTFS_OVERLAY="{infra.filepath("tests/package/test_micropython/rootfs-overlay")}" BR2_TARGET_ROOTFS_CPIO=y # BR2_TARGET_ROOTFS_TAR is not set@@ -64,5 +65,15 @@ class TestMicroPython(infra.basetest.BRTest): output = self.run_upy_code(py_code) self.assertEqual(output[0], expected_output) - # Finally, Check a small script can execute. + # Check a small script can execute. self.assertRunOk("/root/mandel.py", timeout=10) + + # Check we can use a micropython-lib module. + msg = "Hello Buildroot!" + filename = "file.txt" + gz_filename = f"{filename}.gz" + self.assertRunOk(f"echo '{msg}' > {filename}") + self.assertRunOk(f"gzip {filename}") + out, ret = self.emulator.run(f"/root/zcat.py {gz_filename}") + self.assertEqual(ret, 0) + self.assertEqual(out[0], msg)support/testing/tests/package/test_micropython/rootfs-overlay/root/zcat.py new file +15
-0@@ -0,0 +1,15 @@ +#! /usr/bin/env micropython + +import gzip +import sys + + +def main(fname): + with open(fname, "rb") as f: + with gzip.GzipFile(fileobj=f) as g: + s = g.read() + print(s.decode("UTF-8"), end="") + + +if __name__ == "__main__": + main(sys.argv[1])Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot