summaryrefslogtreecommitdiff
path: root/tests/micropython
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2016-10-10 11:42:59 -0700
committerScott Shawcroft <scott@chickadee.tech>2016-10-10 11:42:59 -0700
commita52fd670e66e72dc60d460016a2f1f03a65dbeb6 (patch)
tree3b5af151ff68fcbf772e5348efd43d770445508c /tests/micropython
parenta6254f4344be4f54232149adb5d834ab9561846c (diff)
parent89bfbfdeee2c86a18ccab6dce41bbd3e4597c981 (diff)
Merge remote-tracking branch 'micropython/master'
Diffstat (limited to 'tests/micropython')
-rw-r--r--tests/micropython/const.py2
-rw-r--r--tests/micropython/const2.py34
-rw-r--r--tests/micropython/const2.py.exp4
-rw-r--r--tests/micropython/const_error.py2
4 files changed, 42 insertions, 0 deletions
diff --git a/tests/micropython/const.py b/tests/micropython/const.py
index 09717fd14..660a095f2 100644
--- a/tests/micropython/const.py
+++ b/tests/micropython/const.py
@@ -1,5 +1,7 @@
# test constant optimisation
+from micropython import const
+
X = const(123)
Y = const(X + 456)
diff --git a/tests/micropython/const2.py b/tests/micropython/const2.py
new file mode 100644
index 000000000..60085a1e0
--- /dev/null
+++ b/tests/micropython/const2.py
@@ -0,0 +1,34 @@
+# check that consts are not replaced in anything except standalone identifiers
+
+from micropython import const
+
+X = const(1)
+Y = const(2)
+Z = const(3)
+
+# import that uses a constant
+import micropython as X
+print(globals()['X'])
+
+# function name that matches a constant
+def X():
+ print('function X', X)
+globals()['X']()
+
+# arguments that match a constant
+def f(X, *Y, **Z):
+ pass
+f(1)
+
+# class name that matches a constant
+class X:
+ def f(self):
+ print('class X', X)
+globals()['X']().f()
+
+# constant within a class
+class A:
+ C1 = const(4)
+ def X(self):
+ print('method X', Y, C1, self.C1)
+A().X()
diff --git a/tests/micropython/const2.py.exp b/tests/micropython/const2.py.exp
new file mode 100644
index 000000000..0568f91ce
--- /dev/null
+++ b/tests/micropython/const2.py.exp
@@ -0,0 +1,4 @@
+<module 'micropython'>
+function X 1
+class X 1
+method X 2 4 4
diff --git a/tests/micropython/const_error.py b/tests/micropython/const_error.py
index b46efcae2..6d3d135b5 100644
--- a/tests/micropython/const_error.py
+++ b/tests/micropython/const_error.py
@@ -1,5 +1,7 @@
# make sure syntax error works correctly for bad const definition
+from micropython import const
+
def test_syntax(code):
try:
exec(code)