mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-17 01:51:39 +09:00
Merge pull request #787 from palaviv/os-fd
Add os.{read,write,remove,unlink}
This commit is contained in:
@@ -2,7 +2,36 @@ import os
|
||||
|
||||
from testutils import assert_raises
|
||||
|
||||
assert os.open('README.md', 0) > 0
|
||||
fd = os.open('README.md', 0)
|
||||
assert fd > 0
|
||||
|
||||
os.close(fd)
|
||||
assert_raises(OSError, lambda: os.read(fd, 10))
|
||||
|
||||
FNAME = "test_file_that_no_one_will_have_on_disk"
|
||||
CONTENT = b"testing"
|
||||
CONTENT2 = b"rustpython"
|
||||
CONTENT3 = b"BOYA"
|
||||
|
||||
class TestWithFile():
|
||||
def __enter__(self):
|
||||
open(FNAME, "wb")
|
||||
return FNAME
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
os.remove(FNAME)
|
||||
|
||||
|
||||
with TestWithFile() as fname:
|
||||
fd = os.open(fname, 1)
|
||||
assert os.write(fd, CONTENT2) == len(CONTENT2)
|
||||
assert os.write(fd, CONTENT3) == len(CONTENT3)
|
||||
os.close(fd)
|
||||
|
||||
fd = os.open(fname, 0)
|
||||
assert os.read(fd, len(CONTENT2)) == CONTENT2
|
||||
assert os.read(fd, len(CONTENT3)) == CONTENT3
|
||||
os.close(fd)
|
||||
|
||||
|
||||
assert_raises(FileNotFoundError, lambda: os.open('DOES_NOT_EXIST', 0))
|
||||
|
||||
Reference in New Issue
Block a user