8000 tests/basics/string_format_modulo: Add more tests for dict formatting. · nickzoic/micropython-esp32@84fb292 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84fb292

Browse files
committed
tests/basics/string_format_modulo: Add more tests for dict formatting.
1 parent 7317e34 commit 84fb292

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/basics/string_format_modulo.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
print(">%-+08.4d<" % -12)
6767
print(">%-+08.4d<" % 12)
6868

69+
# Should be able to print dicts; in this case they aren't used
70+
# to lookup keywords in formats like %(foo)s
71+
print('%s' % {})
72+
print('%s' % ({},))
73+
6974
# Cases when "*" used and there's not enough values total
7075
try:
7176
print("%*s" % 5)
@@ -77,6 +82,7 @@
7782
print("TypeError")
7883

7984
print("%(foo)s" % {"foo": "bar", "baz": False})
85+
print("%s %(foo)s %(foo)s" % {"foo": 1})
8086
try:
8187
print("%(foo)s" % {})
8288
except KeyError:
@@ -87,6 +93,16 @@
8793
except TypeError:
8894
print("TypeError")
8995

96+
# When using %(foo)s format the single argument must be a dict
97+
try:
98+
'%(foo)s' % 1
99+
except TypeError:
100+
print('TypeError')
101+
try:
102+
'%(foo)s' % ({},)
103+
except TypeError:
104+
print('TypeError')
105+
90106
try:
91107
'%(a' % {'a':1}
92108
except ValueError:

0 commit comments

Comments
 (0)
0