Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
test.test_sysconfig.TestSysConfig Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_get_path_names
def test_get_paths
def test_get_path
def test_get_config_vars
def test_get_platform
def test_get_config_h_filename
def test_get_scheme_names
def test_symlink
def test_user_similar
def test_main
def test_ldshared_value
def test_platform_in_subprocess

Public Attributes

 sys_path
 uname
 name
 platform
 version
 sep
 join
 isabs
 splitdrive
 old_environ

Private Member Functions

def _set_uname
def _get_uname
def _cleanup_testfn

Private Attributes

 _uname
 _config_vars

Detailed Description

Definition at line 23 of file test_sysconfig.py.


Member Function Documentation

Definition at line 80 of file test_sysconfig.py.

00080 
00081     def _cleanup_testfn(self):
00082         path = TESTFN
00083         if os.path.isfile(path):
00084             os.remove(path)
00085         elif os.path.isdir(path):
00086             shutil.rmtree(path)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file test_sysconfig.py.

00077 
00078     def _get_uname(self):
00079         return self._uname

def test.test_sysconfig.TestSysConfig._set_uname (   self,
  uname 
) [private]

Definition at line 74 of file test_sysconfig.py.

00074 
00075     def _set_uname(self, uname):
00076         self._uname = uname

Here is the caller graph for this function:

Make a copy of sys.path

Definition at line 25 of file test_sysconfig.py.

00025 
00026     def setUp(self):
00027         """Make a copy of sys.path"""
00028         super(TestSysConfig, self).setUp()
00029         self.sys_path = sys.path[:]
00030         # patching os.uname
00031         if hasattr(os, 'uname'):
00032             self.uname = os.uname
00033             self._uname = os.uname()
00034         else:
00035             self.uname = None
00036             self._uname = None
00037         os.uname = self._get_uname
00038         # saving the environment
00039         self.name = os.name
00040         self.platform = sys.platform
00041         self.version = sys.version
00042         self.sep = os.sep
00043         self.join = os.path.join
00044         self.isabs = os.path.isabs
00045         self.splitdrive = os.path.splitdrive
00046         self._config_vars = copy(sysconfig._CONFIG_VARS)
00047         self.old_environ = deepcopy(os.environ)

Here is the caller graph for this function:

Restore sys.path

Definition at line 48 of file test_sysconfig.py.

00048 
00049     def tearDown(self):
00050         """Restore sys.path"""
00051         sys.path[:] = self.sys_path
00052         self._cleanup_testfn()
00053         if self.uname is not None:
00054             os.uname = self.uname
00055         else:
00056             del os.uname
00057         os.name = self.name
00058         sys.platform = self.platform
00059         sys.version = self.version
00060         os.sep = self.sep
00061         os.path.join = self.join
00062         os.path.isabs = self.isabs
00063         os.path.splitdrive = self.splitdrive
00064         sysconfig._CONFIG_VARS = copy(self._config_vars)
00065         for key, value in self.old_environ.items():
00066             if os.environ.get(key) != value:
00067                 os.environ[key] = value
00068 
00069         for key in list(os.environ.keys()):
00070             if key not in self.old_environ:
00071                 del os.environ[key]
00072 
00073         super(TestSysConfig, self).tearDown()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 232 of file test_sysconfig.py.

00232 
00233     def test_get_config_h_filename(self):
00234         config_h = sysconfig.get_config_h_filename()
00235         self.assertTrue(os.path.isfile(config_h), config_h)

Here is the call graph for this function:

Definition at line 106 of file test_sysconfig.py.

00106 
00107     def test_get_config_vars(self):
00108         cvars = get_config_vars()
00109         self.assertTrue(isinstance(cvars, dict))
00110         self.assertTrue(cvars)

Here is the call graph for this function:

Definition at line 100 of file test_sysconfig.py.

00100 
00101     def test_get_path(self):
00102         # xxx make real tests here
00103         for scheme in _INSTALL_SCHEMES:
00104             for name in _INSTALL_SCHEMES[scheme]:
00105                 res = get_path(name, scheme)

Here is the call graph for this function:

Definition at line 87 of file test_sysconfig.py.

00087 
00088     def test_get_path_names(self):
00089         self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)

Here is the call graph for this function:

Definition at line 90 of file test_sysconfig.py.

00090 
00091     def test_get_paths(self):
00092         scheme = get_paths()
00093         default_scheme = _get_default_scheme()
00094         wanted = _expand_vars(default_scheme, None)
00095         wanted = list(wanted.items())
00096         wanted.sort()
00097         scheme = list(scheme.items())
00098         scheme.sort()
00099         self.assertEqual(scheme, wanted)

Here is the call graph for this function:

Definition at line 111 of file test_sysconfig.py.

