diff options
Diffstat (limited to 'pyfakefs/fake_os.py')
-rw-r--r-- | pyfakefs/fake_os.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pyfakefs/fake_os.py b/pyfakefs/fake_os.py index 912fd31..a28939d 100644 --- a/pyfakefs/fake_os.py +++ b/pyfakefs/fake_os.py @@ -65,6 +65,8 @@ from pyfakefs.helpers import ( PERM_EXE, PERM_DEF, is_root, + get_uid, + get_gid, ) if TYPE_CHECKING: @@ -134,6 +136,11 @@ class FakeOsModule: "removexattr", "setxattr", ] + if sys.platform != "win32": + _dir += [ + "getgid", + "getuid", + ] if use_scandir: _dir += ["scandir"] return _dir @@ -1272,6 +1279,22 @@ class FakeOsModule: return written return 0 + def getuid(self) -> int: + """Returns the user id set in the fake filesystem. + If not changed using ``set_uid``, this is the uid of the real system. + """ + if self.filesystem.is_windows_fs: + raise NameError("name 'getuid' is not defined") + return get_uid() + + def getgid(self) -> int: + """Returns the group id set in the fake filesystem. + If not changed using ``set_gid``, this is the gid of the real system. + """ + if self.filesystem.is_windows_fs: + raise NameError("name 'getgid' is not defined") + return get_gid() + def fake_functions(self, original_functions) -> Set: functions = set() for fn in original_functions: |