791b65f4b2
Having a micropython.const identity function, and writing "from micropython import const" at the start of scripts that use the const feature, allows to write scripts which are compatible with CPython, and with uPy builds that don't include const optimisation. This patch adds such a function and updates the tests to do the import.
16 lines
321 B
Python
16 lines
321 B
Python
# make sure syntax error works correctly for bad const definition
|
|
|
|
from micropython import const
|
|
|
|
def test_syntax(code):
|
|
try:
|
|
exec(code)
|
|
except SyntaxError:
|
|
print("SyntaxError")
|
|
|
|
# argument not a constant
|
|
test_syntax("a = const(x)")
|
|
|
|
# redefined constant
|
|
test_syntax("A = const(1); A = const(2)")
|