Back to index

python3.2  3.2.2
Classes | Public Member Functions | Static Public Attributes
test.test_tempfile.test__mkstemp_inner Class Reference
Inheritance diagram for test.test_tempfile.test__mkstemp_inner:
Inheritance graph
[legend]
Collaboration diagram for test.test_tempfile.test__mkstemp_inner:
Collaboration graph
[legend]

List of all members.

Classes

class  mkstemped

Public Member Functions

def do_create
def test_basic
def test_basic_many
def test_choose_directory
def test_file_mode
def test_noinherit
def test_textmode
def setUp
def tearDown
def failOnException
def nameCheck

Static Public Attributes

tuple str_check = re.compile(r"[a-zA-Z0-9_-]{6}$")

Detailed Description

Test the internal function _mkstemp_inner.

Definition at line 204 of file test_tempfile.py.


Member Function Documentation

def test.test_tempfile.test__mkstemp_inner.do_create (   self,
  dir = None,
  pre = "",
  suf = "",
  bin = 1 
)

Definition at line 226 of file test_tempfile.py.

00226 
00227     def do_create(self, dir=None, pre="", suf="", bin=1):
00228         if dir is None:
00229             dir = tempfile.gettempdir()
00230         try:
00231             file = self.mkstemped(dir, pre, suf, bin)
00232         except:
00233             self.failOnException("_mkstemp_inner")
00234 
00235         self.nameCheck(file.name, dir, pre, suf)
00236         return file

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_tempfile.TC.failOnException (   self,
  what,
  ei = None 
) [inherited]

Definition at line 47 of file test_tempfile.py.

00047 
00048     def failOnException(self, what, ei=None):
00049         if ei is None:
00050             ei = sys.exc_info()
00051         self.fail("%s raised %s: %s" % (what, ei[0], ei[1]))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_tempfile.TC.nameCheck (   self,
  name,
  dir,
  pre,
  suf 
) [inherited]

Definition at line 52 of file test_tempfile.py.

00052 
00053     def nameCheck(self, name, dir, pre, suf):
00054         (ndir, nbase) = os.path.split(name)
00055         npre  = nbase[:len(pre)]
00056         nsuf  = nbase[len(nbase)-len(suf):]
00057 
00058         # check for equality of the absolute paths!
00059         self.assertEqual(os.path.abspath(ndir), os.path.abspath(dir),
00060                          "file '%s' not in directory '%s'" % (name, dir))
00061         self.assertEqual(npre, pre,
00062                          "file '%s' does not begin with '%s'" % (nbase, pre))
00063         self.assertEqual(nsuf, suf,
00064                          "file '%s' does not end with '%s'" % (nbase, suf))
00065 
00066         nbase = nbase[len(pre):len(nbase)-len(suf)]
00067         self.assertTrue(self.str_check.match(nbase),
00068                      "random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/"
00069                      % nbase)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_tempfile.TC.setUp (   self) [inherited]

Reimplemented in test.test_tempfile.test_mktemp, and test.test_tempfile.test__RandomNameSequence.

Definition at line 37 of file test_tempfile.py.

00037 
00038     def setUp(self):
00039         self._warnings_manager = support.check_warnings()
00040         self._warnings_manager.__enter__()
00041         warnings.filterwarnings("ignore", category=RuntimeWarning,
00042                                 message="mktemp", module=__name__)

Here is the caller graph for this function:

def test.test_tempfile.TC.tearDown (   self) [inherited]

Reimplemented in test.test_tempfile.test_mktemp.

Definition at line 43 of file test_tempfile.py.

00043 
00044     def tearDown(self):
00045         self._warnings_manager.__exit__(None, None, None)
00046 

Here is the caller graph for this function:

Definition at line 237 of file test_tempfile.py.

00237 
00238     def test_basic(self):
00239         # _mkstemp_inner can create files
00240         self.do_create().write(b"blat")
00241         self.do_create(pre="a").write(b"blat")
00242         self.do_create(suf="b").write(b"blat")
00243         self.do_create(pre="a", suf="b").write(b"blat")
00244         self.do_create(pre="aa", suf=".txt").write(b"blat")

