From 8cfab6ba8a58a9dab19b2df90b608e6012da9533 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Mon, 26 Aug 2024 20:13:16 +0200 Subject: [PATCH] Testing os emulation in pathlib --- pyfakefs/tests/fake_pathlib_test.py | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/pyfakefs/tests/fake_pathlib_test.py b/pyfakefs/tests/fake_pathlib_test.py index afd3efe0..d606eace 100644 --- a/pyfakefs/tests/fake_pathlib_test.py +++ b/pyfakefs/tests/fake_pathlib_test.py @@ -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):