aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_tempfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r--Lib/test/test_tempfile.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 52b13b98cbc..36151b016ea 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -1594,6 +1594,29 @@ if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile:
mock_close.assert_called()
self.assertEqual(os.listdir(dir), [])
+ @unittest.skipUnless(tempfile._O_TMPFILE_WORKS, 'need os.O_TMPFILE')
+ @unittest.skipUnless(os.path.exists('/proc/self/fd'),
+ 'need /proc/self/fd')
+ def test_link_tmpfile(self):
+ dir = tempfile.mkdtemp()
+ self.addCleanup(os_helper.rmtree, dir)
+ filename = os.path.join(dir, "link")
+
+ with tempfile.TemporaryFile('w', dir=dir) as tmp:
+ # the flag can become False on Linux <= 3.11
+ if not tempfile._O_TMPFILE_WORKS:
+ self.skipTest("O_TMPFILE doesn't work")
+
+ tmp.write("hello")
+ tmp.flush()
+ fd = tmp.fileno()
+
+ os.link(f'/proc/self/fd/{fd}',
+ filename,
+ follow_symlinks=True)
+ with open(filename) as fp:
+ self.assertEqual(fp.read(), "hello")
+
# Helper for test_del_on_shutdown
class NulledModules: