Back to index

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

List of all members.

Public Member Functions

def setUp
def tearDown
def test_get_platform
def test_convert_path
def test_change_root
def test_check_environ
def test_split_quoted
def test_strtobool
def test_rfc822_escape
def test_dont_write_bytecode

Public Attributes

 name
 platform
 version
 sep
 join
 isabs
 splitdrive
 uname
 old_environ
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _set_uname
def _get_uname

Private Attributes

 _config_vars
 _uname

Detailed Description

Definition at line 17 of file test_util.py.


Member Function Documentation

Definition at line 60 of file test_util.py.

00060 
00061     def _get_uname(self):
00062         return self._uname

def distutils.tests.test_util.UtilTestCase._set_uname (   self,
  uname 
) [private]

Definition at line 57 of file test_util.py.

00057 
00058     def _set_uname(self, uname):
00059         self._uname = uname

Here is the caller graph for this function:

Reimplemented from distutils.tests.support.EnvironGuard.

Definition at line 19 of file test_util.py.

00019 
00020     def setUp(self):
00021         super(UtilTestCase, self).setUp()
00022         # saving the environment
00023         self.name = os.name
00024         self.platform = sys.platform
00025         self.version = sys.version
00026         self.sep = os.sep
00027         self.join = os.path.join
00028         self.isabs = os.path.isabs
00029         self.splitdrive = os.path.splitdrive
00030         self._config_vars = copy(sysconfig._config_vars)
00031 
00032         # patching os.uname
00033         if hasattr(os, 'uname'):
00034             self.uname = os.uname
00035             self._uname = os.uname()
00036         else:
00037             self.uname = None
00038             self._uname = None
00039 
00040         os.uname = self._get_uname

Here is the caller graph for this function:

Reimplemented from distutils.tests.support.EnvironGuard.

Definition at line 41 of file test_util.py.

00041 
00042     def tearDown(self):
00043         # getting back the environment
00044         os.name = self.name
00045         sys.platform = self.platform
00046         sys.version = self.version
00047         os.sep = self.sep
00048         os.path.join = self.join
00049         os.path.isabs = self.isabs
00050         os.path.splitdrive = self.splitdrive
00051         if self.uname is not None:
00052             os.uname = self.uname
00053         else:
00054             del os.uname
00055         sysconfig._config_vars = copy(self._config_vars)
00056         super(UtilTestCase, self).tearDown()

Here is the caller graph for this function:

Definition at line 191 of file test_util.py.

00191 
00192     def test_change_root(self):
00193         # linux/mac
00194         os.name = 'posix'
00195         def _isabs(path):
00196             return path[0] == '/'
00197         os.path.isabs = _isabs
00198         def _join(*path):
00199             return '/'.join(path)
00200         os.path.join = _join
00201 
00202         self.assertEqual(change_root('/root', '/old/its/here'),
00203                          '/root/old/its/here')
00204         self.assertEqual(change_root('/root', 'its/here'),
00205                          '/root/its/here')
00206 
00207         # windows
00208         os.name = 'nt'
00209         def _isabs(path):
00210             return path.startswith('c:\\')
00211         os.path.isabs = _isabs
00212         def _splitdrive(path):
00213             if path.startswith('c:'):
00214                 return ('', path.replace('c:', ''))
00215             return ('', path)
00216         os.path.splitdrive = _splitdrive
00217         def _join(*path):
00218             return '\\'.join(path)
00219         os.path.join = _join
00220 
00221         self.assertEqual(change_root('c:\\root', 'c:\\old\\its\\here'),
00222                          'c:\\root\\old\\its\\here')
00223         self.assertEqual(change_root('c:\\root', 'its\\here'),
00224                          'c:\\root\\its\\here')
00225 
00226         # BugsBunny os (it's a great os)
00227         os.name = 'BugsBunny'
00228         self.assertRaises(DistutilsPlatformError,
00229                           change_root, 'c:\\root', 'its\\here')
00230 
00231         # XXX platforms to be covered: os2, mac

