File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1594,6 +1594,29 @@ def test_unexpected_error(self):
15941594 mock_close .assert_called ()
15951595 self .assertEqual (os .listdir (dir ), [])
15961596
1597+ @unittest .skipUnless (tempfile ._O_TMPFILE_WORKS , 'need os.O_TMPFILE' )
1598+ @unittest .skipUnless (os .path .exists ('/proc/self/fd' ),
1599+ 'need /proc/self/fd' )
1600+ def test_link_tmpfile (self ):
1601+ dir = tempfile .mkdtemp ()
1602+ self .addCleanup (os_helper .rmtree , dir )
1603+ filename = os .path .join (dir , "link" )
1604+
1605+ with tempfile .TemporaryFile ('w' , dir = dir ) as tmp :
1606+ # the flag can become False on Linux <= 3.11
1607+ if not tempfile ._O_TMPFILE_WORKS :
1608+ self .skipTest ("O_TMPFILE doesn't work" )
1609+
1610+ tmp .write ("hello" )
1611+ tmp .flush ()
1612+ fd = tmp .fileno ()
1613+
1614+ os .link (f'/proc/self/fd/{ fd } ' ,
1615+ filename ,
1616+ follow_symlinks = True )
1617+ with open (filename ) as fp :
1618+ self .assertEqual (fp .read (), "hello" )
1619+
15971620
15981621# Helper for test_del_on_shutdown
15991622class NulledModules :
You can’t perform that action at this time.
0 commit comments