Skip to content

Commit c912963

Browse files
committed
Add test
1 parent 97c3d25 commit c912963

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Lib/test/test_tempfile.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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
15991622
class NulledModules:

0 commit comments

Comments
 (0)