Skip to content

Commit

Permalink
Add some debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Sep 7, 2024
1 parent 1b76afe commit db8f646
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 13 additions & 3 deletions pyfakefs/fake_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit db8f646

Please sign in to comment.