@@ -1786,13 +1786,31 @@ def test_lstat_nosymlink(self):
1786
1786
st = p .stat ()
1787
1787
self .assertEqual (st , p .lstat ())
1788
1788
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 ):
1790
1799
P = self .cls (self .base )
1791
1800
1792
1801
with mock .patch .object (P .parser , 'isjunction' ):
1793
1802
self .assertEqual (P .is_junction (), P .parser .isjunction .return_value )
1794
1803
P .parser .isjunction .assert_called_once_with (P )
1795
1804
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
+
1796
1814
@unittest .skipUnless (hasattr (os , "mkfifo" ), "os.mkfifo() required" )
1797
1815
@unittest .skipIf (sys .platform == "vxworks" ,
1798
1816
"fifo requires special path on VxWorks" )
@@ -1808,6 +1826,15 @@ def test_is_fifo_true(self):
1808
1826
self .assertIs (self .cls (self .base , 'myfifo\udfff ' ).is_fifo (), False )
1809
1827
self .assertIs (self .cls (self .base , 'myfifo\x00 ' ).is_fifo (), False )
1810
1828
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
+
1811
1838
@unittest .skipUnless (hasattr (socket , "AF_UNIX" ), "Unix sockets required" )
1812
1839
@unittest .skipIf (
1813
1840
is_emscripten , "Unix sockets are not implemented on Emscripten."
@@ -1831,6 +1858,24 @@ def test_is_socket_true(self):
1831
1858
self .assertIs (self .cls (self .base , 'mysock\udfff ' ).is_socket (), False )
1832
1859
self .assertIs (self .cls (self .base , 'mysock\x00 ' ).is_socket (), False )
1833
1860
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
+
1834
1879
def test_is_char_device_true (self ):
1835
1880
# os.devnull should generally be a char device.
1836
1881
P = self .cls (os .devnull )
@@ -1842,14 +1887,42 @@ def test_is_char_device_true(self):
1842
1887
self .assertIs (self .cls (f'{ os .devnull } \udfff ' ).is_char_device (), False )
1843
1888
self .assertIs (self .cls (f'{ os .devnull } \x00 ' ).is_char_device (), False )
1844
1889
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 ())
1846
1898
if os .name == 'nt' :
1847
1899
R = self .cls ('c:\\ ' )
1848
1900
else :
1849
1901
R = self .cls ('/' )
1850
1902
self .assertTrue (R .is_mount ())
1851
1903
self .assertFalse ((R / '\udfff ' ).is_mount ())
1852
1904
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
+
1853
1926
def test_passing_kwargs_errors (self ):
1854
1927
with self .assertRaises (TypeError ):
1855
1928
self .cls (foo = "bar" )
0 commit comments