00111 
00112     def test_get_platform(self):
00113         # windows XP, 32bits
00114         os.name = 'nt'
00115         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
00116                        '[MSC v.1310 32 bit (Intel)]')
00117         sys.platform = 'win32'
00118         self.assertEqual(get_platform(), 'win32')
00119 
00120         # windows XP, amd64
00121         os.name = 'nt'
00122         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
00123                        '[MSC v.1310 32 bit (Amd64)]')
00124         sys.platform = 'win32'
00125         self.assertEqual(get_platform(), 'win-amd64')
00126 
00127         # windows XP, itanium
00128         os.name = 'nt'
00129         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
00130                        '[MSC v.1310 32 bit (Itanium)]')
00131         sys.platform = 'win32'
00132         self.assertEqual(get_platform(), 'win-ia64')
00133 
00134         # macbook
00135         os.name = 'posix'
00136         sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
00137                        '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
00138         sys.platform = 'darwin'
00139         self._set_uname(('Darwin', 'macziade', '8.11.1',
00140                    ('Darwin Kernel Version 8.11.1: '
00141                     'Wed Oct 10 18:23:28 PDT 2007; '
00142                     'root:xnu-792.25.20~1/RELEASE_I386'), 'PowerPC'))
00143 
00144 
00145         get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
00146 
00147         get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
00148                                        '-fwrapv -O3 -Wall -Wstrict-prototypes')
00149 
00150         maxint = sys.maxsize
00151         try:
00152             sys.maxsize = 2147483647
00153             self.assertEqual(get_platform(), 'macosx-10.3-ppc')
00154             sys.maxsize = 9223372036854775807
00155             self.assertEqual(get_platform(), 'macosx-10.3-ppc64')
00156         finally:
00157             sys.maxsize = maxint
00158 
00159 
00160         self._set_uname(('Darwin', 'macziade', '8.11.1',
00161                    ('Darwin Kernel Version 8.11.1: '
00162                     'Wed Oct 10 18:23:28 PDT 2007; '
00163                     'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
00164         get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
00165         get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
00166 
00167         get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
00168                                        '-fwrapv -O3 -Wall -Wstrict-prototypes')
00169         maxint = sys.maxsize
00170         try:
00171             sys.maxsize = 2147483647
00172             self.assertEqual(get_platform(), 'macosx-10.3-i386')
00173             sys.maxsize = 9223372036854775807
00174             self.assertEqual(get_platform(), 'macosx-10.3-x86_64')
00175         finally:
00176             sys.maxsize = maxint
00177 
00178         # macbook with fat binaries (fat, universal or fat64)
00179         get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
00180         get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
00181                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00182                                        '-fno-strict-aliasing -fno-common '
00183                                        '-dynamic -DNDEBUG -g -O3')
00184 
00185         self.assertEqual(get_platform(), 'macosx-10.4-fat')
00186 
00187         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot '
00188                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00189                                        '-fno-strict-aliasing -fno-common '
00190                                        '-dynamic -DNDEBUG -g -O3')
00191 
00192         self.assertEqual(get_platform(), 'macosx-10.4-intel')
00193 
00194         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot '
00195                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00196                                        '-fno-strict-aliasing -fno-common '
00197                                        '-dynamic -DNDEBUG -g -O3')
00198         self.assertEqual(get_platform(), 'macosx-10.4-fat3')
00199 
00200         get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot '
00201                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00202                                        '-fno-strict-aliasing -fno-common '
00203                                        '-dynamic -DNDEBUG -g -O3')
00204         self.assertEqual(get_platform(), 'macosx-10.4-universal')
00205 
00206         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot '
00207                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
00208                                        '-fno-strict-aliasing -fno-common '
00209                                        '-dynamic -DNDEBUG -g -O3')
00210 
00211         self.assertEqual(get_platform(), 'macosx-10.4-fat64')
00212 
00213         for arch in ('ppc', 'i386', 'x86_64', 'ppc64'):
00214             get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
00215                                            '/Developer/SDKs/MacOSX10.4u.sdk  '
00216                                            '-fno-strict-aliasing -fno-common '
00217                                            '-dynamic -DNDEBUG -g -O3'%(arch,))
00218 
00219             self.assertEqual(get_platform(), 'macosx-10.4-%s'%(arch,))
00220 
00221         # linux debian sarge
00222         os.name = 'posix'
00223         sys.version = ('2.3.5 (#1, Jul  4 2007, 17:28:59) '
00224                        '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]')
00225         sys.platform = 'linux2'
00226         self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7',
00227                     '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686'))
00228 
00229         self.assertEqual(get_platform(), 'linux-i686')
00230 
00231         # XXX more platforms to tests here

Here is the call graph for this function:

Definition at line 236 of file test_sysconfig.py.

