summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-09-16 13:05:15 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-09-16 13:05:15 +0300
commit75163325ae3fc33ebb9919231289fadec620d124 (patch)
treeb5ef4bba76cbcce561787f364b1879aa3157b127
parent280fb4d92830bedb1f4ef90554300e444661ef8c (diff)
tests/cpydiff: Add cases for locals() discrepancies.
MicroPython doesn't maintain local symbolic environment, so any feature depending on it won't work as expected.
-rw-r--r--tests/cpydiff/core_locals.py11
-rw-r--r--tests/cpydiff/core_locals_eval.py14
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/cpydiff/core_locals.py b/tests/cpydiff/core_locals.py
new file mode 100644
index 000000000..0240e5a1a
--- /dev/null
+++ b/tests/cpydiff/core_locals.py
@@ -0,0 +1,11 @@
+"""
+categories: Core,Runtime
+description: Local variables aren't included in locals() result
+cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name.
+workaround: Unknown
+"""
+def test():
+ val = 2
+ print(locals())
+
+test()
diff --git a/tests/cpydiff/core_locals_eval.py b/tests/cpydiff/core_locals_eval.py
new file mode 100644
index 000000000..8416e3b06
--- /dev/null
+++ b/tests/cpydiff/core_locals_eval.py
@@ -0,0 +1,14 @@
+"""
+categories: Core,Runtime
+description: Code running in eval() function doesn't have access to local variables
+cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.
+workaround: Unknown
+"""
+val = 1
+
+def test():
+ val = 2
+ print(val)
+ eval("print(val)")
+
+test()