2
from pypy.tool.udir import udir
3
from pypy.tool.pytest.modcheck import skipimporterror
4
skipimporterror("ctypes")
6
from pypy.rpython.lltypesystem.module.ll_os import Implementation as impl
10
filename = str(udir.join('test_access.txt'))
11
rsfilename = impl.to_rstr(filename)
13
fd = file(filename, 'w')
16
for mode in os.R_OK, os.W_OK, os.X_OK, os.R_OK | os.W_OK | os.X_OK:
17
assert os.access(filename, mode) == impl.ll_os_access(rsfilename, mode)
20
def test_open_read_write_close():
21
filename = str(udir.join('test_open_read_write_close.txt'))
22
rsfilename = impl.to_rstr(filename)
24
fd = impl.ll_os_open(rsfilename, os.O_WRONLY | os.O_CREAT, 0777)
25
count = impl.ll_os_write(fd, impl.to_rstr("hello world\n"))
26
assert count == len("hello world\n")
29
fd = impl.ll_os_open(rsfilename, os.O_RDONLY, 0777)
30
data = impl.ll_os_read(fd, 500)
31
assert impl.from_rstr(data) == "hello world\n"
37
data = impl.ll_os_getcwd()
38
assert impl.from_rstr(data) == os.getcwd()
41
data = impl.ll_os_strerror(2)
42
assert impl.from_rstr(data) == os.strerror(2)
45
filename = str(udir.join('test_system.txt'))
46
arg = impl.to_rstr('python -c "print 1+1" > %s' % filename)
47
data = impl.ll_os_system(arg)
49
assert file(filename).read().strip() == '2'
52
def test_putenv_unsetenv():
53
filename = str(udir.join('test_putenv.txt'))
54
arg = impl.to_rstr('abcdefgh=12345678')
55
impl.ll_os_putenv(arg)
56
cmd = '''python -c "import os; print os.environ['abcdefgh']" > %s''' % filename
59
result = f.read().strip()
60
assert result == '12345678'
63
posix = __import__(os.name)
64
if hasattr(posix, "unsetenv"):
65
impl.ll_os_unsetenv(impl.to_rstr("abcdefgh"))
66
cmd = '''python -c "import os; print repr(os.getenv('abcdefgh'))" > %s''' % filename
69
result = f.read().strip()
70
assert result == 'None'
76
from pypy.tool.udir import udir
77
from pypy.rpython.lltypesystem.module.ll_os import Implementation as impl
82
if not impl.ll_os_environ(count):
85
channel.send(count == len(os.environ.keys()))
91
gw = py.execnet.PopenGateway()
92
chan = gw.remote_exec(py.code.Source(test_src))
97
def test_opendir_readdir():
99
rsdirname = impl.to_rstr(dirname)
101
DIR = impl.ll_os_opendir(rsdirname)
104
nextentry = impl.ll_os_readdir(DIR)
105
if not nextentry: # null pointer check
107
result.append(impl.from_rstr(nextentry))
109
impl.ll_os_closedir(DIR)
111
assert '..' in result
115
compared_with = os.listdir(dirname)
117
assert result == compared_with
119
if hasattr(os, 'execv'):
120
from pypy.rpython.extregistry import lookup
121
os_execv = lookup(os.execv).lltypeimpl
124
filename = str(udir.join('test_execv_ctypes.txt'))
126
progname = str(sys.executable)
130
l.append('open("%s","w").write("1")' % filename)
133
os_execv(progname, l)
136
assert open(filename).read() == "1"
139
from pypy.rpython.extregistry import lookup
140
os_dup = lookup(os.dup).lltypeimpl
141
testf = udir.join('test.txt')
148
fi = os.open(path,os.O_RDONLY,0755)
150
assert os.fstat(g) == os.fstat(fi)