00236 
00237     def test_get_scheme_names(self):
00238         wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
00239                   'posix_home', 'posix_prefix', 'posix_user')
00240         self.assertEqual(get_scheme_names(), wanted)

Here is the call graph for this function:

Definition at line 280 of file test_sysconfig.py.

00280 
00281     def test_ldshared_value(self):
00282         ldflags = sysconfig.get_config_var('LDFLAGS')
00283         ldshared = sysconfig.get_config_var('LDSHARED')
00284 
00285         self.assertIn(ldflags, ldshared)
00286 

Here is the call graph for this function:

Definition at line 273 of file test_sysconfig.py.

00273 
00274     def test_main(self):
00275         # just making sure _main() runs and returns things in the stdout
00276         with captured_stdout() as output:
00277             _main()
00278         self.assertTrue(len(output.getvalue().split('\n')) > 0)

Here is the call graph for this function:

Definition at line 288 of file test_sysconfig.py.

00288 
00289     def test_platform_in_subprocess(self):
00290         my_platform = sysconfig.get_platform()
00291 
00292         # Test without MACOSX_DEPLOYMENT_TARGET in the environment
00293 
00294         env = os.environ.copy()
00295         if 'MACOSX_DEPLOYMENT_TARGET' in env:
00296             del env['MACOSX_DEPLOYMENT_TARGET']
00297 
00298         with open('/dev/null', 'w') as devnull_fp:
00299             p = subprocess.Popen([
00300                     sys.executable, '-c',
00301                     'import sysconfig; print(sysconfig.get_platform())',
00302                 ],
00303                 stdout=subprocess.PIPE,
00304                 stderr=devnull_fp,
00305                 env=env)
00306         test_platform = p.communicate()[0].strip()
00307         test_platform = test_platform.decode('utf-8')
00308         status = p.wait()
00309 
00310         self.assertEqual(status, 0)
00311         self.assertEqual(my_platform, test_platform)
00312 
00313 
00314         # Test with MACOSX_DEPLOYMENT_TARGET in the environment, and
00315         # using a value that is unlikely to be the default one.
00316         env = os.environ.copy()
00317         env['MACOSX_DEPLOYMENT_TARGET'] = '10.1'
00318 
00319         p = subprocess.Popen([
00320                 sys.executable, '-c',
00321                 'import sysconfig; print(sysconfig.get_platform())',
00322             ],
00323             stdout=subprocess.PIPE,
00324             stderr=open('/dev/null'),
00325             env=env)
00326         test_platform = p.communicate()[0].strip()
00327         test_platform = test_platform.decode('utf-8')
00328         status = p.wait()
00329 
00330         self.assertEqual(status, 0)
00331         self.assertEqual(my_platform, test_platform)
00332 

Here is the call graph for this function:

Definition at line 242 of file test_sysconfig.py.

00242 
00243     def test_symlink(self):
00244         # On Windows, the EXE needs to know where pythonXY.dll is at so we have
00245         # to add the directory to the path.
00246         if sys.platform == "win32":
00247             os.environ["Path"] = "{};{}".format(
00248                 os.path.dirname(sys.executable), os.environ["Path"])
00249 
00250         # Issue 7880
00251         def get(python):
00252             cmd = [python, '-c',
00253                    'import sysconfig; print(sysconfig.get_platform())']
00254             p = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=os.environ)
00255             return p.communicate()
00256         real = os.path.realpath(sys.executable)
00257         link = os.path.abspath(TESTFN)
00258         os.symlink(real, link)
00259         try:
00260             self.assertEqual(get(real), get(link))
00261         finally:
00262             unlink(link)

Here is the call graph for this function:

Definition at line 263 of file test_sysconfig.py.

00263 
00264     def test_user_similar(self):
00265         # Issue 8759 : make sure the posix scheme for the users
00266         # is similar to the global posix_prefix one
00267         base = get_config_var('base')
00268         user = get_config_var('userbase')
00269         for name in ('stdlib', 'platstdlib', 'purelib', 'platlib'):
00270             global_path = get_path(name, 'posix_prefix')
00271             user_path = get_path(name, 'posix_user')
00272             self.assertEqual(user_path, global_path.replace(base, user))

Here is the call graph for this function:


Member Data Documentation

Definition at line 45 of file test_sysconfig.py.

Definition at line 32 of file test_sysconfig.py.

Definition at line 43 of file test_sysconfig.py.

Definition at line 42 of file test_sysconfig.py.

Definition at line 38 of file test_sysconfig.py.

Definition at line 46 of file test_sysconfig.py.

Definition at line 39 of file test_sysconfig.py.

Definition at line 41 of file test_sysconfig.py.

Definition at line 44 of file test_sysconfig.py.

Definition at line 28 of file test_sysconfig.py.

Definition at line 31 of file test_sysconfig.py.

Definition at line 40 of file test_sysconfig.py.


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