summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-05-01 20:55:35 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2009-05-01 20:55:35 +0000
commit2a205dfbc844b289d8405c7dd91bbebb1964a815 (patch)
tree3a8d613e7a5dfe2b7dee040cbaa9fe42ed89b968 /Lib/test
parent67b8c576de8bbd49c30162aa50fbea0827476df1 (diff)
downloadcpython-2a205dfbc844b289d8405c7dd91bbebb1964a815.tar.gz
Issue #3002: `shutil.copyfile()` and `shutil.copytree()` now raise an
error when a named pipe is encountered, rather than blocking infinitely.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_shutil.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 169290da7b..6226f9b61c 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -9,6 +9,7 @@ import os
import os.path
from test import test_support
from test.test_support import TESTFN
+TESTFN2 = TESTFN + "2"
class TestShutil(unittest.TestCase):
def test_rmtree_errors(self):
@@ -240,6 +241,38 @@ class TestShutil(unittest.TestCase):
finally:
shutil.rmtree(TESTFN, ignore_errors=True)
+ if hasattr(os, "mkfifo"):
+ # Issue #3002: copyfile and copytree block indefinitely on named pipes
+ def test_copyfile_named_pipe(self):
+ os.mkfifo(TESTFN)
+ try:
+ self.assertRaises(shutil.SpecialFileError,
+ shutil.copyfile, TESTFN, TESTFN2)
+ self.assertRaises(shutil.SpecialFileError,
+ shutil.copyfile, __file__, TESTFN)
+ finally:
+ os.remove(TESTFN)
+
+ def test_copytree_named_pipe(self):
+ os.mkdir(TESTFN)
+ try:
+ subdir = os.path.join(TESTFN, "subdir")
+ os.mkdir(subdir)
+ pipe = os.path.join(subdir, "mypipe")
+ os.mkfifo(pipe)
+ try:
+ shutil.copytree(TESTFN, TESTFN2)
+ except shutil.Error as e:
+ errors = e.args[0]
+ self.assertEqual(len(errors), 1)
+ src, dst, error_msg = errors[0]
+ self.assertEqual("`%s` is a named pipe" % pipe, error_msg)
+ else:
+ self.fail("shutil.Error should have been raised")
+ finally:
+ shutil.rmtree(TESTFN, ignore_errors=True)
+ shutil.rmtree(TESTFN2, ignore_errors=True)
+
class TestMove(unittest.TestCase):