mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix not throwing the same error as CPython in test_pathlib.test_expanduser (#5578)
* Fix not throwing the same error as CPython when trying to expanduser of a non-existent user Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com> * add pwd test * Skip pwd test on windows --------- Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com> Co-authored-by: Jeong YunWon <jeong@youknowone.org> Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
This commit is contained in:
12
extra_tests/snippets/stdlib_pwd.py
Normal file
12
extra_tests/snippets/stdlib_pwd.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import sys
|
||||
# windows doesn't support pwd
|
||||
if sys.platform.startswith("win"):
|
||||
exit(0)
|
||||
|
||||
from testutils import assert_raises
|
||||
import pwd
|
||||
|
||||
with assert_raises(KeyError):
|
||||
fake_name = 'fake_user'
|
||||
while pwd.getpwnam(fake_name):
|
||||
fake_name += '1'
|
||||
@@ -59,7 +59,7 @@ mod pwd {
|
||||
if pw_name.contains('\0') {
|
||||
return Err(exceptions::cstring_error(vm));
|
||||
}
|
||||
let user = User::from_name(name.as_str()).map_err(|err| err.into_pyexception(vm))?;
|
||||
let user = User::from_name(name.as_str()).ok().flatten();
|
||||
let user = user.ok_or_else(|| {
|
||||
vm.new_key_error(
|
||||
vm.ctx
|
||||
|
||||
Reference in New Issue
Block a user