[Python-checkins] r43568 - python/trunk/Lib/test/test_pty.py

neal.norwitz python-checkins at python.org
Mon Apr 3 07:28:31 CEST 2006


Author: neal.norwitz
Date: Mon Apr  3 07:28:31 2006
New Revision: 43568

Modified:
   python/trunk/Lib/test/test_pty.py
Log:
Fix test_pty on OSF/1 (Tru64).  The problem is that the newline gets
converted to CR CR NL.  There may be a way to fix this with tcsetattr,
but I couldn't find it.  There was a similar problem on IRIX.

Just normalize the output and compare that.

Will backport.


Modified: python/trunk/Lib/test/test_pty.py
==============================================================================
--- python/trunk/Lib/test/test_pty.py	(original)
+++ python/trunk/Lib/test/test_pty.py	Mon Apr  3 07:28:31 2006
@@ -18,6 +18,27 @@
     def debug(msg):
         pass
 
+def normalize_output(data):
+    # Some operating systems do conversions on newline.  We could possibly
+    # fix that by doing the appropriate termios.tcsetattr()s.  I couldn't
+    # figure out the right combo on Tru64 and I don't have an IRIX box.
+    # So just normalize the output and doc the problem O/Ses by allowing 
+    # certain combinations for some platforms, but avoid allowing other
+    # differences (like extra whitespace, trailing garbage, etc.)
+
+    # This is about the best we can do without getting some feedback
+    # from someone more knowledgable.
+
+    # OSF/1 (Tru64) apparently turns \n into \r\r\n.
+    if data.endswith('\r\r\n'):
+        return data[:-3] + '\n'
+
+    # IRIX apparently turns \n into \r\n.
+    if data.endswith('\r\n'):
+        return data[:-2] + '\n'
+
+    return data
+
 # Marginal testing of pty suite. Cannot do extensive 'do or fail' testing
 # because pty code is not too portable.
 
@@ -36,19 +57,16 @@
     if not os.isatty(slave_fd) and sys.platform not in fickle_isatty:
         raise TestFailed, "slave_fd is not a tty"
 
-    # IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
-    # differences (like extra whitespace, trailing garbage, etc.)
-
     debug("Writing to slave_fd")
     os.write(slave_fd, TEST_STRING_1)
     s1 = os.read(master_fd, 1024)
-    sys.stdout.write(s1.replace("\r\n", "\n"))
+    sys.stdout.write(normalize_output(s1))
 
     debug("Writing chunked output")
     os.write(slave_fd, TEST_STRING_2[:5])
     os.write(slave_fd, TEST_STRING_2[5:])
     s2 = os.read(master_fd, 1024)
-    sys.stdout.write(s2.replace("\r\n", "\n"))
+    sys.stdout.write(normalize_output(s2))
 
     os.close(slave_fd)
     os.close(master_fd)


More information about the Python-checkins mailing list