From db8f6460971a7f03c166ddbcd01dd841128ad251 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sat, 7 Sep 2024 16:19:52 +0200 Subject: [PATCH] Add some debug output --- pyfakefs/fake_pathlib.py | 16 +++++++++++++--- pyfakefs/tests/fake_filesystem_unittest_test.py | 4 +--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pyfakefs/fake_pathlib.py b/pyfakefs/fake_pathlib.py index 3c4a931e..67434077 100644 --- a/pyfakefs/fake_pathlib.py +++ b/pyfakefs/fake_pathlib.py @@ -605,7 +605,9 @@ def __new__(cls, *args, **kwargs): else FakePathlibModule.PosixPath ) if sys.version_info < (3, 12): - return cls._from_parts(args) # pytype: disable=attribute-error + ret = cls._from_parts(args) # pytype: disable=attribute-error + print(f"__new__({cls}, {args}, {kwargs}) -> {ret}") + return ret else: return object.__new__(cls) @@ -793,15 +795,23 @@ def home(cls): returned by os.path.expanduser('~')). """ home = os.path.expanduser("~") + print(f"{home=}") if cls.filesystem.is_windows_fs != (os.name == "nt"): username = os.path.split(home)[1] + print(f"{username=}") if cls.filesystem.is_windows_fs: - home = os.path.join("C:", "Users", username) + home = os.path.join("C:" + os.sep, "Users", username) else: home = os.path.join("home", username) + print(f"new {home=}") if not cls.filesystem.exists(home): + print(f"create {home}") cls.filesystem.create_dir(home) - return cls(home.replace(os.sep, cls.filesystem.path_separator)) + home = home.replace(os.sep, cls.filesystem.path_separator) + ret = cls(home) + print(f"before return: {home=}, {cls=}, {cls.__mro__=}, {ret=}") + print(f"{os.path.exists(home)=}, {ret.exists()=}") + return ret def samefile(self, other_path): """Return whether other_path is the same or not as this file diff --git a/pyfakefs/tests/fake_filesystem_unittest_test.py b/pyfakefs/tests/fake_filesystem_unittest_test.py index 4b3de171..964ae3b4 100644 --- a/pyfakefs/tests/fake_filesystem_unittest_test.py +++ b/pyfakefs/tests/fake_filesystem_unittest_test.py @@ -824,9 +824,7 @@ def setUp(self): @mock.patch.dict(os.environ, {"HOME": "/home/john"}) def test_real_file_with_home(self): """Regression test for #558""" - self.fs.is_windows_fs = os.name != "nt" - if self.fs.is_windows_fs: - self.fs.is_macos = False + self.fs.os = OSType.LINUX if sys.platform == "win32" else OSType.WINDOWS self.fs.add_real_file(__file__) with open(__file__, encoding="utf8") as f: self.assertTrue(f.read())