mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #3398 from deantvv/os-error-str-2
os: implement os-error-str according to CPython
This commit is contained in:
2
Lib/test/test_posix.py
vendored
2
Lib/test/test_posix.py
vendored
@@ -1424,8 +1424,6 @@ class PosixTester(unittest.TestCase):
|
||||
# http://lists.freebsd.org/pipermail/freebsd-amd64/2012-January/014332.html
|
||||
raise unittest.SkipTest("OSError raised!")
|
||||
|
||||
# TODO: RUSTPYTHON: AssertionError: "'doesnotexistfilename' -> 'noodly2'" not found in "(2, 'No such file or directory (os error 2)')"
|
||||
@unittest.expectedFailure
|
||||
def test_path_error2(self):
|
||||
"""
|
||||
Test functions that call path_error2(), providing two filenames in their exceptions.
|
||||
|
||||
2
Lib/test/test_tarfile.py
vendored
2
Lib/test/test_tarfile.py
vendored
@@ -342,8 +342,6 @@ class CommonReadTest(ReadTest):
|
||||
finally:
|
||||
tar.close()
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_non_existent_tarfile(self):
|
||||
# Test for issue11513: prevent non-existent gzipped tarfiles raising
|
||||
# multiple exceptions.
|
||||
|
||||
@@ -862,13 +862,28 @@ fn key_error_str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyStrRef {
|
||||
|
||||
fn os_error_str(exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyResult<PyStrRef> {
|
||||
let args = exc.args();
|
||||
let obj = exc.as_object().to_owned();
|
||||
|
||||
if args.as_slice().len() == 2 {
|
||||
// SAFETY: len() == 2 is checked so get_arg 1 or 2 won't panic
|
||||
let s = format!(
|
||||
"[Errno {}] {}",
|
||||
exc.get_arg(0).unwrap().str(vm)?,
|
||||
exc.get_arg(1).unwrap().str(vm)?
|
||||
);
|
||||
let errno = exc.get_arg(0).unwrap().str(vm)?;
|
||||
let msg = exc.get_arg(1).unwrap().str(vm)?;
|
||||
|
||||
let s = match obj.clone().get_attr("filename", vm) {
|
||||
Ok(filename) => match obj.get_attr("filename2", vm) {
|
||||
Ok(filename2) => format!(
|
||||
"[Errno {}] {}: '{}' -> '{}'",
|
||||
errno,
|
||||
msg,
|
||||
filename.str(vm)?,
|
||||
filename2.str(vm)?
|
||||
),
|
||||
Err(_) => format!("[Errno {}] {}: '{}'", errno, msg, filename.str(vm)?),
|
||||
},
|
||||
Err(_) => {
|
||||
format!("[Errno {}] {}", errno, msg)
|
||||
}
|
||||
};
|
||||
Ok(vm.ctx.new_str(s))
|
||||
} else {
|
||||
Ok(exc.str(vm))
|
||||
|
||||
Reference in New Issue
Block a user