8000 io error with filename · RustPython/RustPython@1b07d00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b07d00

Browse files
committed
io error with filename
1 parent c322825 commit 1b07d00

File tree

6 files changed

+16
-26
lines changed

6 files changed

+16
-26
lines changed

Lib/test/test_fileio.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,6 @@ def testMethods(self):
381381
def testOpenDirFD(self):
382382
super().testOpenDirFD()
383383

384-
@unittest.expectedFailureIf(sys.platform != "win32", "TODO: RUSTPYTHON")
385-
def testOpendir(self):
386-
super().testOpendir()
387384

388385
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, test setUp errors on Windows")
389386
class PyAutoFileTests(AutoFileTests, unittest.TestCase):
@@ -617,8 +614,7 @@ class COtherFileTests(OtherFileTests, unittest.TestCase):
617614
FileIO = _io.FileIO
618615
modulename = '_io'
619616

620-
# TODO: RUSTPYTHON
621-
@unittest.expectedFailure
617+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
622618
def testInvalidFd(self):
623619
super().testInvalidFd()
624620

Lib/test/test_pathlib.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,8 +2467,6 @@ def _check_symlink_loop(self, *args, strict=True):
24672467
with self.assertRaises(RuntimeError):
24682468
print(path.resolve(strict))
24692469

2470-
# TODO: RUSTPYTHON
2471-
@unittest.expectedFailure
24722470
def test_open_mode(self):
24732471
old_mask = os.umask(0)
24742472
self.addCleanup(os.umask, old_mask)

Lib/test/test_shutil.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ def test_rmtree_works_on_junctions(self):
318318
self.assertTrue(os.path.exists(dir3))
319319
self.assertTrue(os.path.exists(file1))
320320

321-
# TODO: RUSTPYTHON
322-
@unittest.expectedFailure
323321
def test_rmtree_errors_onerror(self):
324322
# filename is guaranteed not to exist
325323
filename = tempfile.mktemp(dir=self.mkdtemp())
@@ -352,8 +350,6 @@ def onerror(*args):
352350
self.assertIsInstance(errors[1][2][1], NotADirectoryError)
353351
self.assertEqual(errors[1][2][1].filename, filename)
354352

355-
# TODO: RUSTPYTHON
356-
@unittest.expectedFailure
357353
def test_rmtree_errors_onexc(self):
358354
# filename is guaranteed not to exist
359355
filename = tempfile.mktemp(dir=self.mkdtemp())

Lib/test/test_unicode_file_functions.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ def _apply_failure(self, fn, filename,
9494
"with bad filename in the exception: %a" %
9595
(fn.__name__, filename, exc_filename))
9696

97-
# TODO: RUSTPYTHON
98-
@unittest.expectedFailure
9997
def test_failures(self):
10098
# Pass non-existing Unicode filenames all over the place.
10199
for name in self.files:
@@ -113,8 +111,7 @@ def test_failures(self):
113111
else:
114112
_listdir_failure = NotADirectoryError
115113

116-
# TODO: RUSTPYTHON
117-
@unittest.expectedFailure
114+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
118115
def test_open(self):
119116
for name in self.files:
120117
f = open(name, 'wb')
@@ -127,8 +124,6 @@ def test_open(self):
127124
# NFD (a variant of Unicode NFD form). Normalize the filename to NFC, NFKC,
128125
# NFKD in Python is useless, because darwin will normalize it later and so
129126
# open(), os.stat(), etc. don't raise any exception.
130-
# TODO: RUSTPYTHON
131-
@unittest.expectedFailure
132127
@unittest.skipIf(sys.platform == 'darwin', 'irrelevant test on Mac OS X')
133128
@unittest.skipIf(
134129
support.is_emscripten or support.is_wasi,

Lib/test/test_zipapp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ def test_shebang_is_executable(self):
310310
zipapp.create_archive(str(source), str(target), interpreter='python')
311311
self.assertTrue(target.stat().st_mode & stat.S_IEXEC)
312312

313-
# TODO: RUSTPYTHON
314-
@unittest.expectedFailure
315313
@unittest.skipIf(sys.platform == 'win32',
316314
'Windows does not support an executable bit')
317315
def test_no_shebang_is_not_executable(self):

vm/src/stdlib/posix.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
2222
pub mod module {
2323
use crate::{
2424
builtins::{PyDictRef, PyInt, PyListRef, PyStrRef, PyTupleRef, PyTypeRef},
25-
convert::{IntoPyException, ToPyObject, TryFromObject},
25+
convert::{IntoPyException, ToPyException, ToPyObject, TryFromObject},
2626
function::{Either, KwArgs, OptionalArg},
2727
ospath::{IOErrorBuilder, OsPath, OsPathOrFd},
2828
stdlib::os::{
@@ -279,7 +279,7 @@ pub mod module {
279279
)
280280
})?;
281281

282-
let metadata = fs::metadata(path.path.clone());
282+
let metadata = fs::metadata(&path.path);
283283

284284
// if it's only checking for F_OK
285285
if flags == AccessFlags::F_OK {
@@ -1982,20 +1982,27 @@ pub mod module {
19821982

19831983
Errno::clear();
19841984
debug_assert_eq!(errno::errno(), 0);
1985-
let raw = match path {
1985+
let raw = match &path {
19861986
OsPathOrFd::Path(path) => {
1987-
let path = CString::new(path.into_bytes())
1988-
.map_err(|_| vm.new_value_error("embedded null character".to_owned()))?;
1987+
let path = path.clone().into_cstring(vm)?;
19891988
unsafe { libc::pathconf(path.as_ptr(), name) }
19901989
}
1991-
OsPathOrFd::Fd(fd) => unsafe { libc::fpathconf(fd, name) },
1990+
OsPathOrFd::Fd(fd) => unsafe { libc::fpathconf(*fd, name) },
19921991
};
19931992

19941993
if raw == -1 {
19951994
if errno::errno() == 0 {
19961995
Ok(None)
19971996
} else {
1998-
Err(io::Error::from(Errno::last()).into_pyexception(vm))
1997+
let exc = io::Error::from(Errno::last()).to_pyexception(vm);
1998+
if let OsPathOrFd::Path(path) = &path {
1999+
exc.as_object().set_attr(
2000+
"filename",
2001+
vm.ctx.new_str(path.as_path().to_string_lossy()),
2002+
vm,
2003+
)?;
2004+
}
2005+
Err(exc)
19992006
}
20002007
} else {
20012008
Ok(Some(raw))

0 commit comments

Comments
 (0)
0