Back to index

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

List of all members.

Public Member Functions

def do_create
def test_basic
def test_basic_many
def test_choose_directory
def test_mode
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 mkdtemp().

Definition at line 435 of file test_tempfile.py.


Member Function Documentation

def test.test_tempfile.test_mkdtemp.do_create (   self,
  dir = None,
  pre = "",
  suf = "" 
)

Definition at line 438 of file test_tempfile.py.

00438 
00439     def do_create(self, dir=None, pre="", suf=""):
00440         if dir is None:
00441             dir = tempfile.gettempdir()
00442         try:
00443             name = tempfile.mkdtemp(dir=dir, prefix=pre, suffix=suf)
00444         except:
00445             self.failOnException("mkdtemp")
00446 
00447         try:
00448             self.nameCheck(name, dir, pre, suf)
00449             return name
00450         except:
00451             os.rmdir(name)
00452             raise

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 453 of file test_tempfile.py.

00453 
00454     def test_basic(self):
00455         # mkdtemp can create directories
00456         os.rmdir(self.do_create())
00457         os.rmdir(self.do_create(pre="a"))
00458         os.rmdir(self.do_create(suf="b"))
00459         os.rmdir(self.do_create(pre="a", suf="b"))
00460         os.rmdir(self.do_create(pre="aa", suf=".txt"))

Here is the call graph for this function:

Definition at line 461 of file test_tempfile.py.

00461 
00462     def test_basic_many(self):
00463         # mkdtemp can create many directories (stochastic)
00464         extant = list(range(TEST_FILES))
00465         try:
00466             for i in extant:
00467                 extant[i] = self.do_create(pre="aa")
00468         finally:
00469             for i in extant:
00470                 if(isinstance(i, str)):
00471                     os.rmdir(i)

Here is the call graph for this function:

Definition at line 472 of file test_tempfile.py.

00472 
00473     def test_choose_directory(self):
00474         # mkdtemp can create directories in a user-selected directory
00475         dir = tempfile.mkdtemp()
00476         try:
00477             os.rmdir(self.do_create(dir=dir))
00478         finally:
00479             os.rmdir(dir)

Here is the call graph for this function:

Definition at line 480 of file test_tempfile.py.

00480 
00481     def test_mode(self):
00482         # mkdtemp creates directories with the proper mode
00483         if not has_stat:
00484             return            # ugh, can't use SkipTest.
00485 
00486         dir = self.do_create()
00487         try:
00488             mode = stat.S_IMODE(os.stat(dir).st_mode)
00489             mode &= 0o777 # Mask off sticky bits inherited from /tmp
00490             expected = 0o700
00491             if sys.platform in ('win32', 'os2emx'):
00492                 # There's no distinction among 'user', 'group' and 'world';
00493                 # replicate the 'user' bits.
00494                 user = expected >> 6
00495                 expected = user * (1 + 8 + 64)
00496             self.assertEqual(mode, expected)
00497         finally:
00498             os.rmdir(dir)
00499 
00500 test_classes.append(test_mkdtemp)
00501 

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: