Skip to content

Commit eb90998

Browse files
author
Drew O'Meara
committed
kwarg testing (exposes bugs in py.ParseTupleAndKeywords)
1 parent 965bc08 commit eb90998

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

builtin/tests/builtin.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,40 +299,43 @@ def gen2():
299299
doc="print"
300300
ok = False
301301
try:
302-
print("hello", sep=1)
302+
print("hello", sep=1, end="!")
303303
except TypeError as e:
304-
#if e.args[0] != "sep must be None or a string, not int":
305-
# raise
304+
if e.args[0] != "print() argument 1 must be str, not int":
305+
raise
306306
ok = True
307307
assert ok, "TypeError not raised"
308308

309309
try:
310-
print("hello", sep=" ", end=1)
310+
print("hello", sep=",", end=1)
311311
except TypeError as e:
312-
#if e.args[0] != "end must be None or a string, not int":
313-
# raise
312+
if e.args[0] != "print() argument 2 must be str, not int":
313+
raise
314314
ok = True
315315
assert ok, "TypeError not raised"
316316

317317
try:
318-
print("hello", sep=" ", end="\n", file=1)
318+
print("hello", sep=",", end="!", file=1)
319319
except AttributeError as e:
320-
#if e.args[0] != "'int' object has no attribute 'write'":
321-
# raise
320+
if e.args[0] != "'int' has no attribute 'write'":
321+
raise
322322
ok = True
323323
assert ok, "AttributeError not raised"
324324

325325
with open("testfile", "w") as f:
326-
print("hello", "world", sep=" ", end="\n", file=f)
326+
print("hello", "world", end="!\n", file=f, sep=", ")
327+
print("hells", "bells", end="...", file=f)
328+
print(" ~", "Brother ", "Foo", "bar", file=f, end="", sep="")
327329

328330
with open("testfile", "r") as f:
329-
assert f.read() == "hello world\n"
331+
assert f.read() == "hello, world!\nhells bells... ~Brother Foobar"
330332

331333
with open("testfile", "w") as f:
332-
print(1,2,3,sep=",",end=",\n", file=f)
334+
print(1,2,3,sep=",", flush=False, end=",\n", file=f)
335+
print("4",5, file=f, end="!", flush=True, sep=",")
333336

334337
with open("testfile", "r") as f:
335-
assert f.read() == "1,2,3,\n"
338+
assert f.read() == "1,2,3,\n4,5!"
336339

337340
doc="round"
338341
assert round(1.1) == 1.0

0 commit comments

Comments
 (0)