Here is the call graph for this function:

Definition at line 232 of file test_util.py.

00232 
00233     def test_check_environ(self):
00234         util._environ_checked = 0
00235         if 'HOME' in os.environ:
00236             del os.environ['HOME']
00237 
00238         # posix without HOME
00239         if os.name == 'posix':  # this test won't run on windows
00240             check_environ()
00241             import pwd
00242             self.assertEqual(os.environ['HOME'], pwd.getpwuid(os.getuid())[5])
00243         else:
00244             check_environ()
00245 
00246         self.assertEqual(os.environ['PLAT'], get_platform())
00247         self.assertEqual(util._environ_checked, 1)

Here is the call graph for this function:

Definition at line 167 of file test_util.py.

00167 
00168     def test_convert_path(self):
00169         # linux/mac
00170         os.sep = '/'
00171         def _join(path):
00172             return '/'.join(path)
00173         os.path.join = _join
00174 
00175         self.assertEqual(convert_path('/home/to/my/stuff'),
00176                          '/home/to/my/stuff')
00177 
00178         # win
00179         os.sep = '\\'
00180         def _join(*path):
00181             return '\\'.join(path)
00182         os.path.join = _join
00183 
00184         self.assertRaises(ValueError, convert_path, '/home/to/my/stuff')
00185         self.assertRaises(ValueError, convert_path, 'home/to/my/stuff/')
00186 
00187         self.assertEqual(convert_path('home/to/my/stuff'),
00188                          'home\\to\\my\\stuff')
00189         self.assertEqual(convert_path('.'),
00190                          os.curdir)

Here is the call graph for this function:

Definition at line 269 of file test_util.py.

00269 
00270     def test_dont_write_bytecode(self):
00271         # makes sure byte_compile raise a DistutilsError
00272         # if sys.dont_write_bytecode is True
00273         old_dont_write_bytecode = sys.dont_write_bytecode
00274         sys.dont_write_bytecode = True
00275         try:
00276             self.assertRaises(DistutilsByteCompileError, byte_compile, [])
00277         finally:
00278             sys.dont_write_bytecode = old_dont_write_bytecode

Here is the call graph for this function:

Definition at line 63 of file test_util.py.

