Back to index

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

List of all members.

Public Member Functions

def test_package_data
def test_empty_package_dir
def test_dont_write_bytecode
def setUp
def tearDown
def mkdtemp
def write_file
def create_dist
def setUp
def tearDown
def get_logs
def clear_logs

Public Attributes

 old_cwd
 tempdirs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type
 threshold
 logs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Definition at line 18 of file test_build_py.py.


Member Function Documentation

Definition at line 45 of file support.py.

00045 
00046     def clear_logs(self):
00047         self.logs = []
00048 

Here is the caller graph for this function:

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:

def distutils.tests.support.LoggingSilencer.get_logs (   self,
  levels 
) [inherited]

Definition at line 37 of file support.py.

00037 
00038     def get_logs(self, *levels):
00039         def _format(msg, args):
00040             if len(args) == 0:
00041                 return msg
00042             return msg % args
00043         return [_format(msg, args) for level, msg, args
00044                 in self.logs if level in levels]

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_upload.uploadTestCase, distutils.tests.test_register.RegisterTestCase, distutils.tests.test_config.PyPIRCCommandTestCase, distutils.tests.test_sdist.SDistTestCase, distutils.tests.test_dist.DistributionTestCase, distutils.tests.test_bdist_dumb.BuildDumbTestCase, distutils.tests.test_bdist_rpm.BuildRpmTestCase, and distutils.tests.test_config_cmd.ConfigTestCase.

Definition at line 17 of file support.py.

00017 
00018     def setUp(self):
00019         super().setUp()
00020         self.threshold = log.set_threshold(log.FATAL)
00021         # catching warnings
00022         # when log will be replaced by logging
00023         # we won't need such monkey-patch anymore
00024         self._old_log = log.Log._log
00025         log.Log._log = self._log
00026         self.logs = []

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 102 of file test_build_py.py.

00102 
00103     def test_dont_write_bytecode(self):
00104         # makes sure byte_compile is not used
00105         pkg_dir, dist = self.create_dist()
00106         cmd = build_py(dist)
00107         cmd.compile = 1
00108         cmd.optimize = 1
00109 
00110         old_dont_write_bytecode = sys.dont_write_bytecode
00111         sys.dont_write_bytecode = True
00112         try:
00113             cmd.byte_compile([])
00114         finally:
00115             sys.dont_write_bytecode = old_dont_write_bytecode
00116 
00117         self.assertIn('byte-compiling is disabled', self.logs[0][1])

Here is the call graph for this function:

Definition at line 68 of file test_build_py.py.

00068 
00069     def test_empty_package_dir(self):
00070         # See SF 1668596/1720897.
00071         cwd = os.getcwd()
00072 
00073         # create the distribution files.
00074         sources = self.mkdtemp()
00075         open(os.path.join(sources, "__init__.py"), "w").close()
00076 
00077         testdir = os.path.join(sources, "doc")
00078         os.mkdir(testdir)
00079         open(os.path.join(testdir, "testfile"), "w").close()
00080 
00081         os.chdir(sources)
00082         old_stdout = sys.stdout
00083         sys.stdout = io.StringIO()
00084 
00085         try:
00086             dist = Distribution({"packages": ["pkg"],
00087                                  "package_dir": {"pkg": ""},
00088                                  "package_data": {"pkg": ["doc/*"]}})
00089             # script_name need not exist, it just need to be initialized
00090             dist.script_name = os.path.join(sources, "setup.py")
00091             dist.script_args = ["build"]
00092             dist.parse_command_line()
00093 
00094             try:
00095                 dist.run_commands()
00096             except DistutilsFileError:
00097                 self.fail("failed package_data test when package_dir is ''")
00098         finally:
00099             # Restore state.
00100             os.chdir(cwd)
00101             sys.stdout = old_stdout

Here is the call graph for this function:

Definition at line 20 of file test_build_py.py.

00020 
00021     def test_package_data(self):
00022         sources = self.mkdtemp()
00023         f = open(os.path.join(sources, "__init__.py"), "w")
00024         try:
00025             f.write("# Pretend this is a package.")
00026         finally:
00027             f.close()
00028         f = open(os.path.join(sources, "README.txt"), "w")
00029         try:
00030             f.write("Info about this package")
00031         finally:
00032             f.close()
00033 
00034         destination = self.mkdtemp()
00035 
00036         dist = Distribution({"packages": ["pkg"],
00037                              "package_dir": {"pkg": sources}})
00038         # script_name need not exist, it just need to be initialized
00039         dist.script_name = os.path.join(sources, "setup.py")
00040         dist.command_obj["build"] = support.DummyCommand(
00041             force=0,
00042             build_lib=destination)
00043         dist.packages = ["pkg"]
00044         dist.package_data = {"pkg": ["README.txt"]}
00045         dist.package_dir = {"pkg": sources}
00046 
00047         cmd = build_py(dist)
00048         cmd.compile = 1
00049         cmd.ensure_finalized()
00050         self.assertEqual(cmd.package_data, dist.package_data)
00051 
00052         cmd.run()
00053 
00054         # This makes sure the list of outputs includes byte-compiled
00055         # files for Python modules but not for package data files
00056         # (there shouldn't *be* byte-code files for those!).
00057         #
00058         self.assertEqual(len(cmd.get_outputs()), 3)
00059         pkgdest = os.path.join(destination, "pkg")
00060         files = os.listdir(pkgdest)
00061         self.assertIn("__init__.py", files)
00062         self.assertIn("README.txt", files)
00063         # XXX even with -O, distutils writes pyc, not pyo; bug?
00064         if sys.dont_write_bytecode:
00065             self.assertNotIn("__init__.pyc", files)
00066         else:
00067             self.assertIn("__init__.pyc", files)

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 25 of file support.py.

Definition at line 107 of file object.h.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 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.

Definition at line 19 of file support.py.


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