Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_tempfile.test_NamedTemporaryFile Class Reference

 def test_warning(self):

mktemp issues a warning when used

warnings.filterwarnings("error", category=RuntimeWarning, message="mktemp") self.assertRaises(RuntimeWarning, tempfile.mktemp, dir=self.dir) More...

Inheritance diagram for test.test_tempfile.test_NamedTemporaryFile:
Inheritance graph
[legend]
Collaboration diagram for test.test_tempfile.test_NamedTemporaryFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def do_create
def test_basic
def test_creates_named
def test_del_on_close
def test_dis_del_on_close
def test_multiple_close
def test_context_manager
def setUp
def tearDown
def failOnException
def nameCheck

Static Public Attributes

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

Detailed Description

 def test_warning(self):

mktemp issues a warning when used

warnings.filterwarnings("error", category=RuntimeWarning, message="mktemp") self.assertRaises(RuntimeWarning, tempfile.mktemp, dir=self.dir)

Test NamedTemporaryFile().

Definition at line 567 of file test_tempfile.py.


Member Function Documentation

def test.test_tempfile.test_NamedTemporaryFile.do_create (   self,
  dir = None,
  pre = "",
  suf = "",
  delete = True 
)

Definition at line 570 of file test_tempfile.py.

00570 
00571     def do_create(self, dir=None, pre="", suf="", delete=True):
00572         if dir is None:
00573             dir = tempfile.gettempdir()
00574         try:
00575             file = tempfile.NamedTemporaryFile(dir=dir, prefix=pre, suffix=suf,
00576                                                delete=delete)
00577         except:
00578             self.failOnException("NamedTemporaryFile")
00579 
00580         self.nameCheck(file.name, dir, pre, suf)
00581         return file
00582 

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

00583 
00584     def test_basic(self):
00585         # NamedTemporaryFile can create files
00586         self.do_create()
00587         self.do_create(pre="a")
00588         self.do_create(suf="b")
00589         self.do_create(pre="a", suf="b")
00590         self.do_create(pre="aa", suf=".txt")

Here is the call graph for this function:

Definition at line 636 of file test_tempfile.py.

00636 
00637     def test_context_manager(self):
00638         # A NamedTemporaryFile can be used as a context manager
00639         with tempfile.NamedTemporaryFile() as f:
00640             self.assertTrue(os.path.exists(f.name))
00641         self.assertFalse(os.path.exists(f.name))
00642         def use_closed():
00643             with f:
00644                 pass
00645         self.assertRaises(ValueError, use_closed)

Here is the call graph for this function:

Definition at line 591 of file test_tempfile.py.

00591 
00592     def test_creates_named(self):
00593         # NamedTemporaryFile creates files with names
00594         f = tempfile.NamedTemporaryFile()
00595         self.assertTrue(os.path.exists(f.name),
00596                         "NamedTemporaryFile %s does not exist" % f.name)

Here is the call graph for this function:

Definition at line 597 of file test_tempfile.py.

00597 
00598     def test_del_on_close(self):
00599         # A NamedTemporaryFile is deleted when closed
00600         dir = tempfile.mkdtemp()
00601         try:
00602             f = tempfile.NamedTemporaryFile(dir=dir)
00603             f.write(b'blat')
00604             f.close()
00605             self.assertFalse(os.path.exists(f.name),
00606                         "NamedTemporaryFile %s exists after close" % f.name)
00607         finally:
00608             os.rmdir(dir)

Here is the call graph for this function:

Definition at line 609 of file test_tempfile.py.

00609 
00610     def test_dis_del_on_close(self):
00611         # Tests that delete-on-close can be disabled
00612         dir = tempfile.mkdtemp()
00613         tmp = None
00614         try:
00615             f = tempfile.NamedTemporaryFile(dir=dir, delete=False)
00616             tmp = f.name
00617             f.write(b'blat')
00618             f.close()
00619             self.assertTrue(os.path.exists(f.name),
00620                         "NamedTemporaryFile %s missing after close" % f.name)
00621         finally:
00622             if tmp is not None:
00623                 os.unlink(tmp)
00624             os.rmdir(dir)

Here is the call graph for this function:

Definition at line 625 of file test_tempfile.py.

00625 
00626     def test_multiple_close(self):
00627         # A NamedTemporaryFile can be closed many times without error
00628         f = tempfile.NamedTemporaryFile()
00629         f.write(b'abc\n')
00630         f.close()
00631         try:
00632             f.close()
00633             f.close()
00634         except:
00635             self.failOnException("close")

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: