8000 Fix not throwing the same error as CPython in test_pathlib.test_expan… · RustPython/RustPython@2230d6c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2230d6c

Browse files
hbinayouknowone
andauthored
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>
1 parent d800a6b commit 2230d6c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

extra_tests/snippets/stdlib_pwd.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
# windows doesn't support pwd
3+
if sys.platform.startswith("win"):
4+
exit(0)
5+
6+
from testutils import assert_raises
7+
import pwd
8+
9+
with assert_raises(KeyError):
10+
fake_name = 'fake_user'
11+
while pwd.getpwnam(fake_name):
12+
fake_name += '1'

vm/src/stdlib/pwd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod pwd {
5959
if pw_name.contains('\0') {
6060
return Err(exceptions::cstring_error(vm));
6161
}
62-
let user = User::from_name(name.as_str()).map_err(|err| err.into_pyexception(vm))?;
62+
let user = User::from_name(name.as_str()).ok().flatten();
6363
let user = user.ok_or_else(|| {
6464
vm.new_key_error(
6565
vm.ctx

0 commit comments

Comments
 (0)
0