summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-07-17 20:52:51 (GMT)
committerFred Drake <fdrake@acm.org>2001-07-17 20:52:51 (GMT)
commit38c2ef0a4c6f7824e520a94401a349fb7a3f0d59 (patch)
treef898500127dec487cdf2f2be3729d77aa85bb817 /Lib
parent6f70d62855311cb02c0cc9994b3706724cad61fb (diff)
downloadcpython-38c2ef0a4c6f7824e520a94401a349fb7a3f0d59.zip
cpython-38c2ef0a4c6f7824e520a94401a349fb7a3f0d59.tar.gz
cpython-38c2ef0a4c6f7824e520a94401a349fb7a3f0d59.tar.bz2
Start of a test suite for the "os" module -- this only tests the temporary
file management functions that have just been made available on more platforms.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
new file mode 100644
index 0000000..59a2af6
--- /dev/null
+++ b/Lib/test/test_os.py
@@ -0,0 +1,60 @@
+# As a test suite for the os module, this is woefully inadequate, but this
+# does add tests for a few functions which have been determined to be more
+# more portable than they had been thought to be.
+
+import os
+import unittest
+
+from test_support import TESTFN, run_unittest
+
+
+class TemporaryFileTests(unittest.TestCase):
+ def setUp(self):
+ self.files = []
+ os.mkdir(TESTFN)
+
+ def tearDown(self):
+ for name in self.files:
+ os.unlink(name)
+ os.rmdir(TESTFN)
+
+ def check_tempfile(self, name):
+ # make sure it doesn't already exist:
+ self.failIf(os.path.exists(name),
+ "file already exists for temporary file")
+ # make sure we can create the file
+ open(name, "w")
+ self.files.append(name)
+
+ def test_tempnam(self):
+ if not hasattr(os, "tempnam"):
+ return
+ self.check_tempfile(os.tempnam())
+
+ name = os.tempnam(TESTFN)
+ self.assert_(os.path.dirname(name) == TESTFN)
+ self.check_tempfile(name)
+
+ name = os.tempnam(TESTFN, "pfx")
+ self.assert_(os.path.dirname(name) == TESTFN)
+ self.assert_(os.path.basename(name)[:3] == "pfx")
+ self.check_tempfile(name)
+
+ def test_tmpfile(self):
+ if not hasattr(os, "tmpfile"):
+ return
+ fp = os.tmpfile()
+ fp.write("foobar")
+ fp.seek(0,0)
+ s = fp.read()
+ fp.close()
+ self.assert_(s == "foobar")
+
+ def test_tmpnam(self):
+ if not hasattr(os, "tmpnam"):
+ return
+ self.check_tempfile(os.tmpnam())
+
+
+
+run_unittest(TemporaryFileTests)