Skip to content

Commit

Permalink
Testing os emulation in pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Aug 26, 2024
1 parent 27934c3 commit 8cfab6b
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions pyfakefs/tests/fake_pathlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,83 @@ def test_posix_pure_path_parsing(self):
pathlib.PurePosixPath(path).stem,
)

def test_windows_pure_path_str(self):
"""Verify faked pure Windows paths are formatted using windows separators"""
path = r"C:/Windows/cmd.exe"
self.assertEqual(
str(fake_pathlib.FakePathlibModule.PureWindowsPath(path)),
str(pathlib.PureWindowsPath(path)),
)

def test_posix_pure_path_str(self):
"""Verify faked pure POSIX paths are formatted using POSIX separator."""

path = r"/bin/bash"
self.assertEqual(
str(fake_pathlib.FakePathlibModule.PurePosixPath(path)),
str(pathlib.PurePosixPath(path)),
)

def test_posix_pure_path_is_absolute(self):
"""Verify faked pure POSIX paths are formatted using POSIX separator."""

path = r"/bin/bash"
self.assertEqual(
fake_pathlib.FakePathlibModule.PurePosixPath(path).is_absolute(),
pathlib.PurePosixPath(path).is_absolute(),
)
path = r"bin/bash"
self.assertEqual(
fake_pathlib.FakePathlibModule.PurePosixPath(path).is_absolute(),
pathlib.PurePosixPath(path).is_absolute(),
)
path = r"../bin/bash"
self.assertEqual(
fake_pathlib.FakePathlibModule.PurePosixPath(path).is_absolute(),
pathlib.PurePosixPath(path).is_absolute(),
)

def test_windows_pure_path_is_absolute(self):
"""Verify faked pure POSIX paths are formatted using POSIX separator."""

path = r"C:/Windows/cmd.exe"
self.assertEqual(
fake_pathlib.FakePathlibModule.PureWindowsPath(path).is_absolute(),
pathlib.PureWindowsPath(path).is_absolute(),
)
path = r"./cmd.exe"
self.assertEqual(
fake_pathlib.FakePathlibModule.PureWindowsPath(path).is_absolute(),
pathlib.PureWindowsPath(path).is_absolute(),
)
path = r"../cmd.exe"
self.assertEqual(
fake_pathlib.FakePathlibModule.PureWindowsPath(path).is_absolute(),
pathlib.PureWindowsPath(path).is_absolute(),
)


class PureWindowsPath(FakePathlibModulePurePathTest, fake_filesystem_unittest.TestCase):
def setUp(self) -> None:
self.setUpPyfakefs()
self.fs.os = OSType.WINDOWS


class FakePathlibModulePurePathTestMacos(
FakePathlibModulePurePathTest, fake_filesystem_unittest.TestCase
):
def setUp(self) -> None:
self.setUpPyfakefs()
self.fs.os = OSType.MACOS


class FakePathlibModulePurePathTestLinux(
FakePathlibModulePurePathTest, fake_filesystem_unittest.TestCase
):
def setUp(self) -> None:
self.setUpPyfakefs()
self.fs.os = OSType.LINUX


class SkipPathlibTest(fake_filesystem_unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 8cfab6b

Please sign in to comment.