00063 
00064     def test_get_platform(self):
00065 
00066         # windows XP, 32bits
00067         os.name = 'nt'
00068         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
00069                        '[MSC v.1310 32 bit (Intel)]')
00070         sys.platform = 'win32'
00071         self.assertEqual(get_platform(), 'win32')
00072 
00073         # windows XP, amd64
00074         os.name = 'nt'
00075         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
00076                        '[MSC v.1310 32 bit (Amd64)]')
00077         sys.platform = 'win32'
00078         self.assertEqual(get_platform(), 'win-amd64')
00079 
00080         # windows XP, itanium
00081         os.name = 'nt'
00082         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
00083                        '[MSC v.1310 32 bit (Itanium)]')
00084         sys.platform = 'win32'
00085         self.assertEqual(get_platform(), 'win-ia64')
00086 
00087         # macbook
00088         os.name = 'posix'
00089         sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
00090                        '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
00091         sys.platform = 'darwin'
00092         self._set_uname(('Darwin', 'macziade', '8.11.1',
00093                    ('Darwin Kernel Version 8.11.1: '
00094                     'Wed Oct 10 18:23:28 PDT 2007; '
00095                     'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
00096         get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
00097 
00098         get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
00099                                        '-fwrapv -O3 -Wall -Wstrict-prototypes')
00100 
00101         cursize = sys.maxsize
00102         sys.maxsize = (2 ** 31)-1
00103         try:
00104             self.assertEqual(get_platform(), 'macosx-10.3-i386')
00105         finally:
00106             sys.maxsize = cursize
00107 
00108         # macbook with fat binaries (fat, universal or fat64)
00109         get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
00110         get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
00111                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00112                                        '-fno-strict-aliasing -fno-common '
00113                                        '-dynamic -DNDEBUG -g -O3')
00114 
00115         self.assertEqual(get_platform(), 'macosx-10.4-fat')
00116 
00117         os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.1'
00118         self.assertEqual(get_platform(), 'macosx-10.4-fat')
00119 
00120 
00121         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot '
00122                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00123                                        '-fno-strict-aliasing -fno-common '
00124                                        '-dynamic -DNDEBUG -g -O3')
00125 
00126         self.assertEqual(get_platform(), 'macosx-10.4-intel')
00127 
00128         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot '
00129                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00130                                        '-fno-strict-aliasing -fno-common '
00131                                        '-dynamic -DNDEBUG -g -O3')
00132         self.assertEqual(get_platform(), 'macosx-10.4-fat3')
00133 
00134         get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot '
00135                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00136                                        '-fno-strict-aliasing -fno-common '
00137                                        '-dynamic -DNDEBUG -g -O3')
00138         self.assertEqual(get_platform(), 'macosx-10.4-universal')
00139 
00140         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot '
00141                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00142                                        '-fno-strict-aliasing -fno-common '
00143                                        '-dynamic -DNDEBUG -g -O3')
00144 
00145         self.assertEqual(get_platform(), 'macosx-10.4-fat64')
00146 
00147         for arch in ('ppc', 'i386', 'x86_64', 'ppc64'):
00148             get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
00149                                            '/Developer/SDKs/MacOSX10.4u.sdk  '
00150                                            '-fno-strict-aliasing -fno-common '
00151                                            '-dynamic -DNDEBUG -g -O3'%(arch,))
00152 
00153             self.assertEqual(get_platform(), 'macosx-10.4-%s'%(arch,))
00154 
00155 
00156         # linux debian sarge
00157         os.name = 'posix'
00158         sys.version = ('2.3.5 (#1, Jul  4 2007, 17:28:59) '
00159                        '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]')
00160         sys.platform = 'linux2'
00161         self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7',
00162                     '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686'))
00163 
00164         self.assertEqual(get_platform(), 'linux-i686')
00165 
00166         # XXX more platforms to tests here

Here is the call graph for this function:

Definition at line 262 of file test_util.py.

00262 
00263     def test_rfc822_escape(self):
00264         header = 'I am a\npoor\nlonesome\nheader\n'
00265         res = rfc822_escape(header)
00266         wanted = ('I am a%(8s)spoor%(8s)slonesome%(8s)s'
00267                   'header%(8s)s') % {'8s': '\n'+8*' '}
00268         self.assertEqual(res, wanted)

Here is the call graph for this function:

Definition at line 248 of file test_util.py.

00248 
00249     def test_split_quoted(self):
00250         self.assertEqual(split_quoted('""one"" "two" \'three\' \\four'),
00251                          ['one', 'two', 'three', 'four'])

Here is the call graph for this function:

Definition at line 252 of file test_util.py.

00252 
00253     def test_strtobool(self):
00254         yes = ('y', 'Y', 'yes', 'True', 't', 'true', 'True', 'On', 'on', '1')
00255         no = ('n', 'no', 'f', 'false', 'off', '0', 'Off', 'No', 'N')
00256 
00257         for y in yes:
00258             self.assertTrue(strtobool(y))
00259 
00260         for n in no:
00261             self.assertTrue(not strtobool(n))

Here is the call graph for this function:


Member Data Documentation

Definition at line 29 of file test_util.py.

Definition at line 34 of file test_util.py.

Definition at line 27 of file test_util.py.

Definition at line 26 of file test_util.py.

Definition at line 22 of file test_util.py.

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

Definition at line 23 of file test_util.py.

Definition at line 25 of file test_util.py.

Definition at line 28 of file test_util.py.

Definition at line 33 of file test_util.py.

Definition at line 24 of file test_util.py.


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