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:
authored and GitHub committed 2025-04-05 15:33:33 +09:00
1 parent d800a6bb98
commit 2230d6c751
2 files changed
+13 -1

No files matched your search

+12
View 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'
+1 -1
View File
@@ -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