Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6747,8 +6747,6 @@ def test_ambiguous_option(self):
"ambiguous option: --foob=1 could match --foobaz, --fooble$",
self.parser.parse_args, ['--foob=1', '--foogle', '2'])

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_os_error(self):
self.parser.add_argument('file')
self.assertRaisesRegex(argparse.ArgumentError,
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_py_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ def test_bad_syntax_with_quiet(self):
self.assertEqual(stdout, b'')
self.assertEqual(stderr, b'')

@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
def test_file_not_exists(self):
should_not_exists = os.path.join(os.path.dirname(__file__), 'should_not_exists.py')
rc, stdout, stderr = self.pycompilecmd_failure(self.source_path, should_not_exists)
Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1878,8 +1878,6 @@ def _get_chdir_exception(self):
self._nonexistent_dir)
return desired_exception

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exception_cwd(self):
"""Test error in the child raised in the parent for a bad cwd."""
desired_exception = self._get_chdir_exception()
Expand All @@ -1895,8 +1893,6 @@ def test_exception_cwd(self):
else:
self.fail("Expected OSError: %s" % desired_exception)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exception_bad_executable(self):
"""Test error in the child raised in the parent for a bad executable."""
desired_exception = self._get_chdir_exception()
Expand All @@ -1912,8 +1908,6 @@ def test_exception_bad_executable(self):
else:
self.fail("Expected OSError: %s" % desired_exception)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_exception_bad_args_0(self):
"""Test error in the child raised in the parent for a bad args[0]."""
desired_exception = self._get_chdir_exception()
Expand Down
33 changes: 32 additions & 1 deletion crates/vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,41 @@ pub use _io::{OpenArgs, io_open as open};
impl ToPyException for std::io::Error {
fn to_pyexception(&self, vm: &VirtualMachine) -> PyBaseExceptionRef {
let errno = self.posix_errno();
#[cfg(windows)]
let msg = 'msg: {
// On Windows, use C runtime's strerror for POSIX errno values
// For Windows-specific error codes, fall back to FormatMessage

// UCRT's strerror returns "Unknown error" for invalid errno values
// Windows UCRT defines errno values 1-42 plus some more up to ~127
const MAX_POSIX_ERRNO: i32 = 127;
if errno > 0 && errno <= MAX_POSIX_ERRNO {
let ptr = unsafe { libc::strerror(errno) };
if !ptr.is_null() {
let s = unsafe { std::ffi::CStr::from_ptr(ptr) }.to_string_lossy();
if !s.starts_with("Unknown error") {
break 'msg s.into_owned();
}
}
}
self.to_string()
};
#[cfg(unix)]
let msg = {
let ptr = unsafe { libc::strerror(errno) };
if !ptr.is_null() {
unsafe { std::ffi::CStr::from_ptr(ptr) }
.to_string_lossy()
.into_owned()
} else {
self.to_string()
}
};
#[cfg(not(any(windows, unix)))]
let msg = self.to_string();

#[allow(clippy::let_and_return)]
let exc = vm.new_errno_error(errno, msg);

#[cfg(windows)]
{
use crate::object::AsObject;
Expand Down
Loading