Add a test case for this issue: http://bugs.python.org/issue5334
authorZac Medico <zmedico@gentoo.org>
Fri, 25 Sep 2009 05:58:16 +0000 (05:58 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 25 Sep 2009 05:58:16 +0000 (05:58 -0000)
svn path=/main/trunk/; revision=14423

pym/portage/tests/ebuild/test_array_fromfile_eof.py [new file with mode: 0644]
pym/portage/tests/ebuild/test_pty_eof.py

diff --git a/pym/portage/tests/ebuild/test_array_fromfile_eof.py b/pym/portage/tests/ebuild/test_array_fromfile_eof.py
new file mode 100644 (file)
index 0000000..8eacb40
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright 2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+import array
+import pty
+import tempfile
+
+from portage import _unicode_decode
+from portage import _unicode_encode
+from portage.tests import TestCase
+
+class ArrayFromfileEofTestCase(TestCase):
+
+       def testArrayFromfileEof(self):
+               # This tests if the following python issue is fixed
+               # in the currently running version of python:
+               #   http://bugs.python.org/issue5334
+
+               input_data = "an arbitrary string"
+               f = tempfile.TemporaryFile()
+               f.write(_unicode_encode(input_data,
+                       encoding='utf_8', errors='strict'))
+
+               f.seek(0)
+               data = []
+               eof = False
+               while not eof:
+                       a = array.array('B')
+                       try:
+                               a.fromfile(f, len(input_data) + 1)
+                       except EOFError:
+                               # python-3.0 lost data here
+                               eof = True
+
+                       if not a:
+                               eof = True
+                       else:
+                               data.append(_unicode_decode(a.tostring(),
+                                       encoding='utf_8', errors='strict'))
+
+               f.close()
+
+               self.assertEqual(input_data, ''.join(data))
index 8723372b11f85b4423a082a449ba36a7bcee63b6..88334bcb92387739f288242e290645709abc75b0 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1998-2007 Gentoo Foundation
+# Copyright 2009 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 # $Id$