summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-25 09:28:23 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-25 09:28:23 (GMT)
commite77c974357fa96917e6966d627a69eae8a919b37 (patch)
tree6a11773878b477093197c78e3490fda3ec67c02f /Lib/test
parentb72e21b9ab8021b7cbb7e0007d1bf80d533bce15 (diff)
downloadcpython-e77c974357fa96917e6966d627a69eae8a919b37.zip
cpython-e77c974357fa96917e6966d627a69eae8a919b37.tar.gz
cpython-e77c974357fa96917e6966d627a69eae8a919b37.tar.bz2
test_os: Win32ErrorTests now ensures that TESTFN doesn't exist
Replace also other open(filename, "w") with open(filename, "x") to fail if a previous test forgot to remove filename.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_os.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index bc24e47..c8789d7 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -845,9 +845,8 @@ class WalkTests(unittest.TestCase):
os.makedirs(t2_path)
for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:
- f = open(path, "w")
- f.write("I'm " + path + " and proud of it. Blame test_os.\n")
- f.close()
+ with open(path, "x") as f:
+ f.write("I'm " + path + " and proud of it. Blame test_os.\n")
if support.can_symlink():
os.symlink(os.path.abspath(t2_path), self.link_path)
@@ -1427,6 +1426,9 @@ class ExecTests(unittest.TestCase):
@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
class Win32ErrorTests(unittest.TestCase):
+ def setUp(self):
+ self.assertFalse(os.path.exists(support.TESTFN))
+
def test_rename(self):
self.assertRaises(OSError, os.rename, support.TESTFN, support.TESTFN+".bak")
@@ -1439,7 +1441,7 @@ class Win32ErrorTests(unittest.TestCase):
def test_mkdir(self):
self.addCleanup(support.unlink, support.TESTFN)
- with open(support.TESTFN, "w") as f:
+ with open(support.TESTFN, "x") as f:
self.assertRaises(OSError, os.mkdir, support.TESTFN)
def test_utime(self):
@@ -1448,6 +1450,7 @@ class Win32ErrorTests(unittest.TestCase):
def test_chmod(self):
self.assertRaises(OSError, os.chmod, support.TESTFN, 0)
+
class TestInvalidFD(unittest.TestCase):
singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat",
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
@@ -1559,8 +1562,7 @@ class LinkTests(unittest.TestCase):
os.unlink(file)
def _test_link(self, file1, file2):
- with open(file1, "w") as f1:
- f1.write("test")
+ create_file(file1)
with bytes_filename_warn(False):
os.link(file1, file2)