@@ -1786,13 +1786,31 @@ def test_lstat_nosymlink(self):
17861786 st = p .stat ()
17871787 self .assertEqual (st , p .lstat ())
17881788
1789- def test_is_junction (self ):
1789+ def test_is_junction_false (self ):
1790+ P = self .cls (self .base )
1791+ self .assertFalse ((P / 'fileA' ).is_junction ())
1792+ self .assertFalse ((P / 'dirA' ).is_junction ())
1793+ self .assertFalse ((P / 'non-existing' ).is_junction ())
1794+ self .assertFalse ((P / 'fileA' / 'bah' ).is_junction ())
1795+ self .assertFalse ((P / 'fileA\udfff ' ).is_junction ())
1796+ self .assertFalse ((P / 'fileA\x00 ' ).is_junction ())
1797+
1798+ def test_is_junction_true (self ):
17901799 P = self .cls (self .base )
17911800
17921801 with mock .patch .object (P .parser , 'isjunction' ):
17931802 self .assertEqual (P .is_junction (), P .parser .isjunction .return_value )
17941803 P .parser .isjunction .assert_called_once_with (P )
17951804
1805+ def test_is_fifo_false (self ):
1806+ P = self .cls (self .base )
1807+ self .assertFalse ((P / 'fileA' ).is_fifo ())
1808+ self .assertFalse ((P / 'dirA' ).is_fifo ())
1809+ self .assertFalse ((P / 'non-existing' ).is_fifo ())
1810+ self .assertFalse ((P / 'fileA' / 'bah' ).is_fifo ())
1811+ self .assertIs ((P / 'fileA\udfff ' ).is_fifo (), False )
1812+ self .assertIs ((P / 'fileA\x00 ' ).is_fifo (), False )
1813+
17961814 @unittest .skipUnless (hasattr (os , "mkfifo" ), "os.mkfifo() required" )
17971815 @unittest .skipIf (sys .platform == "vxworks" ,
17981816 "fifo requires special path on VxWorks" )
@@ -1808,6 +1826,15 @@ def test_is_fifo_true(self):
18081826 self .assertIs (self .cls (self .base , 'myfifo\udfff ' ).is_fifo (), False )
18091827 self .assertIs (self .cls (self .base , 'myfifo\x00 ' ).is_fifo (), False )
18101828
1829+ def test_is_socket_false (self ):
1830+ P = self .cls (self .base )
1831+ self .assertFalse ((P / 'fileA' ).is_socket ())
1832+ self .assertFalse ((P / 'dirA' ).is_socket ())
1833+ self .assertFalse ((P / 'non-existing' ).is_socket ())
1834+ self .assertFalse ((P / 'fileA' / 'bah' ).is_socket ())
1835+ self .assertIs ((P / 'fileA\udfff ' ).is_socket (), False )
1836+ self .assertIs ((P / 'fileA\x00 ' ).is_socket (), False )
1837+
18111838 @unittest .skipUnless (hasattr (socket , "AF_UNIX" ), "Unix sockets required" )
18121839 @unittest .skipIf (
18131840 is_emscripten , "Unix sockets are not implemented on Emscripten."
@@ -1831,6 +1858,24 @@ def test_is_socket_true(self):
18311858 self .assertIs (self .cls (self .base , 'mysock\udfff ' ).is_socket (), False )
18321859 self .assertIs (self .cls (self .base , 'mysock\x00 ' ).is_socket (), False )
18331860
1861+ def test_is_block_device_false (self ):
1862+ P = self .cls (self .base )
1863+ self .assertFalse ((P / 'fileA' ).is_block_device ())
1864+ self .assertFalse ((P / 'dirA' ).is_block_device ())
1865+ self .assertFalse ((P / 'non-existing' ).is_block_device ())
1866+ self .assertFalse ((P / 'fileA' / 'bah' ).is_block_device ())
1867+ self .assertIs ((P / 'fileA\udfff ' ).is_block_device (), False )
1868+ self .assertIs ((P / 'fileA\x00 ' ).is_block_device (), False )
1869+
1870+ def test_is_char_device_false (self ):
1871+ P = self .cls (self .base )
1872+ self .assertFalse ((P / 'fileA' ).is_char_device ())
1873+ self .assertFalse ((P / 'dirA' ).is_char_device ())
1874+ self .assertFalse ((P / 'non-existing' ).is_char_device ())
1875+ self .assertFalse ((P / 'fileA' / 'bah' ).is_char_device ())
1876+ self .assertIs ((P / 'fileA\udfff ' ).is_char_device (), False )
1877+ self .assertIs ((P / 'fileA\x00 ' ).is_char_device (), False )
1878+
18341879 def test_is_char_device_true (self ):
18351880 # os.devnull should generally be a char device.
18361881 P = self .cls (os .devnull )
@@ -1842,14 +1887,42 @@ def test_is_char_device_true(self):
18421887 self .assertIs (self .cls (f'{ os .devnull } \udfff ' ).is_char_device (), False )
18431888 self .assertIs (self .cls (f'{ os .devnull } \x00 ' ).is_char_device (), False )
18441889
1845- def test_is_mount_root (self ):
1890+ def test_is_mount (self ):
1891+ P = self .cls (self .base )
1892+ self .assertFalse ((P / 'fileA' ).is_mount ())
1893+ self .assertFalse ((P / 'dirA' ).is_mount ())
1894+ self .assertFalse ((P / 'non-existing' ).is_mount ())
1895+ self .assertFalse ((P / 'fileA' / 'bah' ).is_mount ())
1896+ if self .can_symlink :
1897+ self .assertFalse ((P / 'linkA' ).is_mount ())
18461898 if os .name == 'nt' :
18471899 R = self .cls ('c:\\ ' )
18481900 else :
18491901 R = self .cls ('/' )
18501902 self .assertTrue (R .is_mount ())
18511903 self .assertFalse ((R / '\udfff ' ).is_mount ())
18521904
1905+ def test_samefile (self ):
1906+ parser = self .parser
1907+ fileA_path = parser .join (self .base , 'fileA' )
1908+ fileB_path = parser .join (self .base , 'dirB' , 'fileB' )
1909+ p = self .cls (fileA_path )
1910+ pp = self .cls (fileA_path )
1911+ q = self .cls (fileB_path )
1912+ self .assertTrue (p .samefile (fileA_path ))
1913+ self .assertTrue (p .samefile (pp ))
1914+ self .assertFalse (p .samefile (fileB_path ))
1915+ self .assertFalse (p .samefile (q ))
1916+ # Test the non-existent file case
1917+ non_existent = parser .join (self .base , 'foo' )
1918+ r = self .cls (non_existent )
1919+ self .assertRaises (FileNotFoundError , p .samefile , r )
1920+ self .assertRaises (FileNotFoundError , p .samefile , non_existent )
1921+ self .assertRaises (FileNotFoundError , r .samefile , p )
1922+ self .assertRaises (FileNotFoundError , r .samefile , non_existent )
1923+ self .assertRaises (FileNotFoundError , r .samefile , r )
1924+ self .assertRaises (FileNotFoundError , r .samefile , non_existent )
1925+
18531926 def test_passing_kwargs_errors (self ):
18541927 with self .assertRaises (TypeError ):
18551928 self .cls (foo = "bar" )
0 commit comments