[Python-checkins] CVS: python/dist/src/Lib/test test_extcall.py,1.2,1.3

Jeremy Hylton python-dev@python.org
Thu, 30 Mar 2000 18:55:27 -0500


Update of /projects/cvsroot/python/dist/src/Lib/test
In directory goon.cnri.reston.va.us:/home/jhylton/python/src/Lib/test

Modified Files:
	test_extcall.py 
Log Message:
Two fixes for extended call syntax:
If a non-tuple sequence is passed as the *arg, convert it to a tuple
before checking its length.
If named keyword arguments are used in combination with **kwargs, make
a copy of kwargs before inserting the new keys.



Index: test_extcall.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/test/test_extcall.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** test_extcall.py	2000/03/28 23:53:18	1.2
--- test_extcall.py	2000/03/30 23:55:24	1.3
***************
*** 47,50 ****
--- 47,94 ----
  g(1, 2, 3)
  g(1, 2, 3, *(4, 5))
+ class Nothing: pass
+ try:
+     g(*Nothing())
+ except AttributeError, attr:
+     assert attr[0] == '__len__'
+ else:
+     print "should raise AttributeError: __len__"
+ 
+ class Nothing:
+     def __len__(self):
+         return 5
+ try:
+     g(*Nothing())
+ except AttributeError, attr:
+     assert attr[0] == '__getitem__'
+ else:
+     print "should raise AttributeError: __getitem__"
+     
+ class Nothing:
+     def __len__(self):
+         return 5
+     def __getitem__(self, i):
+         if i < 3:
+             return i
+         else:
+             raise IndexError, i
+ g(*Nothing())
+ 
+ # make sure the function call doesn't stomp on the dictionary?
+ d = {'a': 1, 'b': 2, 'c': 3}
+ d2 = d.copy()
+ assert d == d2
+ g(1, d=4, **d)
+ print d
+ print d2
+ assert d == d2, "function call modified dictionary"
+ 
+ # what about willful misconduct?
+ def saboteur(**kw):
+     kw['x'] = locals()
+ d = {}
+ saboteur(a=1, **d)
+ assert d == {}
+         
  try:
      g(1, 2, 3, **{'x':4, 'y':5})