Back to index

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

List of all members.

Public Member Functions

def test_basic
def test_has_no_name
def test_multiple_close
def test_mode_and_encoding
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 TemporaryFile().

Definition at line 853 of file test_tempfile.py.


Member Function Documentation

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

00856 
00857     def test_basic(self):
00858         # TemporaryFile can create files
00859         # No point in testing the name params - the file has no name.
00860         try:
00861             tempfile.TemporaryFile()
00862         except:
00863             self.failOnException("TemporaryFile")

Here is the call graph for this function:

Definition at line 864 of file test_tempfile.py.

00864 
00865     def test_has_no_name(self):
00866         # TemporaryFile creates files with no names (on this system)
00867         dir = tempfile.mkdtemp()
00868         f = tempfile.TemporaryFile(dir=dir)
00869         f.write(b'blat')
00870 
00871         # Sneaky: because this file has no name, it should not prevent
00872         # us from removing the directory it was created in.
00873         try:
00874             os.rmdir(dir)
00875         except:
00876             ei = sys.exc_info()
00877             # cleanup
00878             f.close()
00879             os.rmdir(dir)
00880             self.failOnException("rmdir", ei)

Here is the call graph for this function:

Definition at line 893 of file test_tempfile.py.

00893 
00894     def test_mode_and_encoding(self):
00895 
00896         def roundtrip(input, *args, **kwargs):
00897             with tempfile.TemporaryFile(*args, **kwargs) as fileobj:
00898                 fileobj.write(input)
00899                 fileobj.seek(0)
00900                 self.assertEqual(input, fileobj.read())
00901 
00902         roundtrip(b"1234", "w+b")
00903         roundtrip("abdc\n", "w+")
00904         roundtrip("\u039B", "w+", encoding="utf-16")
00905         roundtrip("foo\r\n", "w+", newline="")
00906 

Here is the call graph for this function:

Definition at line 881 of file test_tempfile.py.

00881 
00882     def test_multiple_close(self):
00883         # A TemporaryFile can be closed many times without error
00884         f = tempfile.TemporaryFile()
00885         f.write(b'abc\n')
00886         f.close()
00887         try:
00888             f.close()
00889             f.close()
00890         except:
00891             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: