micropython/tests/basics/dict1.py
Damien George 8979ce1671 tests: Modify tests that print repr of an exception with 1 arg.
In Python 3.7 the behaviour of repr() of an exception with one argument
changed: it no longer prints a trailing comma in the argument list.  See
https://bugs.python.org/issue30399

This patch modifies tests that rely on this behaviour to not rely on it.
And the python34.py test is updated to include a test for this behaviour
with a .exp file.
2018-08-17 15:46:04 +10:00

43 lines
664 B
Python

# basic dictionary
d = {}
print(d)
d[2] = 123
print(d)
d = {1:2}
d[3] = 3
print(len(d), d[1], d[3])
d[1] = 0
print(len(d), d[1], d[3])
print(str(d) == '{1: 0, 3: 3}' or str(d) == '{3: 3, 1: 0}')
x = 1
while x < 100:
d[x] = x
x += 1
print(d[50])
# equality operator on dicts of different size
print({} == {1:1})
# equality operator on dicts of same size but with different keys
print({1:1} == {2:1})
# value not found
try:
{}[0]
except KeyError as er:
print('KeyError', er, er.args)
# unsupported unary op
try:
+{}
except TypeError:
print('TypeError')
# unsupported binary op
try:
{} + {}
except TypeError:
print('TypeError')