Index: Lib/tempfile.py =================================================================== --- Lib/tempfile.py (revision 86467) +++ Lib/tempfile.py (working copy) @@ -316,7 +316,7 @@ file = _os.path.join(dir, prefix + name + suffix) try: _os.mkdir(file, 0700) - return file + return _os.path.abspath(file) except OSError, e: if e.errno == _errno.EEXIST: continue # try again Index: Lib/test/test_tempfile.py =================================================================== --- Lib/test/test_tempfile.py (revision 86467) +++ Lib/test/test_tempfile.py (working copy) @@ -48,18 +48,22 @@ nsuf = nbase[len(nbase)-len(suf):] # check for equality of the absolute paths! + self.assertTrue(os.path.isabs(name), + "path '%s' is not an absolute path" % (name)) self.assertEqual(os.path.abspath(ndir), os.path.abspath(dir), "file '%s' not in directory '%s'" % (name, dir)) self.assertEqual(npre, pre, "file '%s' does not begin with '%s'" % (nbase, pre)) self.assertEqual(nsuf, suf, "file '%s' does not end with '%s'" % (nbase, suf)) - nbase = nbase[len(pre):len(nbase)-len(suf)] - self.assertTrue(self.str_check.match(nbase), - "random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/" - % nbase) + self.stringCheck(nbase) + def stringCheck(self, pattern): + self.assertTrue(self.str_check.match(pattern), + "random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/" + % pattern) + test_classes = [] class test_exports(TC): @@ -100,7 +104,8 @@ def test_get_six_char_str(self): # _RandomNameSequence returns a six-character string s = self.r.next() - self.nameCheck(s, '', '', '') + self.assertEqual(len(s), 6) + self.stringCheck(s) def test_many(self): # _RandomNameSequence returns no duplicate strings (stochastic) @@ -109,8 +114,8 @@ r = self.r for i in xrange(TEST_FILES): s = r.next() - self.nameCheck(s, '', '', '') self.assertNotIn(s, dict) + self.stringCheck(s) dict[s] = 1 def test_supports_iter(self): @@ -483,6 +488,17 @@ finally: os.rmdir(dir) + def test_return_abs_path_on_rel_directory(self): + # mkdtemp returns an absolute path even when passed a dir that + # is a relative path. + try: + cwd = os.getcwd() + os.chdir(tempfile.gettempdir()) + name = self.do_create(dir=".") + finally: + os.chdir(cwd) + os.rmdir(name) + test_classes.append(test_mkdtemp)