Back to index

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

List of all members.

Public Member Functions

def test_home_installation_scheme
def test_user_site
def test_handle_extra_path
def test_finalize_options
def test_record
def test_record_extensions
def test_debug_mode
def setUp
def tearDown
def mkdtemp
def write_file
def create_dist
def setUp
def tearDown
def setUp
def tearDown
def get_logs
def clear_logs

Public Attributes

 old_user_base
 old_user_site
 tmpdir
 user_base
 user_site
 old_expand
 old_cwd
 tempdirs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type
 old_environ
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type
 threshold
 logs
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _test_user_site

Detailed Description

Definition at line 32 of file test_install.py.


Member Function Documentation

Definition at line 101 of file test_install.py.

00101 
00102     def _test_user_site(self):
00103         for key in ('nt_user', 'unix_user', 'os2_home'):
00104             self.assertTrue(key in INSTALL_SCHEMES)
00105 
00106         dist = Distribution({'name': 'xx'})
00107         cmd = install(dist)
00108 
00109         # making sure the user option is there
00110         options = [name for name, short, lable in
00111                    cmd.user_options]
00112         self.assertTrue('user' in options)
00113 
00114         # setting a value
00115         cmd.user = 1
00116 
00117         # user base and site shouldn't be created yet
00118         self.assertTrue(not os.path.exists(self.user_base))
00119         self.assertTrue(not os.path.exists(self.user_site))
00120 
00121         # let's run finalize
00122         cmd.ensure_finalized()
00123 
00124         # now they should
00125         self.assertTrue(os.path.exists(self.user_base))
00126         self.assertTrue(os.path.exists(self.user_site))
00127 
00128         self.assertTrue('userbase' in cmd.config_vars)
00129         self.assertTrue('usersite' in cmd.config_vars)

Here is the call graph for this function:

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:

def distutils.tests.support.EnvironGuard.setUp (   self) [inherited]

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:

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_dist.DistributionTestCase, distutils.tests.test_util.UtilTestCase, distutils.tests.test_core.CoreTestCase, distutils.tests.test_bdist_dumb.BuildDumbTestCase, and distutils.tests.test_sysconfig.SysconfigTestCase.

Definition at line 127 of file support.py.

00127 
00128     def tearDown(self):
00129         for key, value in self.old_environ.items():
00130             if os.environ.get(key) != value:
00131                 os.environ[key] = value
00132 
00133         for key in tuple(os.environ.keys()):
00134             if key not in self.old_environ:
00135                 del os.environ[key]
00136 
00137         super(EnvironGuard, self).tearDown()
00138 

Here is the caller graph for this function:

Definition at line 235 of file test_install.py.

00235 
00236     def test_debug_mode(self):
00237         # this covers the code called when DEBUG is set
00238         old_logs_len = len(self.logs)
00239         install_module.DEBUG = True
00240         try:
00241             with captured_stdout():
00242                 self.test_record()
00243         finally:
00244             install_module.DEBUG = False
00245         self.assertTrue(len(self.logs) > old_logs_len)

Here is the call graph for this function:

Definition at line 158 of file test_install.py.

00158 
00159     def test_finalize_options(self):
00160         dist = Distribution({'name': 'xx'})
00161         cmd = install(dist)
00162 
00163         # must supply either prefix/exec-prefix/home or
00164         # install-base/install-platbase -- not both
00165         cmd.prefix = 'prefix'
00166         cmd.install_base = 'base'
00167         self.assertRaises(DistutilsOptionError, cmd.finalize_options)
00168 
00169         # must supply either home or prefix/exec-prefix -- not both
00170         cmd.install_base = None
00171         cmd.home = 'home'
00172         self.assertRaises(DistutilsOptionError, cmd.finalize_options)
00173 
00174         # can't combine user with with prefix/exec_prefix/home or
00175         # install_(plat)base
00176         cmd.prefix = None
00177         cmd.user = 'user'
00178         self.assertRaises(DistutilsOptionError, cmd.finalize_options)

Here is the call graph for this function:

Definition at line 130 of file test_install.py.

00130 
00131     def test_handle_extra_path(self):
00132         dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
00133         cmd = install(dist)
00134 
00135         # two elements
00136         cmd.handle_extra_path()
00137         self.assertEqual(cmd.extra_path, ['path', 'dirs'])
00138         self.assertEqual(cmd.extra_dirs, 'dirs')
00139         self.assertEqual(cmd.path_file, 'path')
00140 
00141         # one element
00142         cmd.extra_path = ['path']
00143         cmd.handle_extra_path()
00144         self.assertEqual(cmd.extra_path, ['path'])
00145         self.assertEqual(cmd.extra_dirs, 'path')
00146         self.assertEqual(cmd.path_file, 'path')
00147 
00148         # none
00149         dist.extra_path = cmd.extra_path = None
00150         cmd.handle_extra_path()
00151         self.assertEqual(cmd.extra_path, None)
00152         self.assertEqual(cmd.extra_dirs, '')
00153         self.assertEqual(cmd.path_file, None)
00154 
00155         # three elements (no way !)
00156         cmd.extra_path = 'path,dirs,again'
00157         self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)

Here is the call graph for this function:

Definition at line 34 of file test_install.py.

00034 
00035     def test_home_installation_scheme(self):
00036         # This ensure two things:
00037         # - that --home generates the desired set of directory names
00038         # - test --home is supported on all platforms
00039         builddir = self.mkdtemp()
00040         destination = os.path.join(builddir, "installation")
00041 
00042         dist = Distribution({"name": "foopkg"})
00043         # script_name need not exist, it just need to be initialized
00044         dist.script_name = os.path.join(builddir, "setup.py")
00045         dist.command_obj["build"] = support.DummyCommand(
00046             build_base=builddir,
00047             build_lib=os.path.join(builddir, "lib"),
00048             )
00049 
00050         cmd = install(dist)
00051         cmd.home = destination
00052         cmd.ensure_finalized()
00053 
00054         self.assertEqual(cmd.install_base, destination)
00055         self.assertEqual(cmd.install_platbase, destination)
00056 
00057         def check_path(got, expected):
00058             got = os.path.normpath(got)
00059             expected = os.path.normpath(expected)
00060             self.assertEqual(got, expected)
00061 
00062         libdir = os.path.join(destination, "lib", "python")
00063         check_path(cmd.install_lib, libdir)
00064         check_path(cmd.install_platlib, libdir)
00065         check_path(cmd.install_purelib, libdir)
00066         check_path(cmd.install_headers,
00067                    os.path.join(destination, "include", "python", "foopkg"))
00068         check_path(cmd.install_scripts, os.path.join(destination, "bin"))
00069         check_path(cmd.install_data, destination)

Here is the call graph for this function:

Definition at line 179 of file test_install.py.

00179 
00180     def test_record(self):
00181         install_dir = self.mkdtemp()
00182         project_dir, dist = self.create_dist(scripts=['hello'])
00183         self.addCleanup(os.chdir, os.getcwd())
00184         os.chdir(project_dir)
00185         self.write_file('hello', "print('o hai')")
00186 
00187         cmd = install(dist)
00188         dist.command_obj['install'] = cmd
00189         cmd.root = install_dir
00190         cmd.record = os.path.join(project_dir, 'RECORD')
00191         cmd.ensure_finalized()
00192         cmd.run()
00193 
00194         f = open(cmd.record)
00195         try:
00196             content = f.read()
00197         finally:
00198             f.close()
00199 
00200         found = [os.path.basename(line) for line in content.splitlines()]
00201         expected = ['hello',
00202                     'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
00203         self.assertEqual(found, expected)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 204 of file test_install.py.

00204 
00205     def test_record_extensions(self):
00206         install_dir = self.mkdtemp()
00207         project_dir, dist = self.create_dist(ext_modules=[
00208             Extension('xx', ['xxmodule.c'])])
00209         self.addCleanup(os.chdir, os.getcwd())
00210         os.chdir(project_dir)
00211         support.copy_xxmodule_c(project_dir)
00212 
00213         buildextcmd = build_ext(dist)
00214         support.fixup_build_ext(buildextcmd)
00215         buildextcmd.ensure_finalized()
00216 
00217         cmd = install(dist)
00218         dist.command_obj['install'] = cmd
00219         dist.command_obj['build_ext'] = buildextcmd
00220         cmd.root = install_dir
00221         cmd.record = os.path.join(project_dir, 'RECORD')
00222         cmd.ensure_finalized()
00223         cmd.run()
00224 
00225         f = open(cmd.record)
00226         try:
00227             content = f.read()
00228         finally:
00229             f.close()
00230 
00231         found = [os.path.basename(line) for line in content.splitlines()]
00232         expected = [_make_ext_name('xx'),
00233                     'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
00234         self.assertEqual(found, expected)

Here is the call graph for this function:

Definition at line 70 of file test_install.py.

00070 
00071     def test_user_site(self):
00072         # site.USER_SITE was introduced in 2.6
00073         if sys.version < '2.6':
00074             return
00075 
00076         # preparing the environment for the test
00077         self.old_user_base = site.USER_BASE
00078         self.old_user_site = site.USER_SITE
00079         self.tmpdir = self.mkdtemp()
00080         self.user_base = os.path.join(self.tmpdir, 'B')
00081         self.user_site = os.path.join(self.tmpdir, 'S')
00082         site.USER_BASE = self.user_base
00083         site.USER_SITE = self.user_site
00084         install_module.USER_BASE = self.user_base
00085         install_module.USER_SITE = self.user_site
00086 
00087         def _expanduser(path):
00088             return self.tmpdir
00089         self.old_expand = os.path.expanduser
00090         os.path.expanduser = _expanduser
00091 
00092         try:
00093             # this is the actual test
00094             self._test_user_site()
00095         finally:
00096             site.USER_BASE = self.old_user_base
00097             site.USER_SITE = self.old_user_site
00098             install_module.USER_BASE = self.old_user_base
00099             install_module.USER_SITE = self.old_user_site
00100             os.path.expanduser = self.old_expand

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.

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.

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

Definition at line 88 of file test_install.py.

Definition at line 76 of file test_install.py.

Definition at line 77 of file test_install.py.

Definition at line 58 of file support.py.

Definition at line 19 of file support.py.

Definition at line 78 of file test_install.py.

Definition at line 79 of file test_install.py.

Definition at line 80 of file test_install.py.


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