Back to index

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

List of all members.

Public Member Functions

def test_check_library_dist
def test_get_source_files
def test_build_libraries
def test_finalize_options
def test_run
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 15 of file test_build_clib.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 69 of file test_build_clib.py.

00069 
00070     def test_build_libraries(self):
00071 
00072         pkg_dir, dist = self.create_dist()
00073         cmd = build_clib(dist)
00074         class FakeCompiler:
00075             def compile(*args, **kw):
00076                 pass
00077             create_static_lib = compile
00078 
00079         cmd.compiler = FakeCompiler()
00080 
00081         # build_libraries is also doing a bit of typoe checking
00082         lib = [('name', {'sources': 'notvalid'})]
00083         self.assertRaises(DistutilsSetupError, cmd.build_libraries, lib)
00084 
00085         lib = [('name', {'sources': list()})]
00086         cmd.build_libraries(lib)
00087 
00088         lib = [('name', {'sources': tuple()})]
00089         cmd.build_libraries(lib)

Here is the call graph for this function:

Definition at line 17 of file test_build_clib.py.

00017 
00018     def test_check_library_dist(self):
00019         pkg_dir, dist = self.create_dist()
00020         cmd = build_clib(dist)
00021 
00022         # 'libraries' option must be a list
00023         self.assertRaises(DistutilsSetupError, cmd.check_library_list, 'foo')
00024 
00025         # each element of 'libraries' must a 2-tuple
00026         self.assertRaises(DistutilsSetupError, cmd.check_library_list,
00027                           ['foo1', 'foo2'])
00028 
00029         # first element of each tuple in 'libraries'
00030         # must be a string (the library name)
00031         self.assertRaises(DistutilsSetupError, cmd.check_library_list,
00032                           [(1, 'foo1'), ('name', 'foo2')])
00033 
00034         # library name may not contain directory separators
00035         self.assertRaises(DistutilsSetupError, cmd.check_library_list,
00036                           [('name', 'foo1'),
00037                            ('another/name', 'foo2')])
00038 
00039         # second element of each tuple must be a dictionary (build info)
00040         self.assertRaises(DistutilsSetupError, cmd.check_library_list,
00041                           [('name', {}),
00042                            ('another', 'foo2')])
00043 
00044         # those work
00045         libs = [('name', {}), ('name', {'ok': 'good'})]
00046         cmd.check_library_list(libs)

Here is the call graph for this function:

Definition at line 90 of file test_build_clib.py.

00090 
00091     def test_finalize_options(self):
00092         pkg_dir, dist = self.create_dist()
00093         cmd = build_clib(dist)
00094 
00095         cmd.include_dirs = 'one-dir'
00096         cmd.finalize_options()
00097         self.assertEqual(cmd.include_dirs, ['one-dir'])
00098 
00099         cmd.include_dirs = None
00100         cmd.finalize_options()
00101         self.assertEqual(cmd.include_dirs, [])
00102 
00103         cmd.distribution.libraries = 'WONTWORK'
00104         self.assertRaises(DistutilsSetupError, cmd.finalize_options)

Here is the call graph for this function:

Definition at line 47 of file test_build_clib.py.

00047 
00048     def test_get_source_files(self):
00049         pkg_dir, dist = self.create_dist()
00050         cmd = build_clib(dist)
00051 
00052         # "in 'libraries' option 'sources' must be present and must be
00053         # a list of source filenames
00054         cmd.libraries = [('name', {})]
00055         self.assertRaises(DistutilsSetupError, cmd.get_source_files)
00056 
00057         cmd.libraries = [('name', {'sources': 1})]
00058         self.assertRaises(DistutilsSetupError, cmd.get_source_files)
00059 
00060         cmd.libraries = [('name', {'sources': ['a', 'b']})]
00061         self.assertEqual(cmd.get_source_files(), ['a', 'b'])
00062 
00063         cmd.libraries = [('name', {'sources': ('a', 'b')})]
00064         self.assertEqual(cmd.get_source_files(), ['a', 'b'])
00065 
00066         cmd.libraries = [('name', {'sources': ('a', 'b')}),
00067                          ('name2', {'sources': ['c', 'd']})]
00068         self.assertEqual(cmd.get_source_files(), ['a', 'b', 'c', 'd'])

Here is the call graph for this function:

Definition at line 105 of file test_build_clib.py.

00105 
00106     def test_run(self):
00107         # can't test on windows
00108         if sys.platform == 'win32':
00109             return
00110 
00111         pkg_dir, dist = self.create_dist()
00112         cmd = build_clib(dist)
00113 
00114         foo_c = os.path.join(pkg_dir, 'foo.c')
00115         self.write_file(foo_c, 'int main(void) { return 1;}\n')
00116         cmd.libraries = [('foo', {'sources': [foo_c]})]
00117 
00118         build_temp = os.path.join(pkg_dir, 'build')
00119         os.mkdir(build_temp)
00120         cmd.build_temp = build_temp
00121         cmd.build_clib = build_temp
00122 
00123         # before we run the command, we want to make sure
00124         # all commands are present on the system
00125         # by creating a compiler and checking its executables
00126         from distutils.ccompiler import new_compiler
00127         from distutils.sysconfig import customize_compiler
00128 
00129         compiler = new_compiler()
00130         customize_compiler(compiler)
00131         for ccmd in compiler.executables.values():
00132             if ccmd is None:
00133                 continue
00134             if find_executable(ccmd[0]) is None:
00135                 return # can't test
00136 
00137         # this should work
00138         cmd.run()
00139 
00140         # let's check the result
00141         self.assertTrue('libfoo.a' in os.listdir(build_temp))

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: