From 7bdff1d066e067d49278317e66efd97f7a7717bf Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 19 Mar 2024 17:20:31 +0800 Subject: [PATCH 1/3] gh-104242: Enable test_is_char_device_true in pathlib test on all platform --- Lib/test/test_pathlib/test_pathlib.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 6509c08d227346..561d44623ac8d2 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1103,15 +1103,13 @@ def test_is_socket_true(self): self.assertIs(self.cls(self.base, 'mysock\x00').is_socket(), False) def test_is_char_device_true(self): - # Under Unix, /dev/null should generally be a char device. - P = self.cls('/dev/null') - if not P.exists(): - self.skipTest("/dev/null required") + # os.devnull should generally be a char device. + P = self.cls(os.devnull) self.assertTrue(P.is_char_device()) self.assertFalse(P.is_block_device()) self.assertFalse(P.is_file()) - self.assertIs(self.cls('/dev/null\udfff').is_char_device(), False) - self.assertIs(self.cls('/dev/null\x00').is_char_device(), False) + self.assertIs(self.cls(f'{os.devnull}\udfff').is_char_device(), False) + self.assertIs(self.cls(f'{os.devnull}\x00').is_char_device(), False) def test_is_mount_root(self): if os.name == 'nt': From 555931100dde0d9eadfd418dedba4c9fdcdb6239 Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 19 Mar 2024 17:58:34 +0800 Subject: [PATCH 2/3] Skip the test on Emscripten/WASI --- Lib/test/test_pathlib/test_pathlib.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 561d44623ac8d2..b6117e00d39d4f 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1102,6 +1102,10 @@ def test_is_socket_true(self): self.assertIs(self.cls(self.base, 'mysock\udfff').is_socket(), False) self.assertIs(self.cls(self.base, 'mysock\x00').is_socket(), False) + @unittest.skipIf( + is_emscripten or is_wasi, + "devnull is not implemented on Emscripten/WASI." + ) def test_is_char_device_true(self): # os.devnull should generally be a char device. P = self.cls(os.devnull) From a78eb2cc9d37e9bd6854137d34598730bc696b0c Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 19 Mar 2024 18:26:55 +0800 Subject: [PATCH 3/3] Only skip the test if os.devnull is not exist --- Lib/test/test_pathlib/test_pathlib.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index b6117e00d39d4f..3a6f73c4fe82a4 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -1102,13 +1102,11 @@ def test_is_socket_true(self): self.assertIs(self.cls(self.base, 'mysock\udfff').is_socket(), False) self.assertIs(self.cls(self.base, 'mysock\x00').is_socket(), False) - @unittest.skipIf( - is_emscripten or is_wasi, - "devnull is not implemented on Emscripten/WASI." - ) def test_is_char_device_true(self): # os.devnull should generally be a char device. P = self.cls(os.devnull) + if not P.exists(): + self.skipTest("null device required") self.assertTrue(P.is_char_device()) self.assertFalse(P.is_block_device()) self.assertFalse(P.is_file())