Here is the call graph for this function:

Definition at line 245 of file test_tempfile.py.

00245 
00246     def test_basic_many(self):
00247         # _mkstemp_inner can create many files (stochastic)
00248         extant = list(range(TEST_FILES))
00249         for i in extant:
00250             extant[i] = self.do_create(pre="aa")

Here is the call graph for this function:

Definition at line 251 of file test_tempfile.py.

00251 
00252     def test_choose_directory(self):
00253         # _mkstemp_inner can create files in a user-selected directory
00254         dir = tempfile.mkdtemp()
00255         try:
00256             self.do_create(dir=dir).write(b"blat")
00257         finally:
00258             os.rmdir(dir)

Here is the call graph for this function:

Definition at line 259 of file test_tempfile.py.

00259 
00260     def test_file_mode(self):
00261         # _mkstemp_inner creates files with the proper mode
00262         if not has_stat:
00263             return            # ugh, can't use SkipTest.
00264 
00265         file = self.do_create()
00266         mode = stat.S_IMODE(os.stat(file.name).st_mode)
00267         expected = 0o600
00268         if sys.platform in ('win32', 'os2emx'):
00269             # There's no distinction among 'user', 'group' and 'world';
00270             # replicate the 'user' bits.
00271             user = expected >> 6
00272             expected = user * (1 + 8 + 64)
00273         self.assertEqual(mode, expected)

Here is the call graph for this function:

Definition at line 274 of file test_tempfile.py.

00274 
00275     def test_noinherit(self):
00276         # _mkstemp_inner file handles are not inherited by child processes
00277         if not has_spawnl:
00278             return            # ugh, can't use SkipTest.
00279 
00280         if support.verbose:
00281             v="v"
00282         else:
00283             v="q"
00284 
00285         file = self.do_create()
00286         fd = "%d" % file.fd
00287 
00288         try:
00289             me = __file__
00290         except NameError:
00291             me = sys.argv[0]
00292 
00293         # We have to exec something, so that FD_CLOEXEC will take
00294         # effect.  The core of this test is therefore in
00295         # tf_inherit_check.py, which see.
00296         tester = os.path.join(os.path.dirname(os.path.abspath(me)),
00297                               "tf_inherit_check.py")
00298 
00299         # On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
00300         # but an arg with embedded spaces should be decorated with double
00301         # quotes on each end
00302         if sys.platform in ('win32',):
00303             decorated = '"%s"' % sys.executable
00304             tester = '"%s"' % tester
00305         else:
00306             decorated = sys.executable
00307 
00308         retval = os.spawnl(os.P_WAIT, sys.executable, decorated, tester, v, fd)
00309         self.assertFalse(retval < 0,
00310                     "child process caught fatal signal %d" % -retval)
00311         self.assertFalse(retval > 0, "child process reports failure %d"%retval)

Here is the call graph for this function:

Definition at line 312 of file test_tempfile.py.

00312 
00313     def test_textmode(self):
00314         # _mkstemp_inner can create files in text mode
00315         if not has_textmode:
00316             return            # ugh, can't use SkipTest.
00317 
00318         # A text file is truncated at the first Ctrl+Z byte
00319         f = self.do_create(bin=0)
00320         f.write(b"blat\x1a")
00321         f.write(b"extra\n")
00322         os.lseek(f.fd, 0, os.SEEK_SET)
00323         self.assertEqual(os.read(f.fd, 20), b"blat")
00324 
00325 test_classes.append(test__mkstemp_inner)
00326 

Here is the call graph for this function:


Member Data Documentation

tuple test.test_tempfile.TC.str_check = re.compile(r"[a-zA-Z0-9_-]{6}$") [static, inherited]

Definition at line 35 of file test_tempfile.py.


The documentation for this class was generated from the following file: