[pypy-commit] pypy winconsoleio: Implemented more tests for winconsole io.

andrewjlawrence pypy.commits at gmail.com
Sat Sep 28 13:56:06 EDT 2019


Author: andrewjlawrence
Branch: winconsoleio
Changeset: r97670:ff5130e8c568
Date: 2019-09-28 18:54 +0100
http://bitbucket.org/pypy/pypy/changeset/ff5130e8c568/

Log:	Implemented more tests for winconsole io. Add interp tests for
	get_console_type method. Fixed a few things.

diff --git a/pypy/module/_io/interp_win32consoleio.py b/pypy/module/_io/interp_win32consoleio.py
--- a/pypy/module/_io/interp_win32consoleio.py
+++ b/pypy/module/_io/interp_win32consoleio.py
@@ -172,7 +172,7 @@
             buf[n] = self.buf[0]
             for i in range(1, SMALLBUF):
                 self.buf[i-1] = self.buf[i]
-            self.buf[SMALLBUF-1] = 0
+            self.buf[SMALLBUF-1] = rffi.cast(rffi.CCHARP.TO, 0)
             len -= 1
             n += 1
         return n
@@ -193,7 +193,7 @@
         self.blksize = 0
         rwa = False
         console_type = '\0'
-        self.buf = lltype.malloc(rffi.CCHARPP.TO,SMALLBUF,flavor='raw')
+        self.buf = lltype.malloc(rffi.CCHARP.TO,SMALLBUF,flavor='raw')
 
         try:
             if space.isinstance_w(w_nameobj, space.w_int): 
@@ -330,9 +330,9 @@
         win32traits = make_win32_traits(traits)
         if self.fd < 0 and self.handle != rwin32.INVALID_HANDLE_VALUE:
             if self.writable:
-                self.fd = rwin32.open_osfhandle(self.handle, win32traits._O_WRONLY | win32traits._O_BINARY)
+                self.fd = rwin32.open_osfhandle(rffi.cast(rffi.INTP, self.handle), win32traits._O_WRONLY | win32traits._O_BINARY)
             else:
-                self.fd = rwin32.open_osfhandle(self.handle, win32traits._O_RDONLY | win32traits._O_BINARY)
+                self.fd = rwin32.open_osfhandle(rffi.cast(rffi.INTP, self.handle), win32traits._O_RDONLY | win32traits._O_BINARY)
         if self.fd < 0:
             return err_mode(space, "fileno")
         return space.newint(self.fd)
@@ -377,8 +377,7 @@
                 return space.newint(read_len)
                 
             u8n = 0
-            
-            
+               
             if len < 4:
                 if rwin32.WideCharToMultiByte(rwin32.CP_UTF8,
                                            0, wbuf, n, self.buf,
diff --git a/pypy/module/_io/test/test_win32consoleio.py b/pypy/module/_io/test/test_win32consoleio.py
--- a/pypy/module/_io/test/test_win32consoleio.py
+++ b/pypy/module/_io/test/test_win32consoleio.py
@@ -1,4 +1,6 @@
 from rpython.tool.udir import udir
+from pypy.module._io import interp_win32consoleio
+import os
 
 class AppTestWinConsoleIO:
     spaceconfig = dict(usemodules=['_io'])
@@ -6,13 +8,17 @@
     def setup_method(self, meth):
         tmpfile = udir.join('tmpfile')
         tmpfile.write("a\nb\nc", mode='wb')
-        self.tmpfile = tmpfile    
-        self.conout_path = self.space.wrap(str(udir.join('CONOUT$')))
+        self.w_tmpfile = self.space.wrap(str(tmpfile))   
+        self.w_posix = self.space.appexec([], """():
+            import %s as m;
+            return m""" % os.name)        
+        self.w_conout_path = self.space.wrap(str(udir.join('CONOUT$')))
 
     def test_open_fd(self):
         import _io
-
-        w_fd = self.tempfile.fileno()
+        os = self.posix
+        fd = os.open(self.tmpfile, os.O_RDONLY, 0o666)
+        #w_fd = self.tmpfile.fileno()
         # Windows 10: "Cannot open non-console file"
         # Earlier: "Cannot open console output buffer for reading"
         raises(ValueError, _io._WindowsConsoleIO, fd)
@@ -79,8 +85,8 @@
         f.close()
         f.close()
 
-        f = open('C:/con', 'rb', buffering=0)
-        assert f is _io._WindowsConsoleIO
+        f = open('C:\\con', 'rb', buffering=0)
+        assert isinstance(f,_io._WindowsConsoleIO)
         f.close()
 
     def test_conin_conout_names(self):
@@ -90,7 +96,7 @@
         f.close()
 
         f = open('//?/conout$', 'wb', buffering=0)
-        assert type(f) is _io._WindowsConsoleIO
+        assert isinstance(f , _io._WindowsConsoleIO)
         f.close()
         
     def test_conout_path(self):
@@ -102,4 +108,31 @@
     def test_write_empty_data(self):
         import _io
         with _io._WindowsConsoleIO('CONOUT$', 'w') as f:
-            assert f.write(b'') == 0
\ No newline at end of file
+            assert f.write(b'') == 0
+            
+            
+class TestGetConsoleType:
+    def test_conout(self, space):
+        w_file = space.newtext('CONOUT$')
+        consoletype = interp_win32consoleio._pyio_get_console_type(space, w_file)
+        assert consoletype == 'w'
+
+    def test_conin(self, space):
+        w_file = space.newtext('CONIN$')
+        consoletype = interp_win32consoleio._pyio_get_console_type(space, w_file)
+        assert consoletype == 'r'
+        
+    def test_con(self, space):
+        w_file = space.newtext('CON')
+        consoletype = interp_win32consoleio._pyio_get_console_type(space, w_file)
+        assert consoletype == 'x'
+
+    def test_conin2(self, space):
+        w_file = space.newtext('\\\\.\\conin$')
+        consoletype = interp_win32consoleio._pyio_get_console_type(space, w_file)
+        assert consoletype == 'r'        
+        
+    def test_con2(self, space):
+        w_file = space.newtext('\\\\?\\con')
+        consoletype = interp_win32consoleio._pyio_get_console_type(space, w_file)
+        assert consoletype == 'x'
\ No newline at end of file


More information about the pypy-commit mailing list