diff options
author | Damien George <damien@micropython.org> | 2025-01-20 22:24:10 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-02-11 16:54:20 +1100 |
commit | c3a18d74ebebe1c68955c3dce3c782af949aa4c7 (patch) | |
tree | 1e76917c9e98b1ee1b4196e4533cb429e5ec8d94 /tests/extmod/marshal_micropython.py | |
parent | a11ba7775e600b45c0e93443ca05dffb09a49389 (diff) | |
download | micropython-c3a18d74ebebe1c68955c3dce3c782af949aa4c7.tar.gz micropython-c3a18d74ebebe1c68955c3dce3c782af949aa4c7.zip |
extmod/modmarshal: Add new marshal module.
This commit implements a small subset of the CPython `marshal` module. It
implements `marshal.dumps()` and `marshal.loads()`, but only supports
(un)marshalling code objects at this stage. The semantics match CPython,
except that the actual marshalled bytes is not compatible with CPython's
marshalled bytes.
The module is enabled at the everything level (only on the unix coverage
build at this stage).
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests/extmod/marshal_micropython.py')
-rw-r--r-- | tests/extmod/marshal_micropython.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/extmod/marshal_micropython.py b/tests/extmod/marshal_micropython.py new file mode 100644 index 0000000000..213b3bf318 --- /dev/null +++ b/tests/extmod/marshal_micropython.py @@ -0,0 +1,21 @@ +# Test the marshal module, MicroPython-specific functionality. + +try: + import marshal +except ImportError: + print("SKIP") + raise SystemExit + +import unittest + + +class Test(unittest.TestCase): + def test_function_with_children(self): + # Can't marshal a function with children (in this case the module has a child function f). + code = compile("def f(): pass", "", "exec") + with self.assertRaises(ValueError): + marshal.dumps(code) + + +if __name__ == "__main__": + unittest.main() |