Skip to content
Permalink
Browse files

Merge branch 'more-errnos'

  • Loading branch information
alex committed May 27, 2013
2 parents 51e421d + d0300e1 commit 9bcd59ca1f6b9903af465e52df2ffa12a445d4cb
@@ -10,7 +10,7 @@ env:
- TEST_TYPE=translate
# - TEST_TYPE=rubyspec_untranslated
install:
- pip install --use-mirrors requests invoke
- pip install requests invoke
- invoke travis.install_requirements
script: invoke travis.run_tests
after_success: invoke travis.upload_build
@@ -1,4 +1,7 @@
module Errno
class ENOENT < SystemCallError
end

class ECHILD < SystemCallError
end
end

This file was deleted.

@@ -21,7 +21,7 @@ def __init__(self, func, deps=[], needs_rpython=True, needs_rubyspec=False,
self.create_build = create_build

def install_deps(self):
run("pip install --use-mirrors {}".format(" ".join(self.deps)))
run("pip install {}".format(" ".join(self.deps)))

def download_rpython(self):
run("wget https://bitbucket.org/pypy/pypy/get/default.tar.bz2 -O `pwd`/../pypy.tar.bz2 || wget https://bitbucket.org/pypy/pypy/get/default.tar.bz2 -O `pwd`/../pypy.tar.bz2")
@@ -18,7 +18,7 @@ def test_new(self, space, tmpdir):
f = d.join("content")
f.write("hello")
space.execute("Dir.new('%s')" % d)
with self.raises(space, "SystemCallError"):
with self.raises(space, "Errno::ENOENT"):
space.execute("Dir.new('this does not exist')")
with self.raises(space, "SystemCallError"):
space.execute("Dir.new('%s')" % f)
@@ -68,7 +68,7 @@ def test_new_simple(self, space, tmpdir):
space.execute("File.new('%s', 'rw+')" % f)
with self.raises(space, "ArgumentError", "invalid access mode ra"):
space.execute("File.new('%s', 'ra')" % f)
with self.raises(space, "SystemCallError"):
with self.raises(space, "Errno::ENOENT"):
space.execute("File.new('%s', 1)" % tmpdir.join("non-existant"))

w_res = space.execute("return File.new('%s%snonexist', 'w')" % (tmpdir.dirname, os.sep))
@@ -27,21 +27,20 @@ def print_traceback(space, w_exc, top_filepath=None):


_errno_for_oserror_map = {
errno.ENOENT: "ENOENT",
errno.ECHILD: "ECHILD",
}

def error_for_oserror(space, exc, callee=None):
if callee:
try:
name = _errno_for_oserror_map[exc.errno]
except KeyError:
type = space.w_SystemCallError
else:
type = space.find_const(space.find_const(callee, "Errno"), name)

def error_for_oserror(space, exc):
try:
name = _errno_for_oserror_map[exc.errno]
except KeyError:
w_type = space.w_SystemCallError
else:
type = space.w_SystemCallError
w_type = space.find_const(space.find_const(space.w_object, "Errno"), name)
return space.error(
type,
w_type,
os.strerror(exc.errno),
[space.newint(exc.errno)]
)
@@ -39,7 +39,7 @@ def method_waitpid(self, space, pid=-1):
try:
pid, status = os.waitpid(pid, 0)
except OSError as e:
raise error_for_oserror(space, e, self)
raise error_for_oserror(space, e)
status = WEXITSTATUS(status)
w_status = space.send(
space.find_const(self, "Status"),
@@ -49,12 +49,18 @@ def method_chdir(self, space, path=None, block=None):
if path is None:
path = os.environ["HOME"]
current_dir = os.getcwd()
os.chdir(path)
try:
os.chdir(path)
except OSError as e:
raise error_for_oserror(space, e)
if block is not None:
try:
return space.invoke_block(block, [space.newstr_fromstr(path)])
finally:
os.chdir(current_dir)
try:
os.chdir(current_dir)
except OSError as e:
raise error_for_oserror(space, e)
else:
return space.newint(0)

0 comments on commit 9bcd59c

Please sign in to comment.
You can’t perform that action at this time.