Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
distutils.tests.test_text_file.TextFileTestCase Class Reference
Inheritance diagram for distutils.tests.test_text_file.TextFileTestCase:
Inheritance graph
[legend]
Collaboration diagram for distutils.tests.test_text_file.TextFileTestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_class
def setUp
def tearDown
def mkdtemp
def write_file
def create_dist

Public Attributes

 old_cwd
 tempdirs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Definition at line 15 of file test_text_file.py.


Member Function Documentation

def distutils.tests.support.TempdirManager.create_dist (   self,
  pkg_name = 'foo',
  kw 
) [inherited]
Will generate a test environment.

This function creates:
 - a Distribution instance using keywords
 - a temporary directory with a package structure

It returns the package directory and the distribution
instance.

Definition at line 92 of file support.py.

00092 
00093     def create_dist(self, pkg_name='foo', **kw):
00094         """Will generate a test environment.
00095 
00096         This function creates:
00097          - a Distribution instance using keywords
00098          - a temporary directory with a package structure
00099 
00100         It returns the package directory and the distribution
00101         instance.
00102         """
00103         tmp_dir = self.mkdtemp()
00104         pkg_dir = os.path.join(tmp_dir, pkg_name)
00105         os.mkdir(pkg_dir)
00106         dist = Distribution(attrs=kw)
00107 
00108         return pkg_dir, dist
00109 

Here is the call graph for this function:

Here is the caller graph for this function:

Create a temporary directory that will be cleaned up.

Returns the path of the directory.

Definition at line 69 of file support.py.

00069 
00070     def mkdtemp(self):
00071         """Create a temporary directory that will be cleaned up.
00072 
00073         Returns the path of the directory.
00074         """
00075         d = tempfile.mkdtemp()
00076         self.tempdirs.append(d)
00077         return d

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in distutils.tests.test_dist.MetadataTestCase, distutils.tests.test_register.RegisterTestCase, distutils.tests.test_upload.uploadTestCase, distutils.tests.test_config.PyPIRCCommandTestCase, distutils.tests.test_sdist.SDistTestCase, distutils.tests.test_cygwinccompiler.CygwinCCompilerTestCase, distutils.tests.test_bdist_dumb.BuildDumbTestCase, distutils.tests.test_bdist_rpm.BuildRpmTestCase, distutils.tests.test_dir_util.DirUtilTestCase, distutils.tests.test_file_util.FileUtilTestCase, and distutils.tests.test_config_cmd.ConfigTestCase.

Definition at line 60 of file support.py.

00060 
00061     def tearDown(self):
00062         # Restore working dir, for Solaris and derivatives, where rmdir()
00063         # on the current directory fails.
00064         os.chdir(self.old_cwd)
00065         super().tearDown()
00066         while self.tempdirs:
00067             d = self.tempdirs.pop()
00068             shutil.rmtree(d, os.name in ('nt', 'cygwin'))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 17 of file test_text_file.py.

00017 
00018     def test_class(self):
00019         # old tests moved from text_file.__main__
00020         # so they are really called by the buildbots
00021 
00022         # result 1: no fancy options
00023         result1 = ['# test file\n', '\n', 'line 3 \\\n',
00024                    '# intervening comment\n',
00025                    '  continues on next line\n']
00026 
00027         # result 2: just strip comments
00028         result2 = ["\n",
00029                    "line 3 \\\n",
00030                    "  continues on next line\n"]
00031 
00032         # result 3: just strip blank lines
00033         result3 = ["# test file\n",
00034                    "line 3 \\\n",
00035                    "# intervening comment\n",
00036                    "  continues on next line\n"]
00037 
00038         # result 4: default, strip comments, blank lines,
00039         # and trailing whitespace
00040         result4 = ["line 3 \\",
00041                    "  continues on next line"]
00042 
00043         # result 5: strip comments and blanks, plus join lines (but don't
00044         # "collapse" joined lines
00045         result5 = ["line 3   continues on next line"]
00046 
00047         # result 6: strip comments and blanks, plus join lines (and
00048         # "collapse" joined lines
00049         result6 = ["line 3 continues on next line"]
00050 
00051         def test_input(count, description, file, expected_result):
00052             result = file.readlines()
00053             self.assertEqual(result, expected_result)
00054 
00055         tmpdir = self.mkdtemp()
00056         filename = os.path.join(tmpdir, "test.txt")
00057         out_file = open(filename, "w")
00058         try:
00059             out_file.write(TEST_DATA)
00060         finally:
00061             out_file.close()
00062 
00063         in_file = TextFile(filename, strip_comments=0, skip_blanks=0,
00064                            lstrip_ws=0, rstrip_ws=0)
00065         try:
00066             test_input(1, "no processing", in_file, result1)
00067         finally:
00068             in_file.close()
00069 
00070         in_file = TextFile(filename, strip_comments=1, skip_blanks=0,
00071                            lstrip_ws=0, rstrip_ws=0)
00072         try:
00073             test_input(2, "strip comments", in_file, result2)
00074         finally:
00075             in_file.close()
00076 
00077         in_file = TextFile(filename, strip_comments=0, skip_blanks=1,
00078                            lstrip_ws=0, rstrip_ws=0)
00079         try:
00080             test_input(3, "strip blanks", in_file, result3)
00081         finally:
00082             in_file.close()
00083 
00084         in_file = TextFile(filename)
00085         try:
00086             test_input(4, "default processing", in_file, result4)
00087         finally:
00088             in_file.close()
00089 
00090         in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
00091                            join_lines=1, rstrip_ws=1)
00092         try:
00093             test_input(5, "join lines without collapsing", in_file, result5)
00094         finally:
00095             in_file.close()
00096 
00097         in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
00098                            join_lines=1, rstrip_ws=1, collapse_join=1)
00099         try:
00100             test_input(6, "join lines with collapsing", in_file, result6)
00101         finally:
00102             in_file.close()

Here is the call graph for this function:

def distutils.tests.support.TempdirManager.write_file (   self,
  path,
  content = 'xxx' 
) [inherited]
Writes a file in the given path.


path can be a string or a sequence.

Definition at line 78 of file support.py.

00078 
00079     def write_file(self, path, content='xxx'):
00080         """Writes a file in the given path.
00081 
00082 
00083         path can be a string or a sequence.
00084         """
00085         if isinstance(path, (list, tuple)):
00086             path = os.path.join(*path)
00087         f = open(path, 'w')
00088         try:
00089             f.write(content)
00090         finally:
00091             f.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 57 of file support.py.

Definition at line 58 of file support.py.


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