Author: Brian Kearns <bdkea...@gmail.com>
Branch: 
Changeset: r70993:e87d8dddb7f3
Date: 2014-04-25 19:38 -0400
http://bitbucket.org/pypy/pypy/changeset/e87d8dddb7f3/

Log:    test/fix tcsetattr validation of attributes

diff --git a/pypy/module/termios/interp_termios.py 
b/pypy/module/termios/interp_termios.py
--- a/pypy/module/termios/interp_termios.py
+++ b/pypy/module/termios/interp_termios.py
@@ -4,7 +4,7 @@
 """
 
 from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import wrap_oserror
+from pypy.interpreter.error import wrap_oserror, OperationError
 from rpython.rlib import rtermios
 import termios
 
@@ -19,6 +19,10 @@
 @unwrap_spec(when=int)
 def tcsetattr(space, w_fd, when, w_attributes):
     fd = space.c_filedescriptor_w(w_fd)
+    if not space.isinstance_w(w_attributes, space.w_list) or \
+            space.len_w(w_attributes) != 7:
+        raise OperationError(space.w_TypeError, space.wrap(
+            "tcsetattr, arg 3: must be 7 element list"))
     w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed, w_cc = \
              space.unpackiterable(w_attributes, expected_length=7)
     w_builtin = space.getbuiltinmodule('__builtin__')
diff --git a/pypy/module/termios/test/test_termios.py 
b/pypy/module/termios/test/test_termios.py
--- a/pypy/module/termios/test/test_termios.py
+++ b/pypy/module/termios/test/test_termios.py
@@ -149,4 +149,7 @@
 
     def test_error_tcsetattr(self):
         import termios
-        raises(ValueError, termios.tcsetattr, 0, 1, (1, 2))
+        exc = raises(TypeError, termios.tcsetattr, 0, 1, (1, 2))
+        assert str(exc.value) == "tcsetattr, arg 3: must be 7 element list"
+        exc = raises(TypeError, termios.tcsetattr, 0, 1, (1, 2, 3, 4, 5, 6, 7))
+        assert str(exc.value) == "tcsetattr, arg 3: must be 7 element list"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to