[pypy-svn] r44212 - in pypy/branch/kill-ctypes/pypy/rpython/module: . test

fijal at codespeak.net fijal at codespeak.net
Tue Jun 12 23:22:40 CEST 2007


Author: fijal
Date: Tue Jun 12 23:22:40 2007
New Revision: 44212

Modified:
   pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py
   pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py
Log:
Improve rtermios


Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py	(original)
+++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_termios.py	Tue Jun 12 23:22:40 2007
@@ -13,6 +13,7 @@
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.annotation import model as annmodel
 from pypy.rpython import rclass
+from pypy.rlib import rtermios
 
 # XXX is this portable? well.. not at all, ideally
 # I would like to have NCCS = CLaterConstant(NCCS)
@@ -67,7 +68,7 @@
     finally:
         lltype.free(c_struct, flavor='raw')
 
-register_external(termios.tcgetattr, [int], (int, int, int, int, int, int, [str]),
+register_external(rtermios.tcgetattr, [int], (int, int, int, int, int, int, [str]),
                   llimpl=tcgetattr_llimpl, export_name='termios.tcgetattr')
 
 def tcsetattr_llimpl(fd, when, attributes):
@@ -90,7 +91,7 @@
         lltype.free(c_struct, flavor='raw')
 
 r_uint = rffi.r_uint
-register_external(termios.tcsetattr, [int, int, (r_uint, r_uint, r_uint,
+register_external(rtermios.tcsetattr, [int, int, (r_uint, r_uint, r_uint,
                   r_uint, r_uint, r_uint, [str])], llimpl=tcsetattr_llimpl,
                   export_name='termios.tcsetattr')
 

Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py	(original)
+++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_termios.py	Tue Jun 12 23:22:40 2007
@@ -38,24 +38,25 @@
         sys.path.insert(0, '%s')
         from pypy.translator.c.test.test_genc import compile
         import termios
+        from pypy.rlib import rtermios
         def runs_tcgetattr():
-            tpl = list(termios.tcgetattr(2)[:-1])
+            tpl = list(rtermios.tcgetattr(2)[:-1])
             print tpl
 
         fn = compile(runs_tcgetattr, [], backendopt=False,
 )
         print 'XXX'
         fn(expected_extra_mallocs=1)
-        print str(termios.tcgetattr(2)[:-1])
+        print str(rtermios.tcgetattr(2)[:-1])
         """ % os.path.dirname(pypydir))
         f = udir.join("test_tcgetattr.py")
         f.write(source)
         child = self.spawn([str(f)])
         child.expect("XXX")
-        child.expect('\[[^\]]*\]')
-        first = child.match.group(0)
-        child.expect('\[[^\]]*\]')
-        second = child.match.group(0)
+        child.expect('\[([^\]]*)\]')
+        first = child.match.group(1)
+        child.expect('\(([^\]]*)\)')
+        second = child.match.group(1)
         assert first == second
 
     def test_tcgetattr2(self):
@@ -64,10 +65,11 @@
         sys.path.insert(0, '%s')
         from pypy.translator.c.test.test_genc import compile
         from pypy.rpython.module import ll_termios
+        from pypy.rlib import rtermios
         import termios
         def runs_tcgetattr():
             try:
-                termios.tcgetattr(338)
+                rtermios.tcgetattr(338)
             except termios.error, e:
                 return 2
             return 3
@@ -92,13 +94,14 @@
         sys.path.insert(0, '%s')
         from pypy.translator.c.test.test_genc import compile
         from pypy.rpython.module import ll_termios
+        from pypy.rlib import rtermios
         import termios, time
         def runs_tcsetattr():
-            tp = termios.tcgetattr(2)
+            tp = rtermios.tcgetattr(2)
             a, b, c, d, e, f, g = tp
-            termios.tcsetattr(2, termios.TCSANOW, (a, b, c, d, e, f, g))
+            rtermios.tcsetattr(2, rtermios.TCSANOW, (a, b, c, d, e, f, g))
             time.sleep(1)
-            tp = termios.tcgetattr(2)
+            tp = rtermios.tcgetattr(2)
             assert tp[5] == f
 
         fn = compile(runs_tcsetattr, [], backendopt=False)
@@ -132,3 +135,26 @@
         child = self.spawn([str(f)])
         child.expect("OK!")
 
+    def test_tcsetattr_icanon(self):
+        source = py.code.Source("""
+        import sys
+        sys.path.insert(0, '%s')
+        from pypy.rlib import rtermios
+        import termios
+        old_tcsetattr = termios.tcsetattr
+        def check(fd, when, attributes):
+            count = len([i for i in attributes[-1] if isinstance(i, int)])
+            assert count == 2
+        termios.tcsetattr = check
+        try:
+            attr = list(rtermios.tcgetattr(2))
+            attr[3] |= termios.ICANON
+            rtermios.tcsetattr(2, termios.TCSANOW, attr)
+        finally:
+            termios.tcsetattr = old_tcsetattr
+        print 'OK!'
+        """ % os.path.dirname(pypydir))
+        f = udir.join("test_tcsetattricanon.py")
+        f.write(source)
+        child = self.spawn([str(f)])
+        child.expect("OK!")



More information about the Pypy-commit mailing list