summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2008-09-15 23:02:56 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2008-09-15 23:02:56 (GMT)
commit9cadb1b6e0d10aaeb8f9e69e51f672a53de6b164 (patch)
treee39eac97c8d501a20d6f336ccddcc169f585271d /Lib/test/test_os.py
parent4e80cdd739772406bba00a31fdd98539cdcca651 (diff)
downloadcpython-9cadb1b6e0d10aaeb8f9e69e51f672a53de6b164.zip
cpython-9cadb1b6e0d10aaeb8f9e69e51f672a53de6b164.tar.gz
cpython-9cadb1b6e0d10aaeb8f9e69e51f672a53de6b164.tar.bz2
Issue #3782: os.write() must not accept unicode strings
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 50b5831..f58aaf7 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -41,7 +41,7 @@ class FileTests(unittest.TestCase):
os.close(second)
# close a fd that is open, and one that isn't
os.closerange(first, first + 2)
- self.assertRaises(OSError, os.write, first, "a")
+ self.assertRaises(OSError, os.write, first, b"a")
def test_rename(self):
path = support.TESTFN
@@ -50,6 +50,28 @@ class FileTests(unittest.TestCase):
new = sys.getrefcount(path)
self.assertEqual(old, new)
+ def test_read(self):
+ with open(support.TESTFN, "w+b") as fobj:
+ fobj.write(b"spam")
+ fobj.flush()
+ fd = fobj.fileno()
+ os.lseek(fd, 0, 0)
+ s = os.read(fd, 4)
+ self.assertEqual(type(s), bytes)
+ self.assertEqual(s, b"spam")
+
+ def test_write(self):
+ # os.write() accepts bytes- and buffer-like objects but not strings
+ fd = os.open(support.TESTFN, os.O_CREAT | os.O_WRONLY)
+ self.assertRaises(TypeError, os.write, fd, "beans")
+ os.write(fd, b"bacon\n")
+ os.write(fd, bytearray(b"eggs\n"))
+ os.write(fd, memoryview(b"spam\n"))
+ os.close(fd)
+ with open(support.TESTFN, "rb") as fobj:
+ self.assertEqual(fobj.read(), b"bacon\neggs\nspam\n")
+
+
class TemporaryFileTests(unittest.TestCase):
def setUp(self):
self.files = []