summaryrefslogtreecommitdiff
path: root/src/python/stdlib/distutils/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/stdlib/distutils/tests')
-rwxr-xr-xsrc/python/stdlib/distutils/tests/Setup.sample67
-rw-r--r--src/python/stdlib/distutils/tests/__init__.py35
-rw-r--r--src/python/stdlib/distutils/tests/setuptools_build_ext.py287
-rw-r--r--src/python/stdlib/distutils/tests/setuptools_extension.py51
-rw-r--r--src/python/stdlib/distutils/tests/support.py133
-rw-r--r--src/python/stdlib/distutils/tests/test_archive_util.py284
-rw-r--r--src/python/stdlib/distutils/tests/test_bdist.py45
-rw-r--r--src/python/stdlib/distutils/tests/test_bdist_dumb.py105
-rw-r--r--src/python/stdlib/distutils/tests/test_bdist_msi.py25
-rw-r--r--src/python/stdlib/distutils/tests/test_bdist_rpm.py127
-rw-r--r--src/python/stdlib/distutils/tests/test_bdist_wininst.py32
-rw-r--r--src/python/stdlib/distutils/tests/test_build.py54
-rw-r--r--src/python/stdlib/distutils/tests/test_build_clib.py143
-rw-r--r--src/python/stdlib/distutils/tests/test_build_ext.py437
-rw-r--r--src/python/stdlib/distutils/tests/test_build_py.py126
-rw-r--r--src/python/stdlib/distutils/tests/test_build_scripts.py111
-rw-r--r--src/python/stdlib/distutils/tests/test_ccompiler.py81
-rw-r--r--src/python/stdlib/distutils/tests/test_check.py98
-rw-r--r--src/python/stdlib/distutils/tests/test_clean.py50
-rw-r--r--src/python/stdlib/distutils/tests/test_cmd.py127
-rw-r--r--src/python/stdlib/distutils/tests/test_config.py122
-rw-r--r--src/python/stdlib/distutils/tests/test_config_cmd.py89
-rw-r--r--src/python/stdlib/distutils/tests/test_core.py108
-rw-r--r--src/python/stdlib/distutils/tests/test_dep_util.py80
-rw-r--r--src/python/stdlib/distutils/tests/test_dir_util.py115
-rw-r--r--src/python/stdlib/distutils/tests/test_dist.py436
-rw-r--r--src/python/stdlib/distutils/tests/test_file_util.py80
-rw-r--r--src/python/stdlib/distutils/tests/test_filelist.py85
-rw-r--r--src/python/stdlib/distutils/tests/test_install.py55
-rw-r--r--src/python/stdlib/distutils/tests/test_install_data.py76
-rw-r--r--src/python/stdlib/distutils/tests/test_install_headers.py40
-rw-r--r--src/python/stdlib/distutils/tests/test_install_lib.py106
-rw-r--r--src/python/stdlib/distutils/tests/test_install_scripts.py81
-rw-r--r--src/python/stdlib/distutils/tests/test_msvc9compiler.py140
-rw-r--r--src/python/stdlib/distutils/tests/test_register.py261
-rw-r--r--src/python/stdlib/distutils/tests/test_sdist.py429
-rw-r--r--src/python/stdlib/distutils/tests/test_spawn.py60
-rw-r--r--src/python/stdlib/distutils/tests/test_sysconfig.py82
-rw-r--r--src/python/stdlib/distutils/tests/test_text_file.py106
-rw-r--r--src/python/stdlib/distutils/tests/test_unixccompiler.py129
-rw-r--r--src/python/stdlib/distutils/tests/test_upload.py132
-rw-r--r--src/python/stdlib/distutils/tests/test_util.py24
-rw-r--r--src/python/stdlib/distutils/tests/test_version.py70
-rw-r--r--src/python/stdlib/distutils/tests/test_versionpredicate.py9
44 files changed, 0 insertions, 5333 deletions
diff --git a/src/python/stdlib/distutils/tests/Setup.sample b/src/python/stdlib/distutils/tests/Setup.sample
deleted file mode 100755
index 36c4290..0000000
--- a/src/python/stdlib/distutils/tests/Setup.sample
+++ /dev/null
@@ -1,67 +0,0 @@
-# Setup file from the pygame project
-
-#--StartConfig
-SDL = -I/usr/include/SDL -D_REENTRANT -lSDL
-FONT = -lSDL_ttf
-IMAGE = -lSDL_image
-MIXER = -lSDL_mixer
-SMPEG = -lsmpeg
-PNG = -lpng
-JPEG = -ljpeg
-SCRAP = -lX11
-PORTMIDI = -lportmidi
-PORTTIME = -lporttime
-#--EndConfig
-
-#DEBUG = -C-W -C-Wall
-DEBUG =
-
-#the following modules are optional. you will want to compile
-#everything you can, but you can ignore ones you don't have
-#dependencies for, just comment them out
-
-imageext src/imageext.c $(SDL) $(IMAGE) $(PNG) $(JPEG) $(DEBUG)
-font src/font.c $(SDL) $(FONT) $(DEBUG)
-mixer src/mixer.c $(SDL) $(MIXER) $(DEBUG)
-mixer_music src/music.c $(SDL) $(MIXER) $(DEBUG)
-_numericsurfarray src/_numericsurfarray.c $(SDL) $(DEBUG)
-_numericsndarray src/_numericsndarray.c $(SDL) $(MIXER) $(DEBUG)
-movie src/movie.c $(SDL) $(SMPEG) $(DEBUG)
-scrap src/scrap.c $(SDL) $(SCRAP) $(DEBUG)
-_camera src/_camera.c src/camera_v4l2.c src/camera_v4l.c $(SDL) $(DEBUG)
-pypm src/pypm.c $(SDL) $(PORTMIDI) $(PORTTIME) $(DEBUG)
-
-GFX = src/SDL_gfx/SDL_gfxPrimitives.c
-#GFX = src/SDL_gfx/SDL_gfxBlitFunc.c src/SDL_gfx/SDL_gfxPrimitives.c
-gfxdraw src/gfxdraw.c $(SDL) $(GFX) $(DEBUG)
-
-
-
-#these modules are required for pygame to run. they only require
-#SDL as a dependency. these should not be altered
-
-base src/base.c $(SDL) $(DEBUG)
-cdrom src/cdrom.c $(SDL) $(DEBUG)
-color src/color.c $(SDL) $(DEBUG)
-constants src/constants.c $(SDL) $(DEBUG)
-display src/display.c $(SDL) $(DEBUG)
-event src/event.c $(SDL) $(DEBUG)
-fastevent src/fastevent.c src/fastevents.c $(SDL) $(DEBUG)
-key src/key.c $(SDL) $(DEBUG)
-mouse src/mouse.c $(SDL) $(DEBUG)
-rect src/rect.c $(SDL) $(DEBUG)
-rwobject src/rwobject.c $(SDL) $(DEBUG)
-surface src/surface.c src/alphablit.c src/surface_fill.c $(SDL) $(DEBUG)
-surflock src/surflock.c $(SDL) $(DEBUG)
-time src/time.c $(SDL) $(DEBUG)
-joystick src/joystick.c $(SDL) $(DEBUG)
-draw src/draw.c $(SDL) $(DEBUG)
-image src/image.c $(SDL) $(DEBUG)
-overlay src/overlay.c $(SDL) $(DEBUG)
-transform src/transform.c src/rotozoom.c src/scale2x.c src/scale_mmx.c $(SDL) $(DEBUG)
-mask src/mask.c src/bitmask.c $(SDL) $(DEBUG)
-bufferproxy src/bufferproxy.c $(SDL) $(DEBUG)
-pixelarray src/pixelarray.c $(SDL) $(DEBUG)
-_arraysurfarray src/_arraysurfarray.c $(SDL) $(DEBUG)
-
-
diff --git a/src/python/stdlib/distutils/tests/__init__.py b/src/python/stdlib/distutils/tests/__init__.py
deleted file mode 100644
index 7bdb912..0000000
--- a/src/python/stdlib/distutils/tests/__init__.py
+++ /dev/null
@@ -1,35 +0,0 @@
-"""Test suite for distutils.
-
-This test suite consists of a collection of test modules in the
-distutils.tests package. Each test module has a name starting with
-'test' and contains a function test_suite(). The function is expected
-to return an initialized unittest.TestSuite instance.
-
-Tests for the command classes in the distutils.command package are
-included in distutils.tests as well, instead of using a separate
-distutils.command.tests package, since command identification is done
-by import rather than matching pre-defined names.
-
-"""
-
-import os
-import sys
-import unittest
-
-
-here = os.path.dirname(__file__)
-
-
-def test_suite():
- suite = unittest.TestSuite()
- for fn in os.listdir(here):
- if fn.startswith("test") and fn.endswith(".py"):
- modname = "distutils.tests." + fn[:-3]
- __import__(modname)
- module = sys.modules[modname]
- suite.addTest(module.test_suite())
- return suite
-
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/setuptools_build_ext.py b/src/python/stdlib/distutils/tests/setuptools_build_ext.py
deleted file mode 100644
index 21fa9e8..0000000
--- a/src/python/stdlib/distutils/tests/setuptools_build_ext.py
+++ /dev/null
@@ -1,287 +0,0 @@
-from distutils.command.build_ext import build_ext as _du_build_ext
-try:
- # Attempt to use Pyrex for building extensions, if available
- from Pyrex.Distutils.build_ext import build_ext as _build_ext
-except ImportError:
- _build_ext = _du_build_ext
-
-import os, sys
-from distutils.file_util import copy_file
-
-from distutils.tests.setuptools_extension import Library
-
-from distutils.ccompiler import new_compiler
-from distutils.sysconfig import customize_compiler, get_config_var
-get_config_var("LDSHARED") # make sure _config_vars is initialized
-from distutils.sysconfig import _config_vars
-from distutils import log
-from distutils.errors import *
-
-have_rtld = False
-use_stubs = False
-libtype = 'shared'
-
-if sys.platform == "darwin":
- use_stubs = True
-elif os.name != 'nt':
- try:
- from dl import RTLD_NOW
- have_rtld = True
- use_stubs = True
- except ImportError:
- pass
-
-def if_dl(s):
- if have_rtld:
- return s
- return ''
-
-
-
-
-
-
-class build_ext(_build_ext):
- def run(self):
- """Build extensions in build directory, then copy if --inplace"""
- old_inplace, self.inplace = self.inplace, 0
- _build_ext.run(self)
- self.inplace = old_inplace
- if old_inplace:
- self.copy_extensions_to_source()
-
- def copy_extensions_to_source(self):
- build_py = self.get_finalized_command('build_py')
- for ext in self.extensions:
- fullname = self.get_ext_fullname(ext.name)
- filename = self.get_ext_filename(fullname)
- modpath = fullname.split('.')
- package = '.'.join(modpath[:-1])
- package_dir = build_py.get_package_dir(package)
- dest_filename = os.path.join(package_dir,os.path.basename(filename))
- src_filename = os.path.join(self.build_lib,filename)
-
- # Always copy, even if source is older than destination, to ensure
- # that the right extensions for the current Python/platform are
- # used.
- copy_file(
- src_filename, dest_filename, verbose=self.verbose,
- dry_run=self.dry_run
- )
- if ext._needs_stub:
- self.write_stub(package_dir or os.curdir, ext, True)
-
-
- if _build_ext is not _du_build_ext and not hasattr(_build_ext,'pyrex_sources'):
- # Workaround for problems using some Pyrex versions w/SWIG and/or 2.4
- def swig_sources(self, sources, *otherargs):
- # first do any Pyrex processing
- sources = _build_ext.swig_sources(self, sources) or sources
- # Then do any actual SWIG stuff on the remainder
- return _du_build_ext.swig_sources(self, sources, *otherargs)
-
-
-
- def get_ext_filename(self, fullname):
- filename = _build_ext.get_ext_filename(self,fullname)
- ext = self.ext_map[fullname]
- if isinstance(ext,Library):
- fn, ext = os.path.splitext(filename)
- return self.shlib_compiler.library_filename(fn,libtype)
- elif use_stubs and ext._links_to_dynamic:
- d,fn = os.path.split(filename)
- return os.path.join(d,'dl-'+fn)
- else:
- return filename
-
- def initialize_options(self):
- _build_ext.initialize_options(self)
- self.shlib_compiler = None
- self.shlibs = []
- self.ext_map = {}
-
- def finalize_options(self):
- _build_ext.finalize_options(self)
- self.extensions = self.extensions or []
- self.check_extensions_list(self.extensions)
- self.shlibs = [ext for ext in self.extensions
- if isinstance(ext,Library)]
- if self.shlibs:
- self.setup_shlib_compiler()
- for ext in self.extensions:
- ext._full_name = self.get_ext_fullname(ext.name)
- for ext in self.extensions:
- fullname = ext._full_name
- self.ext_map[fullname] = ext
- ltd = ext._links_to_dynamic = \
- self.shlibs and self.links_to_dynamic(ext) or False
- ext._needs_stub = ltd and use_stubs and not isinstance(ext,Library)
- filename = ext._file_name = self.get_ext_filename(fullname)
- libdir = os.path.dirname(os.path.join(self.build_lib,filename))
- if ltd and libdir not in ext.library_dirs:
- ext.library_dirs.append(libdir)
- if ltd and use_stubs and os.curdir not in ext.runtime_library_dirs:
- ext.runtime_library_dirs.append(os.curdir)
-
- def setup_shlib_compiler(self):
- compiler = self.shlib_compiler = new_compiler(
- compiler=self.compiler, dry_run=self.dry_run, force=self.force
- )
- if sys.platform == "darwin":
- tmp = _config_vars.copy()
- try:
- # XXX Help! I don't have any idea whether these are right...
- _config_vars['LDSHARED'] = "gcc -Wl,-x -dynamiclib -undefined dynamic_lookup"
- _config_vars['CCSHARED'] = " -dynamiclib"
- _config_vars['SO'] = ".dylib"
- customize_compiler(compiler)
- finally:
- _config_vars.clear()
- _config_vars.update(tmp)
- else:
- customize_compiler(compiler)
-
- if self.include_dirs is not None:
- compiler.set_include_dirs(self.include_dirs)
- if self.define is not None:
- # 'define' option is a list of (name,value) tuples
- for (name,value) in self.define:
- compiler.define_macro(name, value)
- if self.undef is not None:
- for macro in self.undef:
- compiler.undefine_macro(macro)
- if self.libraries is not None:
- compiler.set_libraries(self.libraries)
- if self.library_dirs is not None:
- compiler.set_library_dirs(self.library_dirs)
- if self.rpath is not None:
- compiler.set_runtime_library_dirs(self.rpath)
- if self.link_objects is not None:
- compiler.set_link_objects(self.link_objects)
-
- # hack so distutils' build_extension() builds a library instead
- compiler.link_shared_object = link_shared_object.__get__(compiler)
-
-
-
- def get_export_symbols(self, ext):
- if isinstance(ext,Library):
- return ext.export_symbols
- return _build_ext.get_export_symbols(self,ext)
-
- def build_extension(self, ext):
- _compiler = self.compiler
- try:
- if isinstance(ext,Library):
- self.compiler = self.shlib_compiler
- _build_ext.build_extension(self,ext)
- if ext._needs_stub:
- self.write_stub(
- self.get_finalized_command('build_py').build_lib, ext
- )
- finally:
- self.compiler = _compiler
-
- def links_to_dynamic(self, ext):
- """Return true if 'ext' links to a dynamic lib in the same package"""
- # XXX this should check to ensure the lib is actually being built
- # XXX as dynamic, and not just using a locally-found version or a
- # XXX static-compiled version
- libnames = dict.fromkeys([lib._full_name for lib in self.shlibs])
- pkg = '.'.join(ext._full_name.split('.')[:-1]+[''])
- for libname in ext.libraries:
- if pkg+libname in libnames: return True
- return False
-
- def get_outputs(self):
- outputs = _build_ext.get_outputs(self)
- optimize = self.get_finalized_command('build_py').optimize
- for ext in self.extensions:
- if ext._needs_stub:
- base = os.path.join(self.build_lib, *ext._full_name.split('.'))
- outputs.append(base+'.py')
- outputs.append(base+'.pyc')
- if optimize:
- outputs.append(base+'.pyo')
- return outputs
-
- def write_stub(self, output_dir, ext, compile=False):
- log.info("writing stub loader for %s to %s",ext._full_name, output_dir)
- stub_file = os.path.join(output_dir, *ext._full_name.split('.'))+'.py'
- if compile and os.path.exists(stub_file):
- raise DistutilsError(stub_file+" already exists! Please delete.")
- if not self.dry_run:
- f = open(stub_file,'w')
- f.write('\n'.join([
- "def __bootstrap__():",
- " global __bootstrap__, __file__, __loader__",
- " import sys, os, pkg_resources, imp"+if_dl(", dl"),
- " __file__ = pkg_resources.resource_filename(__name__,%r)"
- % os.path.basename(ext._file_name),
- " del __bootstrap__",
- " if '__loader__' in globals():",
- " del __loader__",
- if_dl(" old_flags = sys.getdlopenflags()"),
- " old_dir = os.getcwd()",
- " try:",
- " os.chdir(os.path.dirname(__file__))",
- if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"),
- " imp.load_dynamic(__name__,__file__)",
- " finally:",
- if_dl(" sys.setdlopenflags(old_flags)"),
- " os.chdir(old_dir)",
- "__bootstrap__()",
- "" # terminal \n
- ]))
- f.close()
- if compile:
- from distutils.util import byte_compile
- byte_compile([stub_file], optimize=0,
- force=True, dry_run=self.dry_run)
- optimize = self.get_finalized_command('install_lib').optimize
- if optimize > 0:
- byte_compile([stub_file], optimize=optimize,
- force=True, dry_run=self.dry_run)
- if os.path.exists(stub_file) and not self.dry_run:
- os.unlink(stub_file)
-
-
-if use_stubs or os.name=='nt':
- # Build shared libraries
- #
- def link_shared_object(self, objects, output_libname, output_dir=None,
- libraries=None, library_dirs=None, runtime_library_dirs=None,
- export_symbols=None, debug=0, extra_preargs=None,
- extra_postargs=None, build_temp=None, target_lang=None
- ): self.link(
- self.SHARED_LIBRARY, objects, output_libname,
- output_dir, libraries, library_dirs, runtime_library_dirs,
- export_symbols, debug, extra_preargs, extra_postargs,
- build_temp, target_lang
- )
-else:
- # Build static libraries everywhere else
- libtype = 'static'
-
- def link_shared_object(self, objects, output_libname, output_dir=None,
- libraries=None, library_dirs=None, runtime_library_dirs=None,
- export_symbols=None, debug=0, extra_preargs=None,
- extra_postargs=None, build_temp=None, target_lang=None
- ):
- # XXX we need to either disallow these attrs on Library instances,
- # or warn/abort here if set, or something...
- #libraries=None, library_dirs=None, runtime_library_dirs=None,
- #export_symbols=None, extra_preargs=None, extra_postargs=None,
- #build_temp=None
-
- assert output_dir is None # distutils build_ext doesn't pass this
- output_dir,filename = os.path.split(output_libname)
- basename, ext = os.path.splitext(filename)
- if self.library_filename("x").startswith('lib'):
- # strip 'lib' prefix; this is kludgy if some platform uses
- # a different prefix
- basename = basename[3:]
-
- self.create_static_lib(
- objects, basename, output_dir, debug, target_lang
- )
diff --git a/src/python/stdlib/distutils/tests/setuptools_extension.py b/src/python/stdlib/distutils/tests/setuptools_extension.py
deleted file mode 100644
index ec6b690..0000000
--- a/src/python/stdlib/distutils/tests/setuptools_extension.py
+++ /dev/null
@@ -1,51 +0,0 @@
-from distutils.core import Extension as _Extension
-from distutils.core import Distribution as _Distribution
-
-def _get_unpatched(cls):
- """Protect against re-patching the distutils if reloaded
-
- Also ensures that no other distutils extension monkeypatched the distutils
- first.
- """
- while cls.__module__.startswith('setuptools'):
- cls, = cls.__bases__
- if not cls.__module__.startswith('distutils'):
- raise AssertionError(
- "distutils has already been patched by %r" % cls
- )
- return cls
-
-_Distribution = _get_unpatched(_Distribution)
-_Extension = _get_unpatched(_Extension)
-
-try:
- from Pyrex.Distutils.build_ext import build_ext
-except ImportError:
- have_pyrex = False
-else:
- have_pyrex = True
-
-
-class Extension(_Extension):
- """Extension that uses '.c' files in place of '.pyx' files"""
-
- if not have_pyrex:
- # convert .pyx extensions to .c
- def __init__(self,*args,**kw):
- _Extension.__init__(self,*args,**kw)
- sources = []
- for s in self.sources:
- if s.endswith('.pyx'):
- sources.append(s[:-3]+'c')
- else:
- sources.append(s)
- self.sources = sources
-
-class Library(Extension):
- """Just like a regular Extension, but built as a library instead"""
-
-import sys, distutils.core, distutils.extension
-distutils.core.Extension = Extension
-distutils.extension.Extension = Extension
-if 'distutils.command.build_ext' in sys.modules:
- sys.modules['distutils.command.build_ext'].Extension = Extension
diff --git a/src/python/stdlib/distutils/tests/support.py b/src/python/stdlib/distutils/tests/support.py
deleted file mode 100644
index 783318e..0000000
--- a/src/python/stdlib/distutils/tests/support.py
+++ /dev/null
@@ -1,133 +0,0 @@
-"""Support code for distutils test cases."""
-import os
-import shutil
-import tempfile
-from copy import deepcopy
-import warnings
-
-from distutils import log
-from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
-from distutils.core import Distribution
-
-def capture_warnings(func):
- def _capture_warnings(*args, **kw):
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
- return func(*args, **kw)
- return _capture_warnings
-
-class LoggingSilencer(object):
-
- def setUp(self):
- super(LoggingSilencer, self).setUp()
- self.threshold = log.set_threshold(log.FATAL)
- # catching warnings
- # when log will be replaced by logging
- # we won't need such monkey-patch anymore
- self._old_log = log.Log._log
- log.Log._log = self._log
- self.logs = []
-
- def tearDown(self):
- log.set_threshold(self.threshold)
- log.Log._log = self._old_log
- super(LoggingSilencer, self).tearDown()
-
- def _log(self, level, msg, args):
- if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
- raise ValueError('%s wrong log level' % str(level))
- self.logs.append((level, msg, args))
-
- def get_logs(self, *levels):
- def _format(msg, args):
- if len(args) == 0:
- return msg
- return msg % args
- return [_format(msg, args) for level, msg, args
- in self.logs if level in levels]
-
- def clear_logs(self):
- self.logs = []
-
-class TempdirManager(object):
- """Mix-in class that handles temporary directories for test cases.
-
- This is intended to be used with unittest.TestCase.
- """
-
- def setUp(self):
- super(TempdirManager, self).setUp()
- self.tempdirs = []
-
- def tearDown(self):
- super(TempdirManager, self).tearDown()
- while self.tempdirs:
- d = self.tempdirs.pop()
- shutil.rmtree(d, os.name in ('nt', 'cygwin'))
-
- def mkdtemp(self):
- """Create a temporary directory that will be cleaned up.
-
- Returns the path of the directory.
- """
- d = tempfile.mkdtemp()
- self.tempdirs.append(d)
- return d
-
- def write_file(self, path, content='xxx'):
- """Writes a file in the given path.
-
-
- path can be a string or a sequence.
- """
- if isinstance(path, (list, tuple)):
- path = os.path.join(*path)
- f = open(path, 'w')
- try:
- f.write(content)
- finally:
- f.close()
-
- def create_dist(self, pkg_name='foo', **kw):
- """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.
- """
- tmp_dir = self.mkdtemp()
- pkg_dir = os.path.join(tmp_dir, pkg_name)
- os.mkdir(pkg_dir)
- dist = Distribution(attrs=kw)
-
- return pkg_dir, dist
-
-class DummyCommand:
- """Class to store options for retrieval via set_undefined_options()."""
-
- def __init__(self, **kwargs):
- for kw, val in kwargs.items():
- setattr(self, kw, val)
-
- def ensure_finalized(self):
- pass
-
-class EnvironGuard(object):
-
- def setUp(self):
- super(EnvironGuard, self).setUp()
- self.old_environ = deepcopy(os.environ)
-
- def tearDown(self):
- for key, value in self.old_environ.items():
- if os.environ.get(key) != value:
- os.environ[key] = value
-
- for key in os.environ.keys():
- if key not in self.old_environ:
- del os.environ[key]
-
- super(EnvironGuard, self).tearDown()
diff --git a/src/python/stdlib/distutils/tests/test_archive_util.py b/src/python/stdlib/distutils/tests/test_archive_util.py
deleted file mode 100644
index 829d644..0000000
--- a/src/python/stdlib/distutils/tests/test_archive_util.py
+++ /dev/null
@@ -1,284 +0,0 @@
-"""Tests for distutils.archive_util."""
-__revision__ = "$Id: test_archive_util.py 86637 2010-11-21 13:34:58Z ezio.melotti $"
-
-import unittest
-import os
-import tarfile
-from os.path import splitdrive
-import warnings
-
-from distutils.archive_util import (check_archive_formats, make_tarball,
- make_zipfile, make_archive,
- ARCHIVE_FORMATS)
-from distutils.spawn import find_executable, spawn
-from distutils.tests import support
-from test.test_support import check_warnings
-
-try:
- import grp
- import pwd
- UID_GID_SUPPORT = True
-except ImportError:
- UID_GID_SUPPORT = False
-
-try:
- import zipfile
- ZIP_SUPPORT = True
-except ImportError:
- ZIP_SUPPORT = find_executable('zip')
-
-# some tests will fail if zlib is not available
-try:
- import zlib
-except ImportError:
- zlib = None
-
-
-class ArchiveUtilTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- @unittest.skipUnless(zlib, "requires zlib")
- def test_make_tarball(self):
- # creating something to tar
- tmpdir = self.mkdtemp()
- self.write_file([tmpdir, 'file1'], 'xxx')
- self.write_file([tmpdir, 'file2'], 'xxx')
- os.mkdir(os.path.join(tmpdir, 'sub'))
- self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
-
- tmpdir2 = self.mkdtemp()
- unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
- "source and target should be on same drive")
-
- base_name = os.path.join(tmpdir2, 'archive')
-
- # working with relative paths to avoid tar warnings
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(splitdrive(base_name)[1], '.')
- finally:
- os.chdir(old_dir)
-
- # check if the compressed tarball was created
- tarball = base_name + '.tar.gz'
- self.assertTrue(os.path.exists(tarball))
-
- # trying an uncompressed one
- base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(splitdrive(base_name)[1], '.', compress=None)
- finally:
- os.chdir(old_dir)
- tarball = base_name + '.tar'
- self.assertTrue(os.path.exists(tarball))
-
- def _tarinfo(self, path):
- tar = tarfile.open(path)
- try:
- names = tar.getnames()
- names.sort()
- return tuple(names)
- finally:
- tar.close()
-
- def _create_files(self):
- # creating something to tar
- tmpdir = self.mkdtemp()
- dist = os.path.join(tmpdir, 'dist')
- os.mkdir(dist)
- self.write_file([dist, 'file1'], 'xxx')
- self.write_file([dist, 'file2'], 'xxx')
- os.mkdir(os.path.join(dist, 'sub'))
- self.write_file([dist, 'sub', 'file3'], 'xxx')
- os.mkdir(os.path.join(dist, 'sub2'))
- tmpdir2 = self.mkdtemp()
- base_name = os.path.join(tmpdir2, 'archive')
- return tmpdir, tmpdir2, base_name
-
- @unittest.skipUnless(zlib, "Requires zlib")
- @unittest.skipUnless(find_executable('tar') and find_executable('gzip'),
- 'Need the tar command to run')
- def test_tarfile_vs_tar(self):
- tmpdir, tmpdir2, base_name = self._create_files()
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(base_name, 'dist')
- finally:
- os.chdir(old_dir)
-
- # check if the compressed tarball was created
- tarball = base_name + '.tar.gz'
- self.assertTrue(os.path.exists(tarball))
-
- # now create another tarball using `tar`
- tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
- tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
- gzip_cmd = ['gzip', '-f9', 'archive2.tar']
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- spawn(tar_cmd)
- spawn(gzip_cmd)
- finally:
- os.chdir(old_dir)
-
- self.assertTrue(os.path.exists(tarball2))
- # let's compare both tarballs
- self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
-
- # trying an uncompressed one
- base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(base_name, 'dist', compress=None)
- finally:
- os.chdir(old_dir)
- tarball = base_name + '.tar'
- self.assertTrue(os.path.exists(tarball))
-
- # now for a dry_run
- base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- make_tarball(base_name, 'dist', compress=None, dry_run=True)
- finally:
- os.chdir(old_dir)
- tarball = base_name + '.tar'
- self.assertTrue(os.path.exists(tarball))
-
- @unittest.skipUnless(find_executable('compress'),
- 'The compress program is required')
- def test_compress_deprecated(self):
- tmpdir, tmpdir2, base_name = self._create_files()
-
- # using compress and testing the PendingDeprecationWarning
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- with check_warnings() as w:
- warnings.simplefilter("always")
- make_tarball(base_name, 'dist', compress='compress')
- finally:
- os.chdir(old_dir)
- tarball = base_name + '.tar.Z'
- self.assertTrue(os.path.exists(tarball))
- self.assertEqual(len(w.warnings), 1)
-
- # same test with dry_run
- os.remove(tarball)
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
- with check_warnings() as w:
- warnings.simplefilter("always")
- make_tarball(base_name, 'dist', compress='compress',
- dry_run=True)
- finally:
- os.chdir(old_dir)
- self.assertTrue(not os.path.exists(tarball))
- self.assertEqual(len(w.warnings), 1)
-
- @unittest.skipUnless(zlib, "Requires zlib")
- @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
- def test_make_zipfile(self):
- # creating something to tar
- tmpdir = self.mkdtemp()
- self.write_file([tmpdir, 'file1'], 'xxx')
- self.write_file([tmpdir, 'file2'], 'xxx')
-
- tmpdir2 = self.mkdtemp()
- base_name = os.path.join(tmpdir2, 'archive')
- make_zipfile(base_name, tmpdir)
-
- # check if the compressed tarball was created
- tarball = base_name + '.zip'
-
- def test_check_archive_formats(self):
- self.assertEqual(check_archive_formats(['gztar', 'xxx', 'zip']),
- 'xxx')
- self.assertEqual(check_archive_formats(['gztar', 'zip']), None)
-
- def test_make_archive(self):
- tmpdir = self.mkdtemp()
- base_name = os.path.join(tmpdir, 'archive')
- self.assertRaises(ValueError, make_archive, base_name, 'xxx')
-
- @unittest.skipUnless(zlib, "Requires zlib")
- def test_make_archive_owner_group(self):
- # testing make_archive with owner and group, with various combinations
- # this works even if there's not gid/uid support
- if UID_GID_SUPPORT:
- group = grp.getgrgid(0)[0]
- owner = pwd.getpwuid(0)[0]
- else:
- group = owner = 'root'
-
- base_dir, root_dir, base_name = self._create_files()
- base_name = os.path.join(self.mkdtemp() , 'archive')
- res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
- group=group)
- self.assertTrue(os.path.exists(res))
-
- res = make_archive(base_name, 'zip', root_dir, base_dir)
- self.assertTrue(os.path.exists(res))
-
- res = make_archive(base_name, 'tar', root_dir, base_dir,
- owner=owner, group=group)
- self.assertTrue(os.path.exists(res))
-
- res = make_archive(base_name, 'tar', root_dir, base_dir,
- owner='kjhkjhkjg', group='oihohoh')
- self.assertTrue(os.path.exists(res))
-
- @unittest.skipUnless(zlib, "Requires zlib")
- @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
- def test_tarfile_root_owner(self):
- tmpdir, tmpdir2, base_name = self._create_files()
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- group = grp.getgrgid(0)[0]
- owner = pwd.getpwuid(0)[0]
- try:
- archive_name = make_tarball(base_name, 'dist', compress=None,
- owner=owner, group=group)
- finally:
- os.chdir(old_dir)
-
- # check if the compressed tarball was created
- self.assertTrue(os.path.exists(archive_name))
-
- # now checks the rights
- archive = tarfile.open(archive_name)
- try:
- for member in archive.getmembers():
- self.assertEqual(member.uid, 0)
- self.assertEqual(member.gid, 0)
- finally:
- archive.close()
-
- def test_make_archive_cwd(self):
- current_dir = os.getcwd()
- def _breaks(*args, **kw):
- raise RuntimeError()
- ARCHIVE_FORMATS['xxx'] = (_breaks, [], 'xxx file')
- try:
- try:
- make_archive('xxx', 'xxx', root_dir=self.mkdtemp())
- except:
- pass
- self.assertEqual(os.getcwd(), current_dir)
- finally:
- del ARCHIVE_FORMATS['xxx']
-
-def test_suite():
- return unittest.makeSuite(ArchiveUtilTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_bdist.py b/src/python/stdlib/distutils/tests/test_bdist.py
deleted file mode 100644
index fa7cd5a..0000000
--- a/src/python/stdlib/distutils/tests/test_bdist.py
+++ /dev/null
@@ -1,45 +0,0 @@
-"""Tests for distutils.command.bdist."""
-import unittest
-import sys
-import os
-import tempfile
-import shutil
-
-from test.test_support import run_unittest
-
-from distutils.core import Distribution
-from distutils.command.bdist import bdist
-from distutils.tests import support
-from distutils.spawn import find_executable
-from distutils import spawn
-from distutils.errors import DistutilsExecError
-
-class BuildTestCase(support.TempdirManager,
- unittest.TestCase):
-
- def test_formats(self):
-
- # let's create a command and make sure
- # we can fix the format
- pkg_pth, dist = self.create_dist()
- cmd = bdist(dist)
- cmd.formats = ['msi']
- cmd.ensure_finalized()
- self.assertEqual(cmd.formats, ['msi'])
-
- # what format bdist offers ?
- # XXX an explicit list in bdist is
- # not the best way to bdist_* commands
- # we should add a registry
- formats = ['rpm', 'zip', 'gztar', 'bztar', 'ztar',
- 'tar', 'wininst', 'msi']
- formats.sort()
- founded = cmd.format_command.keys()
- founded.sort()
- self.assertEqual(founded, formats)
-
-def test_suite():
- return unittest.makeSuite(BuildTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_bdist_dumb.py b/src/python/stdlib/distutils/tests/test_bdist_dumb.py
deleted file mode 100644
index 5a22a10..0000000
--- a/src/python/stdlib/distutils/tests/test_bdist_dumb.py
+++ /dev/null
@@ -1,105 +0,0 @@
-"""Tests for distutils.command.bdist_dumb."""
-
-import unittest
-import sys
-import os
-
-# zlib is not used here, but if it's not available
-# test_simple_built will fail
-try:
- import zlib
-except ImportError:
- zlib = None
-
-from test.test_support import run_unittest
-
-from distutils.core import Distribution
-from distutils.command.bdist_dumb import bdist_dumb
-from distutils.tests import support
-
-SETUP_PY = """\
-from distutils.core import setup
-import foo
-
-setup(name='foo', version='0.1', py_modules=['foo'],
- url='xxx', author='xxx', author_email='xxx')
-
-"""
-
-class BuildDumbTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- super(BuildDumbTestCase, self).setUp()
- self.old_location = os.getcwd()
- self.old_sys_argv = sys.argv, sys.argv[:]
-
- def tearDown(self):
- os.chdir(self.old_location)
- sys.argv = self.old_sys_argv[0]
- sys.argv[:] = self.old_sys_argv[1]
- super(BuildDumbTestCase, self).tearDown()
-
- @unittest.skipUnless(zlib, "requires zlib")
- def test_simple_built(self):
-
- # let's create a simple package
- tmp_dir = self.mkdtemp()
- pkg_dir = os.path.join(tmp_dir, 'foo')
- os.mkdir(pkg_dir)
- self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
- self.write_file((pkg_dir, 'foo.py'), '#')
- self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
- self.write_file((pkg_dir, 'README'), '')
-
- dist = Distribution({'name': 'foo', 'version': '0.1',
- 'py_modules': ['foo'],
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'})
- dist.script_name = 'setup.py'
- os.chdir(pkg_dir)
-
- sys.argv = ['setup.py']
- cmd = bdist_dumb(dist)
-
- # so the output is the same no matter
- # what is the platform
- cmd.format = 'zip'
-
- cmd.ensure_finalized()
- cmd.run()
-
- # see what we have
- dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
- base = "%s.%s" % (dist.get_fullname(), cmd.plat_name)
- if os.name == 'os2':
- base = base.replace(':', '-')
-
- wanted = ['%s.zip' % base]
- self.assertEqual(dist_created, wanted)
-
- # now let's check what we have in the zip file
- # XXX to be done
-
- def test_finalize_options(self):
- pkg_dir, dist = self.create_dist()
- os.chdir(pkg_dir)
- cmd = bdist_dumb(dist)
- self.assertEqual(cmd.bdist_dir, None)
- cmd.finalize_options()
-
- # bdist_dir is initialized to bdist_base/dumb if not set
- base = cmd.get_finalized_command('bdist').bdist_base
- self.assertEqual(cmd.bdist_dir, os.path.join(base, 'dumb'))
-
- # the format is set to a default value depending on the os.name
- default = cmd.default_format[os.name]
- self.assertEqual(cmd.format, default)
-
-def test_suite():
- return unittest.makeSuite(BuildDumbTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_bdist_msi.py b/src/python/stdlib/distutils/tests/test_bdist_msi.py
deleted file mode 100644
index 7554e9f..0000000
--- a/src/python/stdlib/distutils/tests/test_bdist_msi.py
+++ /dev/null
@@ -1,25 +0,0 @@
-"""Tests for distutils.command.bdist_msi."""
-import unittest
-import sys
-
-from test.test_support import run_unittest
-
-from distutils.tests import support
-
-@unittest.skipUnless(sys.platform=="win32", "These tests are only for win32")
-class BDistMSITestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_minial(self):
- # minimal test XXX need more tests
- from distutils.command.bdist_msi import bdist_msi
- pkg_pth, dist = self.create_dist()
- cmd = bdist_msi(dist)
- cmd.ensure_finalized()
-
-def test_suite():
- return unittest.makeSuite(BDistMSITestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_bdist_rpm.py b/src/python/stdlib/distutils/tests/test_bdist_rpm.py
deleted file mode 100644
index 25a5763..0000000
--- a/src/python/stdlib/distutils/tests/test_bdist_rpm.py
+++ /dev/null
@@ -1,127 +0,0 @@
-"""Tests for distutils.command.bdist_rpm."""
-
-import unittest
-import sys
-import os
-import tempfile
-import shutil
-
-from test.test_support import run_unittest
-
-from distutils.core import Distribution
-from distutils.command.bdist_rpm import bdist_rpm
-from distutils.tests import support
-from distutils.spawn import find_executable
-from distutils import spawn
-from distutils.errors import DistutilsExecError
-
-SETUP_PY = """\
-from distutils.core import setup
-import foo
-
-setup(name='foo', version='0.1', py_modules=['foo'],
- url='xxx', author='xxx', author_email='xxx')
-
-"""
-
-class BuildRpmTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def setUp(self):
- super(BuildRpmTestCase, self).setUp()
- self.old_location = os.getcwd()
- self.old_sys_argv = sys.argv, sys.argv[:]
-
- def tearDown(self):
- os.chdir(self.old_location)
- sys.argv = self.old_sys_argv[0]
- sys.argv[:] = self.old_sys_argv[1]
- super(BuildRpmTestCase, self).tearDown()
-
- def test_quiet(self):
-
- # XXX I am unable yet to make this test work without
- # spurious sdtout/stderr output under Mac OS X
- if sys.platform != 'linux2':
- return
-
- # this test will run only if the rpm commands are found
- if (find_executable('rpm') is None or
- find_executable('rpmbuild') is None):
- return
-
- # let's create a package
- tmp_dir = self.mkdtemp()
- pkg_dir = os.path.join(tmp_dir, 'foo')
- os.mkdir(pkg_dir)
- self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
- self.write_file((pkg_dir, 'foo.py'), '#')
- self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
- self.write_file((pkg_dir, 'README'), '')
-
- dist = Distribution({'name': 'foo', 'version': '0.1',
- 'py_modules': ['foo'],
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'})
- dist.script_name = 'setup.py'
- os.chdir(pkg_dir)
-
- sys.argv = ['setup.py']
- cmd = bdist_rpm(dist)
- cmd.fix_python = True
-
- # running in quiet mode
- cmd.quiet = 1
- cmd.ensure_finalized()
- cmd.run()
-
- dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
- self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
-
- def test_no_optimize_flag(self):
-
- # XXX I am unable yet to make this test work without
- # spurious sdtout/stderr output under Mac OS X
- if sys.platform != 'linux2':
- return
-
- # http://bugs.python.org/issue1533164
- # this test will run only if the rpm command is found
- if (find_executable('rpm') is None or
- find_executable('rpmbuild') is None):
- return
-
- # let's create a package that brakes bdist_rpm
- tmp_dir = self.mkdtemp()
- pkg_dir = os.path.join(tmp_dir, 'foo')
- os.mkdir(pkg_dir)
- self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
- self.write_file((pkg_dir, 'foo.py'), '#')
- self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
- self.write_file((pkg_dir, 'README'), '')
-
- dist = Distribution({'name': 'foo', 'version': '0.1',
- 'py_modules': ['foo'],
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'})
- dist.script_name = 'setup.py'
- os.chdir(pkg_dir)
-
- sys.argv = ['setup.py']
- cmd = bdist_rpm(dist)
- cmd.fix_python = True
-
- cmd.quiet = 1
- cmd.ensure_finalized()
- cmd.run()
-
- dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
- self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
- os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
-
-def test_suite():
- return unittest.makeSuite(BuildRpmTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_bdist_wininst.py b/src/python/stdlib/distutils/tests/test_bdist_wininst.py
deleted file mode 100644
index c2b13b3..0000000
--- a/src/python/stdlib/distutils/tests/test_bdist_wininst.py
+++ /dev/null
@@ -1,32 +0,0 @@
-"""Tests for distutils.command.bdist_wininst."""
-import unittest
-
-from test.test_support import run_unittest
-
-from distutils.command.bdist_wininst import bdist_wininst
-from distutils.tests import support
-
-class BuildWinInstTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_get_exe_bytes(self):
-
- # issue5731: command was broken on non-windows platforms
- # this test makes sure it works now for every platform
- # let's create a command
- pkg_pth, dist = self.create_dist()
- cmd = bdist_wininst(dist)
- cmd.ensure_finalized()
-
- # let's run the code that finds the right wininst*.exe file
- # and make sure it finds it and returns its content
- # no matter what platform we have
- exe_file = cmd.get_exe_bytes()
- self.assertTrue(len(exe_file) > 10)
-
-def test_suite():
- return unittest.makeSuite(BuildWinInstTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_build.py b/src/python/stdlib/distutils/tests/test_build.py
deleted file mode 100644
index 3db5703..0000000
--- a/src/python/stdlib/distutils/tests/test_build.py
+++ /dev/null
@@ -1,54 +0,0 @@
-"""Tests for distutils.command.build."""
-import unittest
-import os
-import sys
-
-from distutils.command.build import build
-from distutils.tests import support
-from sysconfig import get_platform
-
-class BuildTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_finalize_options(self):
- pkg_dir, dist = self.create_dist()
- cmd = build(dist)
- cmd.finalize_options()
-
- # if not specified, plat_name gets the current platform
- self.assertEqual(cmd.plat_name, get_platform())
-
- # build_purelib is build + lib
- wanted = os.path.join(cmd.build_base, 'lib')
- self.assertEqual(cmd.build_purelib, wanted)
-
- # build_platlib is 'build/lib.platform-x.x[-pydebug]'
- # examples:
- # build/lib.macosx-10.3-i386-2.7
- plat_spec = '.%s-%s' % (cmd.plat_name, sys.version[0:3])
- if hasattr(sys, 'gettotalrefcount'):
- self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
- plat_spec += '-pydebug'
- wanted = os.path.join(cmd.build_base, 'lib' + plat_spec)
- self.assertEqual(cmd.build_platlib, wanted)
-
- # by default, build_lib = build_purelib
- self.assertEqual(cmd.build_lib, cmd.build_purelib)
-
- # build_temp is build/temp.<plat>
- wanted = os.path.join(cmd.build_base, 'temp' + plat_spec)
- self.assertEqual(cmd.build_temp, wanted)
-
- # build_scripts is build/scripts-x.x
- wanted = os.path.join(cmd.build_base, 'scripts-' + sys.version[0:3])
- self.assertEqual(cmd.build_scripts, wanted)
-
- # executable is os.path.normpath(sys.executable)
- self.assertEqual(cmd.executable, os.path.normpath(sys.executable))
-
-def test_suite():
- return unittest.makeSuite(BuildTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_build_clib.py b/src/python/stdlib/distutils/tests/test_build_clib.py
deleted file mode 100644
index d77912a..0000000
--- a/src/python/stdlib/distutils/tests/test_build_clib.py
+++ /dev/null
@@ -1,143 +0,0 @@
-"""Tests for distutils.command.build_clib."""
-import unittest
-import os
-import sys
-
-from distutils.command.build_clib import build_clib
-from distutils.errors import DistutilsSetupError
-from distutils.tests import support
-from distutils.spawn import find_executable
-
-class BuildCLibTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_check_library_dist(self):
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- # 'libraries' option must be a list
- self.assertRaises(DistutilsSetupError, cmd.check_library_list, 'foo')
-
- # each element of 'libraries' must a 2-tuple
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- ['foo1', 'foo2'])
-
- # first element of each tuple in 'libraries'
- # must be a string (the library name)
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- [(1, 'foo1'), ('name', 'foo2')])
-
- # library name may not contain directory separators
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- [('name', 'foo1'),
- ('another/name', 'foo2')])
-
- # second element of each tuple must be a dictionary (build info)
- self.assertRaises(DistutilsSetupError, cmd.check_library_list,
- [('name', {}),
- ('another', 'foo2')])
-
- # those work
- libs = [('name', {}), ('name', {'ok': 'good'})]
- cmd.check_library_list(libs)
-
- def test_get_source_files(self):
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- # "in 'libraries' option 'sources' must be present and must be
- # a list of source filenames
- cmd.libraries = [('name', {})]
- self.assertRaises(DistutilsSetupError, cmd.get_source_files)
-
- cmd.libraries = [('name', {'sources': 1})]
- self.assertRaises(DistutilsSetupError, cmd.get_source_files)
-
- cmd.libraries = [('name', {'sources': ['a', 'b']})]
- self.assertEqual(cmd.get_source_files(), ['a', 'b'])
-
- cmd.libraries = [('name', {'sources': ('a', 'b')})]
- self.assertEqual(cmd.get_source_files(), ['a', 'b'])
-
- cmd.libraries = [('name', {'sources': ('a', 'b')}),
- ('name2', {'sources': ['c', 'd']})]
- self.assertEqual(cmd.get_source_files(), ['a', 'b', 'c', 'd'])
-
- def test_build_libraries(self):
-
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
- class FakeCompiler:
- def compile(*args, **kw):
- pass
- create_static_lib = compile
-
- cmd.compiler = FakeCompiler()
-
- # build_libraries is also doing a bit of typoe checking
- lib = [('name', {'sources': 'notvalid'})]
- self.assertRaises(DistutilsSetupError, cmd.build_libraries, lib)
-
- lib = [('name', {'sources': list()})]
- cmd.build_libraries(lib)
-
- lib = [('name', {'sources': tuple()})]
- cmd.build_libraries(lib)
-
- def test_finalize_options(self):
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- cmd.include_dirs = 'one-dir'
- cmd.finalize_options()
- self.assertEqual(cmd.include_dirs, ['one-dir'])
-
- cmd.include_dirs = None
- cmd.finalize_options()
- self.assertEqual(cmd.include_dirs, [])
-
- cmd.distribution.libraries = 'WONTWORK'
- self.assertRaises(DistutilsSetupError, cmd.finalize_options)
-
- def test_run(self):
- # can't test on windows
- if sys.platform == 'win32':
- return
-
- pkg_dir, dist = self.create_dist()
- cmd = build_clib(dist)
-
- foo_c = os.path.join(pkg_dir, 'foo.c')
- self.write_file(foo_c, 'int main(void) { return 1;}\n')
- cmd.libraries = [('foo', {'sources': [foo_c]})]
-
- build_temp = os.path.join(pkg_dir, 'build')
- os.mkdir(build_temp)
- cmd.build_temp = build_temp
- cmd.build_clib = build_temp
-
- # before we run the command, we want to make sure
- # all commands are present on the system
- # by creating a compiler and checking its executables
- from distutils.ccompiler import new_compiler, customize_compiler
-
- compiler = new_compiler()
- customize_compiler(compiler)
- for ccmd in compiler.executables.values():
- if ccmd is None:
- continue
- if find_executable(ccmd[0]) is None:
- return # can't test
-
- # this should work
- cmd.run()
-
- # let's check the result
- self.assertTrue('libfoo.a' in os.listdir(build_temp))
-
-def test_suite():
- return unittest.makeSuite(BuildCLibTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_build_ext.py b/src/python/stdlib/distutils/tests/test_build_ext.py
deleted file mode 100644
index 86568eb..0000000
--- a/src/python/stdlib/distutils/tests/test_build_ext.py
+++ /dev/null
@@ -1,437 +0,0 @@
-import sys
-import os
-import tempfile
-import shutil
-from StringIO import StringIO
-
-from distutils.core import Extension, Distribution
-from distutils.command.build_ext import build_ext
-from distutils import sysconfig
-from distutils.tests import support
-from distutils.errors import DistutilsSetupError
-
-import unittest
-from test import test_support
-
-# http://bugs.python.org/issue4373
-# Don't load the xx module more than once.
-ALREADY_TESTED = False
-
-def _get_source_filename():
- srcdir = sysconfig.get_config_var('srcdir')
- if srcdir is None:
- return os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c')
- return os.path.join(srcdir, 'Modules', 'xxmodule.c')
-
-_XX_MODULE_PATH = _get_source_filename()
-
-class BuildExtTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
- def setUp(self):
- # Create a simple test environment
- # Note that we're making changes to sys.path
- super(BuildExtTestCase, self).setUp()
- self.tmp_dir = tempfile.mkdtemp(prefix="pythontest_")
- if os.path.exists(_XX_MODULE_PATH):
- self.sys_path = sys.path[:]
- sys.path.append(self.tmp_dir)
- shutil.copy(_XX_MODULE_PATH, self.tmp_dir)
-
- def tearDown(self):
- # Get everything back to normal
- if os.path.exists(_XX_MODULE_PATH):
- test_support.unload('xx')
- sys.path[:] = self.sys_path
- # XXX on Windows the test leaves a directory
- # with xx module in TEMP
- shutil.rmtree(self.tmp_dir, os.name == 'nt' or
- sys.platform == 'cygwin')
- super(BuildExtTestCase, self).tearDown()
-
- def _fixup_command(self, cmd):
- # When Python was build with --enable-shared, -L. is not good enough
- # to find the libpython<blah>.so. This is because regrtest runs it
- # under a tempdir, not in the top level where the .so lives. By the
- # time we've gotten here, Python's already been chdir'd to the
- # tempdir.
- #
- # To further add to the fun, we can't just add library_dirs to the
- # Extension() instance because that doesn't get plumbed through to the
- # final compiler command.
- if (sysconfig.get_config_var('Py_ENABLE_SHARED') and
- not sys.platform.startswith('win')):
- runshared = sysconfig.get_config_var('RUNSHARED')
- if runshared is None:
- cmd.library_dirs = ['.']
- else:
- name, equals, value = runshared.partition('=')
- cmd.library_dirs = value.split(os.pathsep)
-
- @unittest.skipIf(not os.path.exists(_XX_MODULE_PATH),
- 'xxmodule.c not found')
- def test_build_ext(self):
- global ALREADY_TESTED
- xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
- xx_ext = Extension('xx', [xx_c])
- dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
- dist.package_dir = self.tmp_dir
- cmd = build_ext(dist)
- self._fixup_command(cmd)
- if os.name == "nt":
- # On Windows, we must build a debug version iff running
- # a debug build of Python
- cmd.debug = sys.executable.endswith("_d.exe")
- cmd.build_lib = self.tmp_dir
- cmd.build_temp = self.tmp_dir
-
- old_stdout = sys.stdout
- if not test_support.verbose:
- # silence compiler output
- sys.stdout = StringIO()
- try:
- cmd.ensure_finalized()
- cmd.run()
- finally:
- sys.stdout = old_stdout
-
- if ALREADY_TESTED:
- return
- else:
- ALREADY_TESTED = True
-
- import xx
-
- for attr in ('error', 'foo', 'new', 'roj'):
- self.assertTrue(hasattr(xx, attr))
-
- self.assertEqual(xx.foo(2, 5), 7)
- self.assertEqual(xx.foo(13,15), 28)
- self.assertEqual(xx.new().demo(), None)
- doc = 'This is a template module just for instruction.'
- self.assertEqual(xx.__doc__, doc)
- self.assertTrue(isinstance(xx.Null(), xx.Null))
- self.assertTrue(isinstance(xx.Str(), xx.Str))
-
- def test_solaris_enable_shared(self):
- dist = Distribution({'name': 'xx'})
- cmd = build_ext(dist)
- old = sys.platform
-
- sys.platform = 'sunos' # fooling finalize_options
- from distutils.sysconfig import _config_vars
- old_var = _config_vars.get('Py_ENABLE_SHARED')
- _config_vars['Py_ENABLE_SHARED'] = 1
- try:
- cmd.ensure_finalized()
- finally:
- sys.platform = old
- if old_var is None:
- del _config_vars['Py_ENABLE_SHARED']
- else:
- _config_vars['Py_ENABLE_SHARED'] = old_var
-
- # make sure we get some library dirs under solaris
- self.assertTrue(len(cmd.library_dirs) > 0)
-
- def test_finalize_options(self):
- # Make sure Python's include directories (for Python.h, pyconfig.h,
- # etc.) are in the include search path.
- modules = [Extension('foo', ['xxx'])]
- dist = Distribution({'name': 'xx', 'ext_modules': modules})
- cmd = build_ext(dist)
- cmd.finalize_options()
-
- from distutils import sysconfig
- py_include = sysconfig.get_python_inc()
- self.assertTrue(py_include in cmd.include_dirs)
-
- plat_py_include = sysconfig.get_python_inc(plat_specific=1)
- self.assertTrue(plat_py_include in cmd.include_dirs)
-
- # make sure cmd.libraries is turned into a list
- # if it's a string
- cmd = build_ext(dist)
- cmd.libraries = 'my_lib'
- cmd.finalize_options()
- self.assertEqual(cmd.libraries, ['my_lib'])
-
- # make sure cmd.library_dirs is turned into a list
- # if it's a string
- cmd = build_ext(dist)
- cmd.library_dirs = 'my_lib_dir'
- cmd.finalize_options()
- self.assertTrue('my_lib_dir' in cmd.library_dirs)
-
- # make sure rpath is turned into a list
- # if it's a list of os.pathsep's paths
- cmd = build_ext(dist)
- cmd.rpath = os.pathsep.join(['one', 'two'])
- cmd.finalize_options()
- self.assertEqual(cmd.rpath, ['one', 'two'])
-
- # XXX more tests to perform for win32
-
- # make sure define is turned into 2-tuples
- # strings if they are ','-separated strings
- cmd = build_ext(dist)
- cmd.define = 'one,two'
- cmd.finalize_options()
- self.assertEqual(cmd.define, [('one', '1'), ('two', '1')])
-
- # make sure undef is turned into a list of
- # strings if they are ','-separated strings
- cmd = build_ext(dist)
- cmd.undef = 'one,two'
- cmd.finalize_options()
- self.assertEqual(cmd.undef, ['one', 'two'])
-
- # make sure swig_opts is turned into a list
- cmd = build_ext(dist)
- cmd.swig_opts = None
- cmd.finalize_options()
- self.assertEqual(cmd.swig_opts, [])
-
- cmd = build_ext(dist)
- cmd.swig_opts = '1 2'
- cmd.finalize_options()
- self.assertEqual(cmd.swig_opts, ['1', '2'])
-
- def test_check_extensions_list(self):
- dist = Distribution()
- cmd = build_ext(dist)
- cmd.finalize_options()
-
- #'extensions' option must be a list of Extension instances
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, 'foo')
-
- # each element of 'ext_modules' option must be an
- # Extension instance or 2-tuple
- exts = [('bar', 'foo', 'bar'), 'foo']
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # first element of each tuple in 'ext_modules'
- # must be the extension name (a string) and match
- # a python dotted-separated name
- exts = [('foo-bar', '')]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # second element of each tuple in 'ext_modules'
- # must be a ary (build info)
- exts = [('foo.bar', '')]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # ok this one should pass
- exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
- 'some': 'bar'})]
- cmd.check_extensions_list(exts)
- ext = exts[0]
- self.assertTrue(isinstance(ext, Extension))
-
- # check_extensions_list adds in ext the values passed
- # when they are in ('include_dirs', 'library_dirs', 'libraries'
- # 'extra_objects', 'extra_compile_args', 'extra_link_args')
- self.assertEqual(ext.libraries, 'foo')
- self.assertTrue(not hasattr(ext, 'some'))
-
- # 'macros' element of build info dict must be 1- or 2-tuple
- exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
- 'some': 'bar', 'macros': [('1', '2', '3'), 'foo']})]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- exts[0][1]['macros'] = [('1', '2'), ('3',)]
- cmd.check_extensions_list(exts)
- self.assertEqual(exts[0].undef_macros, ['3'])
- self.assertEqual(exts[0].define_macros, [('1', '2')])
-
- def test_get_source_files(self):
- modules = [Extension('foo', ['xxx'])]
- dist = Distribution({'name': 'xx', 'ext_modules': modules})
- cmd = build_ext(dist)
- cmd.ensure_finalized()
- self.assertEqual(cmd.get_source_files(), ['xxx'])
-
- def test_compiler_option(self):
- # cmd.compiler is an option and
- # should not be overriden by a compiler instance
- # when the command is run
- dist = Distribution()
- cmd = build_ext(dist)
- cmd.compiler = 'unix'
- cmd.ensure_finalized()
- cmd.run()
- self.assertEqual(cmd.compiler, 'unix')
-
- def test_get_outputs(self):
- tmp_dir = self.mkdtemp()
- c_file = os.path.join(tmp_dir, 'foo.c')
- self.write_file(c_file, 'void initfoo(void) {};\n')
- ext = Extension('foo', [c_file])
- dist = Distribution({'name': 'xx',
- 'ext_modules': [ext]})
- cmd = build_ext(dist)
- self._fixup_command(cmd)
- cmd.ensure_finalized()
- self.assertEqual(len(cmd.get_outputs()), 1)
-
- if os.name == "nt":
- cmd.debug = sys.executable.endswith("_d.exe")
-
- cmd.build_lib = os.path.join(self.tmp_dir, 'build')
- cmd.build_temp = os.path.join(self.tmp_dir, 'tempt')
-
- # issue #5977 : distutils build_ext.get_outputs
- # returns wrong result with --inplace
- other_tmp_dir = os.path.realpath(self.mkdtemp())
- old_wd = os.getcwd()
- os.chdir(other_tmp_dir)
- try:
- cmd.inplace = 1
- cmd.run()
- so_file = cmd.get_outputs()[0]
- finally:
- os.chdir(old_wd)
- self.assertTrue(os.path.exists(so_file))
- self.assertEqual(os.path.splitext(so_file)[-1],
- sysconfig.get_config_var('SO'))
- so_dir = os.path.dirname(so_file)
- self.assertEqual(so_dir, other_tmp_dir)
- cmd.compiler = None
- cmd.inplace = 0
- cmd.run()
- so_file = cmd.get_outputs()[0]
- self.assertTrue(os.path.exists(so_file))
- self.assertEqual(os.path.splitext(so_file)[-1],
- sysconfig.get_config_var('SO'))
- so_dir = os.path.dirname(so_file)
- self.assertEqual(so_dir, cmd.build_lib)
-
- # inplace = 0, cmd.package = 'bar'
- build_py = cmd.get_finalized_command('build_py')
- build_py.package_dir = {'': 'bar'}
- path = cmd.get_ext_fullpath('foo')
- # checking that the last directory is the build_dir
- path = os.path.split(path)[0]
- self.assertEqual(path, cmd.build_lib)
-
- # inplace = 1, cmd.package = 'bar'
- cmd.inplace = 1
- other_tmp_dir = os.path.realpath(self.mkdtemp())
- old_wd = os.getcwd()
- os.chdir(other_tmp_dir)
- try:
- path = cmd.get_ext_fullpath('foo')
- finally:
- os.chdir(old_wd)
- # checking that the last directory is bar
- path = os.path.split(path)[0]
- lastdir = os.path.split(path)[-1]
- self.assertEqual(lastdir, 'bar')
-
- def test_ext_fullpath(self):
- ext = sysconfig.get_config_vars()['SO']
- dist = Distribution()
- cmd = build_ext(dist)
- cmd.inplace = 1
- cmd.distribution.package_dir = {'': 'src'}
- cmd.distribution.packages = ['lxml', 'lxml.html']
- curdir = os.getcwd()
- wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
- path = cmd.get_ext_fullpath('lxml.etree')
- self.assertEqual(wanted, path)
-
- # building lxml.etree not inplace
- cmd.inplace = 0
- cmd.build_lib = os.path.join(curdir, 'tmpdir')
- wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree' + ext)
- path = cmd.get_ext_fullpath('lxml.etree')
- self.assertEqual(wanted, path)
-
- # building twisted.runner.portmap not inplace
- build_py = cmd.get_finalized_command('build_py')
- build_py.package_dir = {}
- cmd.distribution.packages = ['twisted', 'twisted.runner.portmap']
- path = cmd.get_ext_fullpath('twisted.runner.portmap')
- wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
- 'portmap' + ext)
- self.assertEqual(wanted, path)
-
- # building twisted.runner.portmap inplace
- cmd.inplace = 1
- path = cmd.get_ext_fullpath('twisted.runner.portmap')
- wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
- self.assertEqual(wanted, path)
-
- def test_build_ext_inplace(self):
- etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
- etree_ext = Extension('lxml.etree', [etree_c])
- dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
- cmd = build_ext(dist)
- cmd.ensure_finalized()
- cmd.inplace = 1
- cmd.distribution.package_dir = {'': 'src'}
- cmd.distribution.packages = ['lxml', 'lxml.html']
- curdir = os.getcwd()
- ext = sysconfig.get_config_var("SO")
- wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
- path = cmd.get_ext_fullpath('lxml.etree')
- self.assertEqual(wanted, path)
-
- def test_setuptools_compat(self):
- import distutils.core, distutils.extension, distutils.command.build_ext
- saved_ext = distutils.extension.Extension
- try:
- # on some platforms, it loads the deprecated "dl" module
- test_support.import_module('setuptools_build_ext', deprecated=True)
-
- # theses import patch Distutils' Extension class
- from setuptools_build_ext import build_ext as setuptools_build_ext
- from setuptools_extension import Extension
-
- etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
- etree_ext = Extension('lxml.etree', [etree_c])
- dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
- cmd = setuptools_build_ext(dist)
- cmd.ensure_finalized()
- cmd.inplace = 1
- cmd.distribution.package_dir = {'': 'src'}
- cmd.distribution.packages = ['lxml', 'lxml.html']
- curdir = os.getcwd()
- ext = sysconfig.get_config_var("SO")
- wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
- path = cmd.get_ext_fullpath('lxml.etree')
- self.assertEqual(wanted, path)
- finally:
- # restoring Distutils' Extension class otherwise its broken
- distutils.extension.Extension = saved_ext
- distutils.core.Extension = saved_ext
- distutils.command.build_ext.Extension = saved_ext
-
- def test_build_ext_path_with_os_sep(self):
- dist = Distribution({'name': 'UpdateManager'})
- cmd = build_ext(dist)
- cmd.ensure_finalized()
- ext = sysconfig.get_config_var("SO")
- ext_name = os.path.join('UpdateManager', 'fdsend')
- ext_path = cmd.get_ext_fullpath(ext_name)
- wanted = os.path.join(cmd.build_lib, 'UpdateManager', 'fdsend' + ext)
- self.assertEqual(ext_path, wanted)
-
- def test_build_ext_path_cross_platform(self):
- if sys.platform != 'win32':
- return
- dist = Distribution({'name': 'UpdateManager'})
- cmd = build_ext(dist)
- cmd.ensure_finalized()
- ext = sysconfig.get_config_var("SO")
- # this needs to work even under win32
- ext_name = 'UpdateManager/fdsend'
- ext_path = cmd.get_ext_fullpath(ext_name)
- wanted = os.path.join(cmd.build_lib, 'UpdateManager', 'fdsend' + ext)
- self.assertEqual(ext_path, wanted)
-
-def test_suite():
- return unittest.makeSuite(BuildExtTestCase)
-
-if __name__ == '__main__':
- test_support.run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_build_py.py b/src/python/stdlib/distutils/tests/test_build_py.py
deleted file mode 100644
index 0351739..0000000
--- a/src/python/stdlib/distutils/tests/test_build_py.py
+++ /dev/null
@@ -1,126 +0,0 @@
-"""Tests for distutils.command.build_py."""
-
-import os
-import sys
-import StringIO
-import unittest
-
-from distutils.command.build_py import build_py
-from distutils.core import Distribution
-from distutils.errors import DistutilsFileError
-
-from distutils.tests import support
-
-
-class BuildPyTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def _setup_package_data(self):
- sources = self.mkdtemp()
- f = open(os.path.join(sources, "__init__.py"), "w")
- try:
- f.write("# Pretend this is a package.")
- finally:
- f.close()
- f = open(os.path.join(sources, "README.txt"), "w")
- try:
- f.write("Info about this package")
- finally:
- f.close()
-
- destination = self.mkdtemp()
-
- dist = Distribution({"packages": ["pkg"],
- "package_dir": {"pkg": sources}})
- # script_name need not exist, it just need to be initialized
- dist.script_name = os.path.join(sources, "setup.py")
- dist.command_obj["build"] = support.DummyCommand(
- force=0,
- build_lib=destination)
- dist.packages = ["pkg"]
- dist.package_data = {"pkg": ["README.txt"]}
- dist.package_dir = {"pkg": sources}
-
- cmd = build_py(dist)
- cmd.compile = 1
- cmd.ensure_finalized()
- self.assertEqual(cmd.package_data, dist.package_data)
-
- cmd.run()
-
- # This makes sure the list of outputs includes byte-compiled
- # files for Python modules but not for package data files
- # (there shouldn't *be* byte-code files for those!).
- #
- self.assertEqual(len(cmd.get_outputs()), 3)
- pkgdest = os.path.join(destination, "pkg")
- files = os.listdir(pkgdest)
- return files
-
- def test_package_data(self):
- files = self._setup_package_data()
- self.assertTrue("__init__.py" in files)
- self.assertTrue("README.txt" in files)
-
- @unittest.skipIf(sys.flags.optimize >= 2,
- "pyc files are not written with -O2 and above")
- def test_package_data_pyc(self):
- files = self._setup_package_data()
- self.assertTrue("__init__.pyc" in files)
-
- def test_empty_package_dir (self):
- # See SF 1668596/1720897.
- cwd = os.getcwd()
-
- # create the distribution files.
- sources = self.mkdtemp()
- open(os.path.join(sources, "__init__.py"), "w").close()
-
- testdir = os.path.join(sources, "doc")
- os.mkdir(testdir)
- open(os.path.join(testdir, "testfile"), "w").close()
-
- os.chdir(sources)
- old_stdout = sys.stdout
- sys.stdout = StringIO.StringIO()
-
- try:
- dist = Distribution({"packages": ["pkg"],
- "package_dir": {"pkg": ""},
- "package_data": {"pkg": ["doc/*"]}})
- # script_name need not exist, it just need to be initialized
- dist.script_name = os.path.join(sources, "setup.py")
- dist.script_args = ["build"]
- dist.parse_command_line()
-
- try:
- dist.run_commands()
- except DistutilsFileError:
- self.fail("failed package_data test when package_dir is ''")
- finally:
- # Restore state.
- os.chdir(cwd)
- sys.stdout = old_stdout
-
- def test_dont_write_bytecode(self):
- # makes sure byte_compile is not used
- pkg_dir, dist = self.create_dist()
- cmd = build_py(dist)
- cmd.compile = 1
- cmd.optimize = 1
-
- old_dont_write_bytecode = sys.dont_write_bytecode
- sys.dont_write_bytecode = True
- try:
- cmd.byte_compile([])
- finally:
- sys.dont_write_bytecode = old_dont_write_bytecode
-
- self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
-
-def test_suite():
- return unittest.makeSuite(BuildPyTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_build_scripts.py b/src/python/stdlib/distutils/tests/test_build_scripts.py
deleted file mode 100644
index df89cde..0000000
--- a/src/python/stdlib/distutils/tests/test_build_scripts.py
+++ /dev/null
@@ -1,111 +0,0 @@
-"""Tests for distutils.command.build_scripts."""
-
-import os
-import unittest
-
-from distutils.command.build_scripts import build_scripts
-from distutils.core import Distribution
-import sysconfig
-
-from distutils.tests import support
-
-
-class BuildScriptsTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_default_settings(self):
- cmd = self.get_build_scripts_cmd("/foo/bar", [])
- self.assertTrue(not cmd.force)
- self.assertTrue(cmd.build_dir is None)
-
- cmd.finalize_options()
-
- self.assertTrue(cmd.force)
- self.assertEqual(cmd.build_dir, "/foo/bar")
-
- def test_build(self):
- source = self.mkdtemp()
- target = self.mkdtemp()
- expected = self.write_sample_scripts(source)
-
- cmd = self.get_build_scripts_cmd(target,
- [os.path.join(source, fn)
- for fn in expected])
- cmd.finalize_options()
- cmd.run()
-
- built = os.listdir(target)
- for name in expected:
- self.assertTrue(name in built)
-
- def get_build_scripts_cmd(self, target, scripts):
- import sys
- dist = Distribution()
- dist.scripts = scripts
- dist.command_obj["build"] = support.DummyCommand(
- build_scripts=target,
- force=1,
- executable=sys.executable
- )
- return build_scripts(dist)
-
- def write_sample_scripts(self, dir):
- expected = []
- expected.append("script1.py")
- self.write_script(dir, "script1.py",
- ("#! /usr/bin/env python2.3\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
- expected.append("script2.py")
- self.write_script(dir, "script2.py",
- ("#!/usr/bin/python\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
- expected.append("shell.sh")
- self.write_script(dir, "shell.sh",
- ("#!/bin/sh\n"
- "# bogus shell script w/ sh-bang\n"
- "exit 0\n"))
- return expected
-
- def write_script(self, dir, name, text):
- f = open(os.path.join(dir, name), "w")
- try:
- f.write(text)
- finally:
- f.close()
-
- def test_version_int(self):
- source = self.mkdtemp()
- target = self.mkdtemp()
- expected = self.write_sample_scripts(source)
-
-
- cmd = self.get_build_scripts_cmd(target,
- [os.path.join(source, fn)
- for fn in expected])
- cmd.finalize_options()
-
- # http://bugs.python.org/issue4524
- #
- # On linux-g++-32 with command line `./configure --enable-ipv6
- # --with-suffix=3`, python is compiled okay but the build scripts
- # failed when writing the name of the executable
- old = sysconfig.get_config_vars().get('VERSION')
- sysconfig._CONFIG_VARS['VERSION'] = 4
- try:
- cmd.run()
- finally:
- if old is not None:
- sysconfig._CONFIG_VARS['VERSION'] = old
-
- built = os.listdir(target)
- for name in expected:
- self.assertTrue(name in built)
-
-def test_suite():
- return unittest.makeSuite(BuildScriptsTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_ccompiler.py b/src/python/stdlib/distutils/tests/test_ccompiler.py
deleted file mode 100644
index e21873e..0000000
--- a/src/python/stdlib/distutils/tests/test_ccompiler.py
+++ /dev/null
@@ -1,81 +0,0 @@
-"""Tests for distutils.ccompiler."""
-import os
-import unittest
-from test.test_support import captured_stdout
-
-from distutils.ccompiler import (gen_lib_options, CCompiler,
- get_default_compiler, customize_compiler)
-from distutils import debug
-from distutils.tests import support
-
-class FakeCompiler(object):
- def library_dir_option(self, dir):
- return "-L" + dir
-
- def runtime_library_dir_option(self, dir):
- return ["-cool", "-R" + dir]
-
- def find_library_file(self, dirs, lib, debug=0):
- return 'found'
-
- def library_option(self, lib):
- return "-l" + lib
-
-class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
-
- def test_gen_lib_options(self):
- compiler = FakeCompiler()
- libdirs = ['lib1', 'lib2']
- runlibdirs = ['runlib1']
- libs = [os.path.join('dir', 'name'), 'name2']
-
- opts = gen_lib_options(compiler, libdirs, runlibdirs, libs)
- wanted = ['-Llib1', '-Llib2', '-cool', '-Rrunlib1', 'found',
- '-lname2']
- self.assertEqual(opts, wanted)
-
- def test_debug_print(self):
-
- class MyCCompiler(CCompiler):
- executables = {}
-
- compiler = MyCCompiler()
- with captured_stdout() as stdout:
- compiler.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
-
- debug.DEBUG = True
- try:
- with captured_stdout() as stdout:
- compiler.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), 'xxx\n')
- finally:
- debug.DEBUG = False
-
- def test_customize_compiler(self):
-
- # not testing if default compiler is not unix
- if get_default_compiler() != 'unix':
- return
-
- os.environ['AR'] = 'my_ar'
- os.environ['ARFLAGS'] = '-arflags'
-
- # make sure AR gets caught
- class compiler:
- compiler_type = 'unix'
-
- def set_executables(self, **kw):
- self.exes = kw
-
- comp = compiler()
- customize_compiler(comp)
- self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
-
-def test_suite():
- return unittest.makeSuite(CCompilerTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_check.py b/src/python/stdlib/distutils/tests/test_check.py
deleted file mode 100644
index 7c56c04..0000000
--- a/src/python/stdlib/distutils/tests/test_check.py
+++ /dev/null
@@ -1,98 +0,0 @@
-"""Tests for distutils.command.check."""
-import unittest
-
-from distutils.command.check import check, HAS_DOCUTILS
-from distutils.tests import support
-from distutils.errors import DistutilsSetupError
-
-class CheckTestCase(support.LoggingSilencer,
- support.TempdirManager,
- unittest.TestCase):
-
- def _run(self, metadata=None, **options):
- if metadata is None:
- metadata = {}
- pkg_info, dist = self.create_dist(**metadata)
- cmd = check(dist)
- cmd.initialize_options()
- for name, value in options.items():
- setattr(cmd, name, value)
- cmd.ensure_finalized()
- cmd.run()
- return cmd
-
- def test_check_metadata(self):
- # let's run the command with no metadata at all
- # by default, check is checking the metadata
- # should have some warnings
- cmd = self._run()
- self.assertEqual(cmd._warnings, 2)
-
- # now let's add the required fields
- # and run it again, to make sure we don't get
- # any warning anymore
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx'}
- cmd = self._run(metadata)
- self.assertEqual(cmd._warnings, 0)
-
- # now with the strict mode, we should
- # get an error if there are missing metadata
- self.assertRaises(DistutilsSetupError, self._run, {}, **{'strict': 1})
-
- # and of course, no error when all metadata are present
- cmd = self._run(metadata, strict=1)
- self.assertEqual(cmd._warnings, 0)
-
- def test_check_document(self):
- if not HAS_DOCUTILS: # won't test without docutils
- return
- pkg_info, dist = self.create_dist()
- cmd = check(dist)
-
- # let's see if it detects broken rest
- broken_rest = 'title\n===\n\ntest'
- msgs = cmd._check_rst_data(broken_rest)
- self.assertEqual(len(msgs), 1)
-
- # and non-broken rest
- rest = 'title\n=====\n\ntest'
- msgs = cmd._check_rst_data(rest)
- self.assertEqual(len(msgs), 0)
-
- def test_check_restructuredtext(self):
- if not HAS_DOCUTILS: # won't test without docutils
- return
- # let's see if it detects broken rest in long_description
- broken_rest = 'title\n===\n\ntest'
- pkg_info, dist = self.create_dist(long_description=broken_rest)
- cmd = check(dist)
- cmd.check_restructuredtext()
- self.assertEqual(cmd._warnings, 1)
-
- # let's see if we have an error with strict=1
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx',
- 'long_description': broken_rest}
- self.assertRaises(DistutilsSetupError, self._run, metadata,
- **{'strict': 1, 'restructuredtext': 1})
-
- # and non-broken rest
- metadata['long_description'] = 'title\n=====\n\ntest'
- cmd = self._run(metadata, strict=1, restructuredtext=1)
- self.assertEqual(cmd._warnings, 0)
-
- def test_check_all(self):
-
- metadata = {'url': 'xxx', 'author': 'xxx'}
- self.assertRaises(DistutilsSetupError, self._run,
- {}, **{'strict': 1,
- 'restructuredtext': 1})
-
-def test_suite():
- return unittest.makeSuite(CheckTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_clean.py b/src/python/stdlib/distutils/tests/test_clean.py
deleted file mode 100644
index dbc4ee2..0000000
--- a/src/python/stdlib/distutils/tests/test_clean.py
+++ /dev/null
@@ -1,50 +0,0 @@
-"""Tests for distutils.command.clean."""
-import sys
-import os
-import unittest
-import getpass
-
-from distutils.command.clean import clean
-from distutils.tests import support
-
-class cleanTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_simple_run(self):
- pkg_dir, dist = self.create_dist()
- cmd = clean(dist)
-
- # let's add some elements clean should remove
- dirs = [(d, os.path.join(pkg_dir, d))
- for d in ('build_temp', 'build_lib', 'bdist_base',
- 'build_scripts', 'build_base')]
-
- for name, path in dirs:
- os.mkdir(path)
- setattr(cmd, name, path)
- if name == 'build_base':
- continue
- for f in ('one', 'two', 'three'):
- self.write_file(os.path.join(path, f))
-
- # let's run the command
- cmd.all = 1
- cmd.ensure_finalized()
- cmd.run()
-
- # make sure the files where removed
- for name, path in dirs:
- self.assertTrue(not os.path.exists(path),
- '%s was not removed' % path)
-
- # let's run the command again (should spit warnings but suceed)
- cmd.all = 1
- cmd.ensure_finalized()
- cmd.run()
-
-def test_suite():
- return unittest.makeSuite(cleanTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_cmd.py b/src/python/stdlib/distutils/tests/test_cmd.py
deleted file mode 100644
index 97cdb8a..0000000
--- a/src/python/stdlib/distutils/tests/test_cmd.py
+++ /dev/null
@@ -1,127 +0,0 @@
-"""Tests for distutils.cmd."""
-import unittest
-import os
-from test.test_support import captured_stdout, run_unittest
-
-from distutils.cmd import Command
-from distutils.dist import Distribution
-from distutils.errors import DistutilsOptionError
-from distutils import debug
-
-class MyCmd(Command):
- def initialize_options(self):
- pass
-
-class CommandTestCase(unittest.TestCase):
-
- def setUp(self):
- dist = Distribution()
- self.cmd = MyCmd(dist)
-
- def test_ensure_string_list(self):
-
- cmd = self.cmd
- cmd.not_string_list = ['one', 2, 'three']
- cmd.yes_string_list = ['one', 'two', 'three']
- cmd.not_string_list2 = object()
- cmd.yes_string_list2 = 'ok'
- cmd.ensure_string_list('yes_string_list')
- cmd.ensure_string_list('yes_string_list2')
-
- self.assertRaises(DistutilsOptionError,
- cmd.ensure_string_list, 'not_string_list')
-
- self.assertRaises(DistutilsOptionError,
- cmd.ensure_string_list, 'not_string_list2')
-
- def test_make_file(self):
-
- cmd = self.cmd
-
- # making sure it raises when infiles is not a string or a list/tuple
- self.assertRaises(TypeError, cmd.make_file,
- infiles=1, outfile='', func='func', args=())
-
- # making sure execute gets called properly
- def _execute(func, args, exec_msg, level):
- self.assertEqual(exec_msg, 'generating out from in')
- cmd.force = True
- cmd.execute = _execute
- cmd.make_file(infiles='in', outfile='out', func='func', args=())
-
- def test_dump_options(self):
-
- msgs = []
- def _announce(msg, level):
- msgs.append(msg)
- cmd = self.cmd
- cmd.announce = _announce
- cmd.option1 = 1
- cmd.option2 = 1
- cmd.user_options = [('option1', '', ''), ('option2', '', '')]
- cmd.dump_options()
-
- wanted = ["command options for 'MyCmd':", ' option1 = 1',
- ' option2 = 1']
- self.assertEqual(msgs, wanted)
-
- def test_ensure_string(self):
- cmd = self.cmd
- cmd.option1 = 'ok'
- cmd.ensure_string('option1')
-
- cmd.option2 = None
- cmd.ensure_string('option2', 'xxx')
- self.assertTrue(hasattr(cmd, 'option2'))
-
- cmd.option3 = 1
- self.assertRaises(DistutilsOptionError, cmd.ensure_string, 'option3')
-
- def test_ensure_string_list(self):
- cmd = self.cmd
- cmd.option1 = 'ok,dok'
- cmd.ensure_string_list('option1')
- self.assertEqual(cmd.option1, ['ok', 'dok'])
-
- cmd.option2 = ['xxx', 'www']
- cmd.ensure_string_list('option2')
-
- cmd.option3 = ['ok', 2]
- self.assertRaises(DistutilsOptionError, cmd.ensure_string_list,
- 'option3')
-
- def test_ensure_filename(self):
- cmd = self.cmd
- cmd.option1 = __file__
- cmd.ensure_filename('option1')
- cmd.option2 = 'xxx'
- self.assertRaises(DistutilsOptionError, cmd.ensure_filename, 'option2')
-
- def test_ensure_dirname(self):
- cmd = self.cmd
- cmd.option1 = os.path.dirname(__file__)
- cmd.ensure_dirname('option1')
- cmd.option2 = 'xxx'
- self.assertRaises(DistutilsOptionError, cmd.ensure_dirname, 'option2')
-
- def test_debug_print(self):
- cmd = self.cmd
- with captured_stdout() as stdout:
- cmd.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
-
- debug.DEBUG = True
- try:
- with captured_stdout() as stdout:
- cmd.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), 'xxx\n')
- finally:
- debug.DEBUG = False
-
-def test_suite():
- return unittest.makeSuite(CommandTestCase)
-
-if __name__ == '__main__':
- run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_config.py b/src/python/stdlib/distutils/tests/test_config.py
deleted file mode 100644
index 8d71234..0000000
--- a/src/python/stdlib/distutils/tests/test_config.py
+++ /dev/null
@@ -1,122 +0,0 @@
-"""Tests for distutils.pypirc.pypirc."""
-import sys
-import os
-import unittest
-import tempfile
-import shutil
-
-from distutils.core import PyPIRCCommand
-from distutils.core import Distribution
-from distutils.log import set_threshold
-from distutils.log import WARN
-
-from distutils.tests import support
-
-PYPIRC = """\
-[distutils]
-
-index-servers =
- server1
- server2
-
-[server1]
-username:me
-password:secret
-
-[server2]
-username:meagain
-password: secret
-realm:acme
-repository:http://another.pypi/
-"""
-
-PYPIRC_OLD = """\
-[server-login]
-username:tarek
-password:secret
-"""
-
-WANTED = """\
-[distutils]
-index-servers =
- pypi
-
-[pypi]
-username:tarek
-password:xxx
-"""
-
-
-class PyPIRCCommandTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- """Patches the environment."""
- super(PyPIRCCommandTestCase, self).setUp()
- self.tmp_dir = self.mkdtemp()
- os.environ['HOME'] = self.tmp_dir
- self.rc = os.path.join(self.tmp_dir, '.pypirc')
- self.dist = Distribution()
-
- class command(PyPIRCCommand):
- def __init__(self, dist):
- PyPIRCCommand.__init__(self, dist)
- def initialize_options(self):
- pass
- finalize_options = initialize_options
-
- self._cmd = command
- self.old_threshold = set_threshold(WARN)
-
- def tearDown(self):
- """Removes the patch."""
- set_threshold(self.old_threshold)
- super(PyPIRCCommandTestCase, self).tearDown()
-
- def test_server_registration(self):
- # This test makes sure PyPIRCCommand knows how to:
- # 1. handle several sections in .pypirc
- # 2. handle the old format
-
- # new format
- self.write_file(self.rc, PYPIRC)
- cmd = self._cmd(self.dist)
- config = cmd._read_pypirc()
-
- config = config.items()
- config.sort()
- waited = [('password', 'secret'), ('realm', 'pypi'),
- ('repository', 'http://pypi.python.org/pypi'),
- ('server', 'server1'), ('username', 'me')]
- self.assertEqual(config, waited)
-
- # old format
- self.write_file(self.rc, PYPIRC_OLD)
- config = cmd._read_pypirc()
- config = config.items()
- config.sort()
- waited = [('password', 'secret'), ('realm', 'pypi'),
- ('repository', 'http://pypi.python.org/pypi'),
- ('server', 'server-login'), ('username', 'tarek')]
- self.assertEqual(config, waited)
-
- def test_server_empty_registration(self):
- cmd = self._cmd(self.dist)
- rc = cmd._get_rc_file()
- self.assertTrue(not os.path.exists(rc))
- cmd._store_pypirc('tarek', 'xxx')
- self.assertTrue(os.path.exists(rc))
- f = open(rc)
- try:
- content = f.read()
- self.assertEqual(content, WANTED)
- finally:
- f.close()
-
-def test_suite():
- return unittest.makeSuite(PyPIRCCommandTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_config_cmd.py b/src/python/stdlib/distutils/tests/test_config_cmd.py
deleted file mode 100644
index fcb798e..0000000
--- a/src/python/stdlib/distutils/tests/test_config_cmd.py
+++ /dev/null
@@ -1,89 +0,0 @@
-"""Tests for distutils.command.config."""
-import unittest
-import os
-import sys
-
-from distutils.command.config import dump_file, config
-from distutils.tests import support
-from distutils import log
-
-class ConfigTestCase(support.LoggingSilencer,
- support.TempdirManager,
- unittest.TestCase):
-
- def _info(self, msg, *args):
- for line in msg.splitlines():
- self._logs.append(line)
-
- def setUp(self):
- super(ConfigTestCase, self).setUp()
- self._logs = []
- self.old_log = log.info
- log.info = self._info
-
- def tearDown(self):
- log.info = self.old_log
- super(ConfigTestCase, self).tearDown()
-
- def test_dump_file(self):
- this_file = os.path.splitext(__file__)[0] + '.py'
- f = open(this_file)
- try:
- numlines = len(f.readlines())
- finally:
- f.close()
-
- dump_file(this_file, 'I am the header')
- self.assertEqual(len(self._logs), numlines+1)
-
- def test_search_cpp(self):
- if sys.platform == 'win32':
- return
- pkg_dir, dist = self.create_dist()
- cmd = config(dist)
-
- # simple pattern searches
- match = cmd.search_cpp(pattern='xxx', body='// xxx')
- self.assertEqual(match, 0)
-
- match = cmd.search_cpp(pattern='_configtest', body='// xxx')
- self.assertEqual(match, 1)
-
- def test_finalize_options(self):
- # finalize_options does a bit of transformation
- # on options
- pkg_dir, dist = self.create_dist()
- cmd = config(dist)
- cmd.include_dirs = 'one%stwo' % os.pathsep
- cmd.libraries = 'one'
- cmd.library_dirs = 'three%sfour' % os.pathsep
- cmd.ensure_finalized()
-
- self.assertEqual(cmd.include_dirs, ['one', 'two'])
- self.assertEqual(cmd.libraries, ['one'])
- self.assertEqual(cmd.library_dirs, ['three', 'four'])
-
- def test_clean(self):
- # _clean removes files
- tmp_dir = self.mkdtemp()
- f1 = os.path.join(tmp_dir, 'one')
- f2 = os.path.join(tmp_dir, 'two')
-
- self.write_file(f1, 'xxx')
- self.write_file(f2, 'xxx')
-
- for f in (f1, f2):
- self.assertTrue(os.path.exists(f))
-
- pkg_dir, dist = self.create_dist()
- cmd = config(dist)
- cmd._clean(f1, f2)
-
- for f in (f1, f2):
- self.assertTrue(not os.path.exists(f))
-
-def test_suite():
- return unittest.makeSuite(ConfigTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_core.py b/src/python/stdlib/distutils/tests/test_core.py
deleted file mode 100644
index 74d1f3b..0000000
--- a/src/python/stdlib/distutils/tests/test_core.py
+++ /dev/null
@@ -1,108 +0,0 @@
-"""Tests for distutils.core."""
-
-import StringIO
-import distutils.core
-import os
-import shutil
-import sys
-import test.test_support
-from test.test_support import captured_stdout
-import unittest
-from distutils.tests import support
-
-# setup script that uses __file__
-setup_using___file__ = """\
-
-__file__
-
-from distutils.core import setup
-setup()
-"""
-
-setup_prints_cwd = """\
-
-import os
-print os.getcwd()
-
-from distutils.core import setup
-setup()
-"""
-
-
-class CoreTestCase(support.EnvironGuard, unittest.TestCase):
-
- def setUp(self):
- super(CoreTestCase, self).setUp()
- self.old_stdout = sys.stdout
- self.cleanup_testfn()
- self.old_argv = sys.argv, sys.argv[:]
-
- def tearDown(self):
- sys.stdout = self.old_stdout
- self.cleanup_testfn()
- sys.argv = self.old_argv[0]
- sys.argv[:] = self.old_argv[1]
- super(CoreTestCase, self).tearDown()
-
- def cleanup_testfn(self):
- path = test.test_support.TESTFN
- if os.path.isfile(path):
- os.remove(path)
- elif os.path.isdir(path):
- shutil.rmtree(path)
-
- def write_setup(self, text, path=test.test_support.TESTFN):
- f = open(path, "w")
- try:
- f.write(text)
- finally:
- f.close()
- return path
-
- def test_run_setup_provides_file(self):
- # Make sure the script can use __file__; if that's missing, the test
- # setup.py script will raise NameError.
- distutils.core.run_setup(
- self.write_setup(setup_using___file__))
-
- def test_run_setup_uses_current_dir(self):
- # This tests that the setup script is run with the current directory
- # as its own current directory; this was temporarily broken by a
- # previous patch when TESTFN did not use the current directory.
- sys.stdout = StringIO.StringIO()
- cwd = os.getcwd()
-
- # Create a directory and write the setup.py file there:
- os.mkdir(test.test_support.TESTFN)
- setup_py = os.path.join(test.test_support.TESTFN, "setup.py")
- distutils.core.run_setup(
- self.write_setup(setup_prints_cwd, path=setup_py))
-
- output = sys.stdout.getvalue()
- if output.endswith("\n"):
- output = output[:-1]
- self.assertEqual(cwd, output)
-
- def test_debug_mode(self):
- # this covers the code called when DEBUG is set
- sys.argv = ['setup.py', '--name']
- with captured_stdout() as stdout:
- distutils.core.setup(name='bar')
- stdout.seek(0)
- self.assertEqual(stdout.read(), 'bar\n')
-
- distutils.core.DEBUG = True
- try:
- with captured_stdout() as stdout:
- distutils.core.setup(name='bar')
- finally:
- distutils.core.DEBUG = False
- stdout.seek(0)
- wanted = "options (after parsing config files):\n"
- self.assertEqual(stdout.readlines()[0], wanted)
-
-def test_suite():
- return unittest.makeSuite(CoreTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_dep_util.py b/src/python/stdlib/distutils/tests/test_dep_util.py
deleted file mode 100644
index 3550819..0000000
--- a/src/python/stdlib/distutils/tests/test_dep_util.py
+++ /dev/null
@@ -1,80 +0,0 @@
-"""Tests for distutils.dep_util."""
-import unittest
-import os
-import time
-
-from distutils.dep_util import newer, newer_pairwise, newer_group
-from distutils.errors import DistutilsFileError
-from distutils.tests import support
-
-class DepUtilTestCase(support.TempdirManager, unittest.TestCase):
-
- def test_newer(self):
-
- tmpdir = self.mkdtemp()
- new_file = os.path.join(tmpdir, 'new')
- old_file = os.path.abspath(__file__)
-
- # Raise DistutilsFileError if 'new_file' does not exist.
- self.assertRaises(DistutilsFileError, newer, new_file, old_file)
-
- # Return true if 'new_file' exists and is more recently modified than
- # 'old_file', or if 'new_file' exists and 'old_file' doesn't.
- self.write_file(new_file)
- self.assertTrue(newer(new_file, 'I_dont_exist'))
- self.assertTrue(newer(new_file, old_file))
-
- # Return false if both exist and 'old_file' is the same age or younger
- # than 'new_file'.
- self.assertFalse(newer(old_file, new_file))
-
- def test_newer_pairwise(self):
- tmpdir = self.mkdtemp()
- sources = os.path.join(tmpdir, 'sources')
- targets = os.path.join(tmpdir, 'targets')
- os.mkdir(sources)
- os.mkdir(targets)
- one = os.path.join(sources, 'one')
- two = os.path.join(sources, 'two')
- three = os.path.abspath(__file__) # I am the old file
- four = os.path.join(targets, 'four')
- self.write_file(one)
- self.write_file(two)
- self.write_file(four)
-
- self.assertEqual(newer_pairwise([one, two], [three, four]),
- ([one],[three]))
-
- def test_newer_group(self):
- tmpdir = self.mkdtemp()
- sources = os.path.join(tmpdir, 'sources')
- os.mkdir(sources)
- one = os.path.join(sources, 'one')
- two = os.path.join(sources, 'two')
- three = os.path.join(sources, 'three')
- old_file = os.path.abspath(__file__)
-
- # return true if 'old_file' is out-of-date with respect to any file
- # listed in 'sources'.
- self.write_file(one)
- self.write_file(two)
- self.write_file(three)
- self.assertTrue(newer_group([one, two, three], old_file))
- self.assertFalse(newer_group([one, two, old_file], three))
-
- # missing handling
- os.remove(one)
- self.assertRaises(OSError, newer_group, [one, two, old_file], three)
-
- self.assertFalse(newer_group([one, two, old_file], three,
- missing='ignore'))
-
- self.assertTrue(newer_group([one, two, old_file], three,
- missing='newer'))
-
-
-def test_suite():
- return unittest.makeSuite(DepUtilTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_dir_util.py b/src/python/stdlib/distutils/tests/test_dir_util.py
deleted file mode 100644
index 84a0ec6..0000000
--- a/src/python/stdlib/distutils/tests/test_dir_util.py
+++ /dev/null
@@ -1,115 +0,0 @@
-"""Tests for distutils.dir_util."""
-import unittest
-import os
-import stat
-import shutil
-import sys
-
-from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree,
- ensure_relative)
-
-from distutils import log
-from distutils.tests import support
-
-class DirUtilTestCase(support.TempdirManager, unittest.TestCase):
-
- def _log(self, msg, *args):
- if len(args) > 0:
- self._logs.append(msg % args)
- else:
- self._logs.append(msg)
-
- def setUp(self):
- super(DirUtilTestCase, self).setUp()
- self._logs = []
- tmp_dir = self.mkdtemp()
- self.root_target = os.path.join(tmp_dir, 'deep')
- self.target = os.path.join(self.root_target, 'here')
- self.target2 = os.path.join(tmp_dir, 'deep2')
- self.old_log = log.info
- log.info = self._log
-
- def tearDown(self):
- log.info = self.old_log
- super(DirUtilTestCase, self).tearDown()
-
- def test_mkpath_remove_tree_verbosity(self):
-
- mkpath(self.target, verbose=0)
- wanted = []
- self.assertEqual(self._logs, wanted)
- remove_tree(self.root_target, verbose=0)
-
- mkpath(self.target, verbose=1)
- wanted = ['creating %s' % self.root_target,
- 'creating %s' % self.target]
- self.assertEqual(self._logs, wanted)
- self._logs = []
-
- remove_tree(self.root_target, verbose=1)
- wanted = ["removing '%s' (and everything under it)" % self.root_target]
- self.assertEqual(self._logs, wanted)
-
- @unittest.skipIf(sys.platform.startswith('win'),
- "This test is only appropriate for POSIX-like systems.")
- def test_mkpath_with_custom_mode(self):
- # Get and set the current umask value for testing mode bits.
- umask = os.umask(0o002)
- os.umask(umask)
- mkpath(self.target, 0o700)
- self.assertEqual(
- stat.S_IMODE(os.stat(self.target).st_mode), 0o700 & ~umask)
- mkpath(self.target2, 0o555)
- self.assertEqual(
- stat.S_IMODE(os.stat(self.target2).st_mode), 0o555 & ~umask)
-
- def test_create_tree_verbosity(self):
-
- create_tree(self.root_target, ['one', 'two', 'three'], verbose=0)
- self.assertEqual(self._logs, [])
- remove_tree(self.root_target, verbose=0)
-
- wanted = ['creating %s' % self.root_target]
- create_tree(self.root_target, ['one', 'two', 'three'], verbose=1)
- self.assertEqual(self._logs, wanted)
-
- remove_tree(self.root_target, verbose=0)
-
-
- def test_copy_tree_verbosity(self):
-
- mkpath(self.target, verbose=0)
-
- copy_tree(self.target, self.target2, verbose=0)
- self.assertEqual(self._logs, [])
-
- remove_tree(self.root_target, verbose=0)
-
- mkpath(self.target, verbose=0)
- a_file = os.path.join(self.target, 'ok.txt')
- f = open(a_file, 'w')
- try:
- f.write('some content')
- finally:
- f.close()
-
- wanted = ['copying %s -> %s' % (a_file, self.target2)]
- copy_tree(self.target, self.target2, verbose=1)
- self.assertEqual(self._logs, wanted)
-
- remove_tree(self.root_target, verbose=0)
- remove_tree(self.target2, verbose=0)
-
- def test_ensure_relative(self):
- if os.sep == '/':
- self.assertEqual(ensure_relative('/home/foo'), 'home/foo')
- self.assertEqual(ensure_relative('some/path'), 'some/path')
- else: # \\
- self.assertEqual(ensure_relative('c:\\home\\foo'), 'c:home\\foo')
- self.assertEqual(ensure_relative('home\\foo'), 'home\\foo')
-
-def test_suite():
- return unittest.makeSuite(DirUtilTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_dist.py b/src/python/stdlib/distutils/tests/test_dist.py
deleted file mode 100644
index 8ab7e9f..0000000
--- a/src/python/stdlib/distutils/tests/test_dist.py
+++ /dev/null
@@ -1,436 +0,0 @@
-# -*- coding: utf8 -*-
-
-"""Tests for distutils.dist."""
-import os
-import StringIO
-import sys
-import unittest
-import warnings
-import textwrap
-
-from distutils.dist import Distribution, fix_help_options, DistributionMetadata
-from distutils.cmd import Command
-import distutils.dist
-from test.test_support import TESTFN, captured_stdout
-from distutils.tests import support
-
-class test_dist(Command):
- """Sample distutils extension command."""
-
- user_options = [
- ("sample-option=", "S", "help text"),
- ]
-
- def initialize_options(self):
- self.sample_option = None
-
-
-class TestDistribution(Distribution):
- """Distribution subclasses that avoids the default search for
- configuration files.
-
- The ._config_files attribute must be set before
- .parse_config_files() is called.
- """
-
- def find_config_files(self):
- return self._config_files
-
-
-class DistributionTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- super(DistributionTestCase, self).setUp()
- self.argv = sys.argv, sys.argv[:]
- del sys.argv[1:]
-
- def tearDown(self):
- sys.argv = self.argv[0]
- sys.argv[:] = self.argv[1]
- super(DistributionTestCase, self).tearDown()
-
- def create_distribution(self, configfiles=()):
- d = TestDistribution()
- d._config_files = configfiles
- d.parse_config_files()
- d.parse_command_line()
- return d
-
- def test_debug_mode(self):
- with open(TESTFN, "w") as f:
- f.write("[global]")
- f.write("command_packages = foo.bar, splat")
-
- files = [TESTFN]
- sys.argv.append("build")
-
- with captured_stdout() as stdout:
- self.create_distribution(files)
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
- distutils.dist.DEBUG = True
- try:
- with captured_stdout() as stdout:
- self.create_distribution(files)
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
- finally:
- distutils.dist.DEBUG = False
-
- def test_command_packages_unspecified(self):
- sys.argv.append("build")
- d = self.create_distribution()
- self.assertEqual(d.get_command_packages(), ["distutils.command"])
-
- def test_command_packages_cmdline(self):
- from distutils.tests.test_dist import test_dist
- sys.argv.extend(["--command-packages",
- "foo.bar,distutils.tests",
- "test_dist",
- "-Ssometext",
- ])
- d = self.create_distribution()
- # let's actually try to load our test command:
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "foo.bar", "distutils.tests"])
- cmd = d.get_command_obj("test_dist")
- self.assertTrue(isinstance(cmd, test_dist))
- self.assertEqual(cmd.sample_option, "sometext")
-
- def test_command_packages_configfile(self):
- sys.argv.append("build")
- self.addCleanup(os.unlink, TESTFN)
- f = open(TESTFN, "w")
- try:
- print >>f, "[global]"
- print >>f, "command_packages = foo.bar, splat"
- finally:
- f.close()
-
- d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "foo.bar", "splat"])
-
- # ensure command line overrides config:
- sys.argv[1:] = ["--command-packages", "spork", "build"]
- d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(),
- ["distutils.command", "spork"])
-
- # Setting --command-packages to '' should cause the default to
- # be used even if a config file specified something else:
- sys.argv[1:] = ["--command-packages", "", "build"]
- d = self.create_distribution([TESTFN])
- self.assertEqual(d.get_command_packages(), ["distutils.command"])
-
- def test_write_pkg_file(self):
- # Check DistributionMetadata handling of Unicode fields
- tmp_dir = self.mkdtemp()
- my_file = os.path.join(tmp_dir, 'f')
- klass = Distribution
-
- dist = klass(attrs={'author': u'Mister Café',
- 'name': 'my.package',
- 'maintainer': u'Café Junior',
- 'description': u'Café torréfié',
- 'long_description': u'Héhéhé'})
-
-
- # let's make sure the file can be written
- # with Unicode fields. they are encoded with
- # PKG_INFO_ENCODING
- dist.metadata.write_pkg_file(open(my_file, 'w'))
-
- # regular ascii is of course always usable
- dist = klass(attrs={'author': 'Mister Cafe',
- 'name': 'my.package',
- 'maintainer': 'Cafe Junior',
- 'description': 'Cafe torrefie',
- 'long_description': 'Hehehe'})
-
- my_file2 = os.path.join(tmp_dir, 'f2')
- dist.metadata.write_pkg_file(open(my_file, 'w'))
-
- def test_empty_options(self):
- # an empty options dictionary should not stay in the
- # list of attributes
- klass = Distribution
-
- # catching warnings
- warns = []
- def _warn(msg):
- warns.append(msg)
-
- old_warn = warnings.warn
- warnings.warn = _warn
- try:
- dist = klass(attrs={'author': 'xxx',
- 'name': 'xxx',
- 'version': 'xxx',
- 'url': 'xxxx',
- 'options': {}})
- finally:
- warnings.warn = old_warn
-
- self.assertEqual(len(warns), 0)
-
- def test_finalize_options(self):
-
- attrs = {'keywords': 'one,two',
- 'platforms': 'one,two'}
-
- dist = Distribution(attrs=attrs)
- dist.finalize_options()
-
- # finalize_option splits platforms and keywords
- self.assertEqual(dist.metadata.platforms, ['one', 'two'])
- self.assertEqual(dist.metadata.keywords, ['one', 'two'])
-
- def test_get_command_packages(self):
- dist = Distribution()
- self.assertEqual(dist.command_packages, None)
- cmds = dist.get_command_packages()
- self.assertEqual(cmds, ['distutils.command'])
- self.assertEqual(dist.command_packages,
- ['distutils.command'])
-
- dist.command_packages = 'one,two'
- cmds = dist.get_command_packages()
- self.assertEqual(cmds, ['distutils.command', 'one', 'two'])
-
-
- def test_announce(self):
- # make sure the level is known
- dist = Distribution()
- args = ('ok',)
- kwargs = {'level': 'ok2'}
- self.assertRaises(ValueError, dist.announce, args, kwargs)
-
- def test_find_config_files_disable(self):
- # Ticket #1180: Allow user to disable their home config file.
- temp_home = self.mkdtemp()
- if os.name == 'posix':
- user_filename = os.path.join(temp_home, ".pydistutils.cfg")
- else:
- user_filename = os.path.join(temp_home, "pydistutils.cfg")
-
- with open(user_filename, 'w') as f:
- f.write('[distutils]\n')
-
- def _expander(path):
- return temp_home
-
- old_expander = os.path.expanduser
- os.path.expanduser = _expander
- try:
- d = distutils.dist.Distribution()
- all_files = d.find_config_files()
-
- d = distutils.dist.Distribution(attrs={'script_args':
- ['--no-user-cfg']})
- files = d.find_config_files()
- finally:
- os.path.expanduser = old_expander
-
- # make sure --no-user-cfg disables the user cfg file
- self.assertEqual(len(all_files)-1, len(files))
-
-
-class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
- unittest.TestCase):
-
- def setUp(self):
- super(MetadataTestCase, self).setUp()
- self.argv = sys.argv, sys.argv[:]
-
- def tearDown(self):
- sys.argv = self.argv[0]
- sys.argv[:] = self.argv[1]
- super(MetadataTestCase, self).tearDown()
-
- def test_simple_metadata(self):
- attrs = {"name": "package",
- "version": "1.0"}
- dist = Distribution(attrs)
- meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.0" in meta)
- self.assertTrue("provides:" not in meta.lower())
- self.assertTrue("requires:" not in meta.lower())
- self.assertTrue("obsoletes:" not in meta.lower())
-
- def test_provides(self):
- attrs = {"name": "package",
- "version": "1.0",
- "provides": ["package", "package.sub"]}
- dist = Distribution(attrs)
- self.assertEqual(dist.metadata.get_provides(),
- ["package", "package.sub"])
- self.assertEqual(dist.get_provides(),
- ["package", "package.sub"])
- meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.1" in meta)
- self.assertTrue("requires:" not in meta.lower())
- self.assertTrue("obsoletes:" not in meta.lower())
-
- def test_provides_illegal(self):
- self.assertRaises(ValueError, Distribution,
- {"name": "package",
- "version": "1.0",
- "provides": ["my.pkg (splat)"]})
-
- def test_requires(self):
- attrs = {"name": "package",
- "version": "1.0",
- "requires": ["other", "another (==1.0)"]}
- dist = Distribution(attrs)
- self.assertEqual(dist.metadata.get_requires(),
- ["other", "another (==1.0)"])
- self.assertEqual(dist.get_requires(),
- ["other", "another (==1.0)"])
- meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.1" in meta)
- self.assertTrue("provides:" not in meta.lower())
- self.assertTrue("Requires: other" in meta)
- self.assertTrue("Requires: another (==1.0)" in meta)
- self.assertTrue("obsoletes:" not in meta.lower())
-
- def test_requires_illegal(self):
- self.assertRaises(ValueError, Distribution,
- {"name": "package",
- "version": "1.0",
- "requires": ["my.pkg (splat)"]})
-
- def test_obsoletes(self):
- attrs = {"name": "package",
- "version": "1.0",
- "obsoletes": ["other", "another (<1.0)"]}
- dist = Distribution(attrs)
- self.assertEqual(dist.metadata.get_obsoletes(),
- ["other", "another (<1.0)"])
- self.assertEqual(dist.get_obsoletes(),
- ["other", "another (<1.0)"])
- meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.1" in meta)
- self.assertTrue("provides:" not in meta.lower())
- self.assertTrue("requires:" not in meta.lower())
- self.assertTrue("Obsoletes: other" in meta)
- self.assertTrue("Obsoletes: another (<1.0)" in meta)
-
- def test_obsoletes_illegal(self):
- self.assertRaises(ValueError, Distribution,
- {"name": "package",
- "version": "1.0",
- "obsoletes": ["my.pkg (splat)"]})
-
- def format_metadata(self, dist):
- sio = StringIO.StringIO()
- dist.metadata.write_pkg_file(sio)
- return sio.getvalue()
-
- def test_custom_pydistutils(self):
- # fixes #2166
- # make sure pydistutils.cfg is found
- if os.name == 'posix':
- user_filename = ".pydistutils.cfg"
- else:
- user_filename = "pydistutils.cfg"
-
- temp_dir = self.mkdtemp()
- user_filename = os.path.join(temp_dir, user_filename)
- f = open(user_filename, 'w')
- try:
- f.write('.')
- finally:
- f.close()
-
- try:
- dist = Distribution()
-
- # linux-style
- if sys.platform in ('linux', 'darwin'):
- os.environ['HOME'] = temp_dir
- files = dist.find_config_files()
- self.assertTrue(user_filename in files)
-
- # win32-style
- if sys.platform == 'win32':
- # home drive should be found
- os.environ['HOME'] = temp_dir
- files = dist.find_config_files()
- self.assertTrue(user_filename in files,
- '%r not found in %r' % (user_filename, files))
- finally:
- os.remove(user_filename)
-
- def test_fix_help_options(self):
- help_tuples = [('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
- fancy_options = fix_help_options(help_tuples)
- self.assertEqual(fancy_options[0], ('a', 'b', 'c'))
- self.assertEqual(fancy_options[1], (1, 2, 3))
-
- def test_show_help(self):
- # smoke test, just makes sure some help is displayed
- dist = Distribution()
- sys.argv = []
- dist.help = 1
- dist.script_name = 'setup.py'
- with captured_stdout() as s:
- dist.parse_command_line()
-
- output = [line for line in s.getvalue().split('\n')
- if line.strip() != '']
- self.assertTrue(len(output) > 0)
-
- def test_long_description(self):
- long_desc = textwrap.dedent("""\
- example::
- We start here
- and continue here
- and end here.""")
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": long_desc}
-
- dist = distutils.dist.Distribution(attrs)
- meta = self.format_metadata(dist)
- meta = meta.replace('\n' + 8 * ' ', '\n')
- self.assertTrue(long_desc in meta)
-
- def test_read_metadata(self):
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": "desc",
- "description": "xxx",
- "download_url": "http://example.com",
- "keywords": ['one', 'two'],
- "requires": ['foo']}
-
- dist = Distribution(attrs)
- metadata = dist.metadata
-
- # write it then reloads it
- PKG_INFO = StringIO.StringIO()
- metadata.write_pkg_file(PKG_INFO)
- PKG_INFO.seek(0)
- metadata.read_pkg_file(PKG_INFO)
-
- self.assertEqual(metadata.name, "package")
- self.assertEqual(metadata.version, "1.0")
- self.assertEqual(metadata.description, "xxx")
- self.assertEqual(metadata.download_url, 'http://example.com')
- self.assertEqual(metadata.keywords, ['one', 'two'])
- self.assertEqual(metadata.platforms, ['UNKNOWN'])
- self.assertEqual(metadata.obsoletes, None)
- self.assertEqual(metadata.requires, ['foo'])
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(DistributionTestCase))
- suite.addTest(unittest.makeSuite(MetadataTestCase))
- return suite
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_file_util.py b/src/python/stdlib/distutils/tests/test_file_util.py
deleted file mode 100644
index dbc6283..0000000
--- a/src/python/stdlib/distutils/tests/test_file_util.py
+++ /dev/null
@@ -1,80 +0,0 @@
-"""Tests for distutils.file_util."""
-import unittest
-import os
-import shutil
-
-from distutils.file_util import move_file, write_file, copy_file
-from distutils import log
-from distutils.tests import support
-
-class FileUtilTestCase(support.TempdirManager, unittest.TestCase):
-
- def _log(self, msg, *args):
- if len(args) > 0:
- self._logs.append(msg % args)
- else:
- self._logs.append(msg)
-
- def setUp(self):
- super(FileUtilTestCase, self).setUp()
- self._logs = []
- self.old_log = log.info
- log.info = self._log
- tmp_dir = self.mkdtemp()
- self.source = os.path.join(tmp_dir, 'f1')
- self.target = os.path.join(tmp_dir, 'f2')
- self.target_dir = os.path.join(tmp_dir, 'd1')
-
- def tearDown(self):
- log.info = self.old_log
- super(FileUtilTestCase, self).tearDown()
-
- def test_move_file_verbosity(self):
- f = open(self.source, 'w')
- try:
- f.write('some content')
- finally:
- f.close()
-
- move_file(self.source, self.target, verbose=0)
- wanted = []
- self.assertEqual(self._logs, wanted)
-
- # back to original state
- move_file(self.target, self.source, verbose=0)
-
- move_file(self.source, self.target, verbose=1)
- wanted = ['moving %s -> %s' % (self.source, self.target)]
- self.assertEqual(self._logs, wanted)
-
- # back to original state
- move_file(self.target, self.source, verbose=0)
-
- self._logs = []
- # now the target is a dir
- os.mkdir(self.target_dir)
- move_file(self.source, self.target_dir, verbose=1)
- wanted = ['moving %s -> %s' % (self.source, self.target_dir)]
- self.assertEqual(self._logs, wanted)
-
- def test_write_file(self):
- lines = ['a', 'b', 'c']
- dir = self.mkdtemp()
- foo = os.path.join(dir, 'foo')
- write_file(foo, lines)
- content = [line.strip() for line in open(foo).readlines()]
- self.assertEqual(content, lines)
-
- def test_copy_file(self):
- src_dir = self.mkdtemp()
- foo = os.path.join(src_dir, 'foo')
- write_file(foo, 'content')
- dst_dir = self.mkdtemp()
- copy_file(foo, dst_dir)
- self.assertTrue(os.path.exists(os.path.join(dst_dir, 'foo')))
-
-def test_suite():
- return unittest.makeSuite(FileUtilTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_filelist.py b/src/python/stdlib/distutils/tests/test_filelist.py
deleted file mode 100644
index 32c56c7..0000000
--- a/src/python/stdlib/distutils/tests/test_filelist.py
+++ /dev/null
@@ -1,85 +0,0 @@
-"""Tests for distutils.filelist."""
-from os.path import join
-import unittest
-from test.test_support import captured_stdout
-
-from distutils.filelist import glob_to_re, FileList
-from distutils import debug
-
-MANIFEST_IN = """\
-include ok
-include xo
-exclude xo
-include foo.tmp
-global-include *.x
-global-include *.txt
-global-exclude *.tmp
-recursive-include f *.oo
-recursive-exclude global *.x
-graft dir
-prune dir3
-"""
-
-class FileListTestCase(unittest.TestCase):
-
- def test_glob_to_re(self):
- # simple cases
- self.assertEqual(glob_to_re('foo*'), 'foo[^/]*\\Z(?ms)')
- self.assertEqual(glob_to_re('foo?'), 'foo[^/]\\Z(?ms)')
- self.assertEqual(glob_to_re('foo??'), 'foo[^/][^/]\\Z(?ms)')
-
- # special cases
- self.assertEqual(glob_to_re(r'foo\\*'), r'foo\\\\[^/]*\Z(?ms)')
- self.assertEqual(glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*\Z(?ms)')
- self.assertEqual(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
- self.assertEqual(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
-
- def test_process_template_line(self):
- # testing all MANIFEST.in template patterns
- file_list = FileList()
-
- # simulated file list
- file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt',
- join('global', 'one.txt'),
- join('global', 'two.txt'),
- join('global', 'files.x'),
- join('global', 'here.tmp'),
- join('f', 'o', 'f.oo'),
- join('dir', 'graft-one'),
- join('dir', 'dir2', 'graft2'),
- join('dir3', 'ok'),
- join('dir3', 'sub', 'ok.txt')
- ]
-
- for line in MANIFEST_IN.split('\n'):
- if line.strip() == '':
- continue
- file_list.process_template_line(line)
-
- wanted = ['ok', 'four.txt', join('global', 'one.txt'),
- join('global', 'two.txt'), join('f', 'o', 'f.oo'),
- join('dir', 'graft-one'), join('dir', 'dir2', 'graft2')]
-
- self.assertEqual(file_list.files, wanted)
-
- def test_debug_print(self):
- file_list = FileList()
- with captured_stdout() as stdout:
- file_list.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), '')
-
- debug.DEBUG = True
- try:
- with captured_stdout() as stdout:
- file_list.debug_print('xxx')
- stdout.seek(0)
- self.assertEqual(stdout.read(), 'xxx\n')
- finally:
- debug.DEBUG = False
-
-def test_suite():
- return unittest.makeSuite(FileListTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_install.py b/src/python/stdlib/distutils/tests/test_install.py
deleted file mode 100644
index c834b91..0000000
--- a/src/python/stdlib/distutils/tests/test_install.py
+++ /dev/null
@@ -1,55 +0,0 @@
-"""Tests for distutils.command.install."""
-
-import os
-import unittest
-
-from distutils.command.install import install
-from distutils.core import Distribution
-
-from distutils.tests import support
-
-
-class InstallTestCase(support.TempdirManager, unittest.TestCase):
-
- def test_home_installation_scheme(self):
- # This ensure two things:
- # - that --home generates the desired set of directory names
- # - test --home is supported on all platforms
- builddir = self.mkdtemp()
- destination = os.path.join(builddir, "installation")
-
- dist = Distribution({"name": "foopkg"})
- # script_name need not exist, it just need to be initialized
- dist.script_name = os.path.join(builddir, "setup.py")
- dist.command_obj["build"] = support.DummyCommand(
- build_base=builddir,
- build_lib=os.path.join(builddir, "lib"),
- )
-
- cmd = install(dist)
- cmd.home = destination
- cmd.ensure_finalized()
-
- self.assertEqual(cmd.install_base, destination)
- self.assertEqual(cmd.install_platbase, destination)
-
- def check_path(got, expected):
- got = os.path.normpath(got)
- expected = os.path.normpath(expected)
- self.assertEqual(got, expected)
-
- libdir = os.path.join(destination, "lib", "python")
- check_path(cmd.install_lib, libdir)
- check_path(cmd.install_platlib, libdir)
- check_path(cmd.install_purelib, libdir)
- check_path(cmd.install_headers,
- os.path.join(destination, "include", "python", "foopkg"))
- check_path(cmd.install_scripts, os.path.join(destination, "bin"))
- check_path(cmd.install_data, destination)
-
-
-def test_suite():
- return unittest.makeSuite(InstallTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_install_data.py b/src/python/stdlib/distutils/tests/test_install_data.py
deleted file mode 100644
index 86db4a1..0000000
--- a/src/python/stdlib/distutils/tests/test_install_data.py
+++ /dev/null
@@ -1,76 +0,0 @@
-"""Tests for distutils.command.install_data."""
-import sys
-import os
-import unittest
-import getpass
-
-from distutils.command.install_data import install_data
-from distutils.tests import support
-
-class InstallDataTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def test_simple_run(self):
- pkg_dir, dist = self.create_dist()
- cmd = install_data(dist)
- cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
-
- # data_files can contain
- # - simple files
- # - a tuple with a path, and a list of file
- one = os.path.join(pkg_dir, 'one')
- self.write_file(one, 'xxx')
- inst2 = os.path.join(pkg_dir, 'inst2')
- two = os.path.join(pkg_dir, 'two')
- self.write_file(two, 'xxx')
-
- cmd.data_files = [one, (inst2, [two])]
- self.assertEqual(cmd.get_inputs(), [one, (inst2, [two])])
-
- # let's run the command
- cmd.ensure_finalized()
- cmd.run()
-
- # let's check the result
- self.assertEqual(len(cmd.get_outputs()), 2)
- rtwo = os.path.split(two)[-1]
- self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
- rone = os.path.split(one)[-1]
- self.assertTrue(os.path.exists(os.path.join(inst, rone)))
- cmd.outfiles = []
-
- # let's try with warn_dir one
- cmd.warn_dir = 1
- cmd.ensure_finalized()
- cmd.run()
-
- # let's check the result
- self.assertEqual(len(cmd.get_outputs()), 2)
- self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
- self.assertTrue(os.path.exists(os.path.join(inst, rone)))
- cmd.outfiles = []
-
- # now using root and empty dir
- cmd.root = os.path.join(pkg_dir, 'root')
- inst3 = os.path.join(cmd.install_dir, 'inst3')
- inst4 = os.path.join(pkg_dir, 'inst4')
- three = os.path.join(cmd.install_dir, 'three')
- self.write_file(three, 'xx')
- cmd.data_files = [one, (inst2, [two]),
- ('inst3', [three]),
- (inst4, [])]
- cmd.ensure_finalized()
- cmd.run()
-
- # let's check the result
- self.assertEqual(len(cmd.get_outputs()), 4)
- self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
- self.assertTrue(os.path.exists(os.path.join(inst, rone)))
-
-def test_suite():
- return unittest.makeSuite(InstallDataTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_install_headers.py b/src/python/stdlib/distutils/tests/test_install_headers.py
deleted file mode 100644
index aa8a4e6..0000000
--- a/src/python/stdlib/distutils/tests/test_install_headers.py
+++ /dev/null
@@ -1,40 +0,0 @@
-"""Tests for distutils.command.install_headers."""
-import sys
-import os
-import unittest
-import getpass
-
-from distutils.command.install_headers import install_headers
-from distutils.tests import support
-
-class InstallHeadersTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def test_simple_run(self):
- # we have two headers
- header_list = self.mkdtemp()
- header1 = os.path.join(header_list, 'header1')
- header2 = os.path.join(header_list, 'header2')
- self.write_file(header1)
- self.write_file(header2)
- headers = [header1, header2]
-
- pkg_dir, dist = self.create_dist(headers=headers)
- cmd = install_headers(dist)
- self.assertEqual(cmd.get_inputs(), headers)
-
- # let's run the command
- cmd.install_dir = os.path.join(pkg_dir, 'inst')
- cmd.ensure_finalized()
- cmd.run()
-
- # let's check the results
- self.assertEqual(len(cmd.get_outputs()), 2)
-
-def test_suite():
- return unittest.makeSuite(InstallHeadersTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_install_lib.py b/src/python/stdlib/distutils/tests/test_install_lib.py
deleted file mode 100644
index 754ea63..0000000
--- a/src/python/stdlib/distutils/tests/test_install_lib.py
+++ /dev/null
@@ -1,106 +0,0 @@
-"""Tests for distutils.command.install_data."""
-import os
-import sys
-import unittest
-
-from distutils.command.install_lib import install_lib
-from distutils.extension import Extension
-from distutils.tests import support
-from distutils.errors import DistutilsOptionError
-
-class InstallLibTestCase(support.TempdirManager,
- support.LoggingSilencer,
- support.EnvironGuard,
- unittest.TestCase):
-
- def test_finalize_options(self):
- pkg_dir, dist = self.create_dist()
- cmd = install_lib(dist)
-
- cmd.finalize_options()
- self.assertEqual(cmd.compile, 1)
- self.assertEqual(cmd.optimize, 0)
-
- # optimize must be 0, 1, or 2
- cmd.optimize = 'foo'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
- cmd.optimize = '4'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
-
- cmd.optimize = '2'
- cmd.finalize_options()
- self.assertEqual(cmd.optimize, 2)
-
- def _setup_byte_compile(self):
- pkg_dir, dist = self.create_dist()
- cmd = install_lib(dist)
- cmd.compile = cmd.optimize = 1
-
- f = os.path.join(pkg_dir, 'foo.py')
- self.write_file(f, '# python file')
- cmd.byte_compile([f])
- return pkg_dir
-
- @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile not enabled')
- def test_byte_compile(self):
- pkg_dir = self._setup_byte_compile()
- if sys.flags.optimize < 1:
- self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
- else:
- self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
-
- def test_get_outputs(self):
- pkg_dir, dist = self.create_dist()
- cmd = install_lib(dist)
-
- # setting up a dist environment
- cmd.compile = cmd.optimize = 1
- cmd.install_dir = pkg_dir
- f = os.path.join(pkg_dir, 'foo.py')
- self.write_file(f, '# python file')
- cmd.distribution.py_modules = [pkg_dir]
- cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
- cmd.distribution.packages = [pkg_dir]
- cmd.distribution.script_name = 'setup.py'
-
- # get_output should return 4 elements
- self.assertTrue(len(cmd.get_outputs()) >= 2)
-
- def test_get_inputs(self):
- pkg_dir, dist = self.create_dist()
- cmd = install_lib(dist)
-
- # setting up a dist environment
- cmd.compile = cmd.optimize = 1
- cmd.install_dir = pkg_dir
- f = os.path.join(pkg_dir, 'foo.py')
- self.write_file(f, '# python file')
- cmd.distribution.py_modules = [pkg_dir]
- cmd.distribution.ext_modules = [Extension('foo', ['xxx'])]
- cmd.distribution.packages = [pkg_dir]
- cmd.distribution.script_name = 'setup.py'
-
- # get_input should return 2 elements
- self.assertEqual(len(cmd.get_inputs()), 2)
-
- def test_dont_write_bytecode(self):
- # makes sure byte_compile is not used
- pkg_dir, dist = self.create_dist()
- cmd = install_lib(dist)
- cmd.compile = 1
- cmd.optimize = 1
-
- old_dont_write_bytecode = sys.dont_write_bytecode
- sys.dont_write_bytecode = True
- try:
- cmd.byte_compile([])
- finally:
- sys.dont_write_bytecode = old_dont_write_bytecode
-
- self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
-
-def test_suite():
- return unittest.makeSuite(InstallLibTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_install_scripts.py b/src/python/stdlib/distutils/tests/test_install_scripts.py
deleted file mode 100644
index 08360d2..0000000
--- a/src/python/stdlib/distutils/tests/test_install_scripts.py
+++ /dev/null
@@ -1,81 +0,0 @@
-"""Tests for distutils.command.install_scripts."""
-
-import os
-import unittest
-
-from distutils.command.install_scripts import install_scripts
-from distutils.core import Distribution
-
-from distutils.tests import support
-
-
-class InstallScriptsTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_default_settings(self):
- dist = Distribution()
- dist.command_obj["build"] = support.DummyCommand(
- build_scripts="/foo/bar")
- dist.command_obj["install"] = support.DummyCommand(
- install_scripts="/splat/funk",
- force=1,
- skip_build=1,
- )
- cmd = install_scripts(dist)
- self.assertTrue(not cmd.force)
- self.assertTrue(not cmd.skip_build)
- self.assertTrue(cmd.build_dir is None)
- self.assertTrue(cmd.install_dir is None)
-
- cmd.finalize_options()
-
- self.assertTrue(cmd.force)
- self.assertTrue(cmd.skip_build)
- self.assertEqual(cmd.build_dir, "/foo/bar")
- self.assertEqual(cmd.install_dir, "/splat/funk")
-
- def test_installation(self):
- source = self.mkdtemp()
- expected = []
-
- def write_script(name, text):
- expected.append(name)
- f = open(os.path.join(source, name), "w")
- try:
- f.write(text)
- finally:
- f.close()
-
- write_script("script1.py", ("#! /usr/bin/env python2.3\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
- write_script("script2.py", ("#!/usr/bin/python\n"
- "# bogus script w/ Python sh-bang\n"
- "pass\n"))
- write_script("shell.sh", ("#!/bin/sh\n"
- "# bogus shell script w/ sh-bang\n"
- "exit 0\n"))
-
- target = self.mkdtemp()
- dist = Distribution()
- dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
- dist.command_obj["install"] = support.DummyCommand(
- install_scripts=target,
- force=1,
- skip_build=1,
- )
- cmd = install_scripts(dist)
- cmd.finalize_options()
- cmd.run()
-
- installed = os.listdir(target)
- for name in expected:
- self.assertTrue(name in installed)
-
-
-def test_suite():
- return unittest.makeSuite(InstallScriptsTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_msvc9compiler.py b/src/python/stdlib/distutils/tests/test_msvc9compiler.py
deleted file mode 100644
index b8e2209..0000000
--- a/src/python/stdlib/distutils/tests/test_msvc9compiler.py
+++ /dev/null
@@ -1,140 +0,0 @@
-"""Tests for distutils.msvc9compiler."""
-import sys
-import unittest
-import os
-
-from distutils.errors import DistutilsPlatformError
-from distutils.tests import support
-
-_MANIFEST = """\
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="XXXX">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="XXXX"></assemblyIdentity>
- </dependentAssembly>
- </dependency>
-</assembly>
-"""
-
-_CLEANED_MANIFEST = """\
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
-
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="XXXX"></assemblyIdentity>
- </dependentAssembly>
- </dependency>
-</assembly>"""
-
-if sys.platform=="win32":
- from distutils.msvccompiler import get_build_version
- if get_build_version()>=8.0:
- SKIP_MESSAGE = None
- else:
- SKIP_MESSAGE = "These tests are only for MSVC8.0 or above"
-else:
- SKIP_MESSAGE = "These tests are only for win32"
-
-@unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE)
-class msvc9compilerTestCase(support.TempdirManager,
- unittest.TestCase):
-
- def test_no_compiler(self):
- # makes sure query_vcvarsall throws
- # a DistutilsPlatformError if the compiler
- # is not found
- from distutils.msvc9compiler import query_vcvarsall
- def _find_vcvarsall(version):
- return None
-
- from distutils import msvc9compiler
- old_find_vcvarsall = msvc9compiler.find_vcvarsall
- msvc9compiler.find_vcvarsall = _find_vcvarsall
- try:
- self.assertRaises(DistutilsPlatformError, query_vcvarsall,
- 'wont find this version')
- finally:
- msvc9compiler.find_vcvarsall = old_find_vcvarsall
-
- def test_reg_class(self):
- from distutils.msvc9compiler import Reg
- self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
-
- # looking for values that should exist on all
- # windows registeries versions.
- path = r'Control Panel\Desktop'
- v = Reg.get_value(path, u'dragfullwindows')
- self.assertTrue(v in (u'0', u'1', u'2'))
-
- import _winreg
- HKCU = _winreg.HKEY_CURRENT_USER
- keys = Reg.read_keys(HKCU, 'xxxx')
- self.assertEqual(keys, None)
-
- keys = Reg.read_keys(HKCU, r'Control Panel')
- self.assertTrue('Desktop' in keys)
-
- def test_remove_visual_c_ref(self):
- from distutils.msvc9compiler import MSVCCompiler
- tempdir = self.mkdtemp()
- manifest = os.path.join(tempdir, 'manifest')
- f = open(manifest, 'w')
- try:
- f.write(_MANIFEST)
- finally:
- f.close()
-
- compiler = MSVCCompiler()
- compiler._remove_visual_c_ref(manifest)
-
- # see what we got
- f = open(manifest)
- try:
- # removing trailing spaces
- content = '\n'.join([line.rstrip() for line in f.readlines()])
- finally:
- f.close()
-
- # makes sure the manifest was properly cleaned
- self.assertEqual(content, _CLEANED_MANIFEST)
-
-
-def test_suite():
- return unittest.makeSuite(msvc9compilerTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_register.py b/src/python/stdlib/distutils/tests/test_register.py
deleted file mode 100644
index 915427b..0000000
--- a/src/python/stdlib/distutils/tests/test_register.py
+++ /dev/null
@@ -1,261 +0,0 @@
-"""Tests for distutils.command.register."""
-# -*- encoding: utf8 -*-
-import sys
-import os
-import unittest
-import getpass
-import urllib2
-import warnings
-
-from test.test_support import check_warnings
-
-from distutils.command import register as register_module
-from distutils.command.register import register
-from distutils.core import Distribution
-from distutils.errors import DistutilsSetupError
-
-from distutils.tests import support
-from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
-
-PYPIRC_NOPASSWORD = """\
-[distutils]
-
-index-servers =
- server1
-
-[server1]
-username:me
-"""
-
-WANTED_PYPIRC = """\
-[distutils]
-index-servers =
- pypi
-
-[pypi]
-username:tarek
-password:password
-"""
-
-class RawInputs(object):
- """Fakes user inputs."""
- def __init__(self, *answers):
- self.answers = answers
- self.index = 0
-
- def __call__(self, prompt=''):
- try:
- return self.answers[self.index]
- finally:
- self.index += 1
-
-class FakeOpener(object):
- """Fakes a PyPI server"""
- def __init__(self):
- self.reqs = []
-
- def __call__(self, *args):
- return self
-
- def open(self, req):
- self.reqs.append(req)
- return self
-
- def read(self):
- return 'xxx'
-
-class RegisterTestCase(PyPIRCCommandTestCase):
-
- def setUp(self):
- super(RegisterTestCase, self).setUp()
- # patching the password prompt
- self._old_getpass = getpass.getpass
- def _getpass(prompt):
- return 'password'
- getpass.getpass = _getpass
- self.old_opener = urllib2.build_opener
- self.conn = urllib2.build_opener = FakeOpener()
-
- def tearDown(self):
- getpass.getpass = self._old_getpass
- urllib2.build_opener = self.old_opener
- super(RegisterTestCase, self).tearDown()
-
- def _get_cmd(self, metadata=None):
- if metadata is None:
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx',
- 'name': 'xxx', 'version': 'xxx'}
- pkg_info, dist = self.create_dist(**metadata)
- return register(dist)
-
- def test_create_pypirc(self):
- # this test makes sure a .pypirc file
- # is created when requested.
-
- # let's create a register instance
- cmd = self._get_cmd()
-
- # we shouldn't have a .pypirc file yet
- self.assertTrue(not os.path.exists(self.rc))
-
- # patching raw_input and getpass.getpass
- # so register gets happy
- #
- # Here's what we are faking :
- # use your existing login (choice 1.)
- # Username : 'tarek'
- # Password : 'password'
- # Save your login (y/N)? : 'y'
- inputs = RawInputs('1', 'tarek', 'y')
- register_module.raw_input = inputs.__call__
- # let's run the command
- try:
- cmd.run()
- finally:
- del register_module.raw_input
-
- # we should have a brand new .pypirc file
- self.assertTrue(os.path.exists(self.rc))
-
- # with the content similar to WANTED_PYPIRC
- f = open(self.rc)
- try:
- content = f.read()
- self.assertEqual(content, WANTED_PYPIRC)
- finally:
- f.close()
-
- # now let's make sure the .pypirc file generated
- # really works : we shouldn't be asked anything
- # if we run the command again
- def _no_way(prompt=''):
- raise AssertionError(prompt)
- register_module.raw_input = _no_way
-
- cmd.show_response = 1
- cmd.run()
-
- # let's see what the server received : we should
- # have 2 similar requests
- self.assertTrue(self.conn.reqs, 2)
- req1 = dict(self.conn.reqs[0].headers)
- req2 = dict(self.conn.reqs[1].headers)
- self.assertEqual(req2['Content-length'], req1['Content-length'])
- self.assertTrue('xxx' in self.conn.reqs[1].data)
-
- def test_password_not_in_file(self):
-
- self.write_file(self.rc, PYPIRC_NOPASSWORD)
- cmd = self._get_cmd()
- cmd._set_config()
- cmd.finalize_options()
- cmd.send_metadata()
-
- # dist.password should be set
- # therefore used afterwards by other commands
- self.assertEqual(cmd.distribution.password, 'password')
-
- def test_registering(self):
- # this test runs choice 2
- cmd = self._get_cmd()
- inputs = RawInputs('2', 'tarek', 'tarek@ziade.org')
- register_module.raw_input = inputs.__call__
- try:
- # let's run the command
- cmd.run()
- finally:
- del register_module.raw_input
-
- # we should have send a request
- self.assertTrue(self.conn.reqs, 1)
- req = self.conn.reqs[0]
- headers = dict(req.headers)
- self.assertEqual(headers['Content-length'], '608')
- self.assertTrue('tarek' in req.data)
-
- def test_password_reset(self):
- # this test runs choice 3
- cmd = self._get_cmd()
- inputs = RawInputs('3', 'tarek@ziade.org')
- register_module.raw_input = inputs.__call__
- try:
- # let's run the command
- cmd.run()
- finally:
- del register_module.raw_input
-
- # we should have send a request
- self.assertTrue(self.conn.reqs, 1)
- req = self.conn.reqs[0]
- headers = dict(req.headers)
- self.assertEqual(headers['Content-length'], '290')
- self.assertTrue('tarek' in req.data)
-
- def test_strict(self):
- # testing the script option
- # when on, the register command stops if
- # the metadata is incomplete or if
- # long_description is not reSt compliant
-
- # empty metadata
- cmd = self._get_cmd({})
- cmd.ensure_finalized()
- cmd.strict = 1
- self.assertRaises(DistutilsSetupError, cmd.run)
-
- # we don't test the reSt feature if docutils
- # is not installed
- try:
- import docutils
- except ImportError:
- return
-
- # metadata are OK but long_description is broken
- metadata = {'url': 'xxx', 'author': 'xxx',
- 'author_email': u'éxéxé',
- 'name': 'xxx', 'version': 'xxx',
- 'long_description': 'title\n==\n\ntext'}
-
- cmd = self._get_cmd(metadata)
- cmd.ensure_finalized()
- cmd.strict = 1
- self.assertRaises(DistutilsSetupError, cmd.run)
-
- # now something that works
- metadata['long_description'] = 'title\n=====\n\ntext'
- cmd = self._get_cmd(metadata)
- cmd.ensure_finalized()
- cmd.strict = 1
- inputs = RawInputs('1', 'tarek', 'y')
- register_module.raw_input = inputs.__call__
- # let's run the command
- try:
- cmd.run()
- finally:
- del register_module.raw_input
-
- # strict is not by default
- cmd = self._get_cmd()
- cmd.ensure_finalized()
- inputs = RawInputs('1', 'tarek', 'y')
- register_module.raw_input = inputs.__call__
- # let's run the command
- try:
- cmd.run()
- finally:
- del register_module.raw_input
-
- def test_check_metadata_deprecated(self):
- # makes sure make_metadata is deprecated
- cmd = self._get_cmd()
- with check_warnings() as w:
- warnings.simplefilter("always")
- cmd.check_metadata()
- self.assertEqual(len(w.warnings), 1)
-
-def test_suite():
- return unittest.makeSuite(RegisterTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_sdist.py b/src/python/stdlib/distutils/tests/test_sdist.py
deleted file mode 100644
index b9d86bb..0000000
--- a/src/python/stdlib/distutils/tests/test_sdist.py
+++ /dev/null
@@ -1,429 +0,0 @@
-"""Tests for distutils.command.sdist."""
-import os
-import unittest
-import shutil
-import zipfile
-import tarfile
-
-# zlib is not used here, but if it's not available
-# the tests that use zipfile may fail
-try:
- import zlib
-except ImportError:
- zlib = None
-
-try:
- import grp
- import pwd
- UID_GID_SUPPORT = True
-except ImportError:
- UID_GID_SUPPORT = False
-
-from os.path import join
-import sys
-import tempfile
-import warnings
-
-from test.test_support import check_warnings
-from test.test_support import captured_stdout
-
-from distutils.command.sdist import sdist
-from distutils.command.sdist import show_formats
-from distutils.core import Distribution
-from distutils.tests.test_config import PyPIRCCommandTestCase
-from distutils.errors import DistutilsExecError, DistutilsOptionError
-from distutils.spawn import find_executable
-from distutils.tests import support
-from distutils.log import WARN
-from distutils.archive_util import ARCHIVE_FORMATS
-
-SETUP_PY = """
-from distutils.core import setup
-import somecode
-
-setup(name='fake')
-"""
-
-MANIFEST = """\
-# file GENERATED by distutils, do NOT edit
-README
-inroot.txt
-setup.py
-data%(sep)sdata.dt
-scripts%(sep)sscript.py
-some%(sep)sfile.txt
-some%(sep)sother_file.txt
-somecode%(sep)s__init__.py
-somecode%(sep)sdoc.dat
-somecode%(sep)sdoc.txt
-"""
-
-class SDistTestCase(PyPIRCCommandTestCase):
-
- def setUp(self):
- # PyPIRCCommandTestCase creates a temp dir already
- # and put it in self.tmp_dir
- super(SDistTestCase, self).setUp()
- # setting up an environment
- self.old_path = os.getcwd()
- os.mkdir(join(self.tmp_dir, 'somecode'))
- os.mkdir(join(self.tmp_dir, 'dist'))
- # a package, and a README
- self.write_file((self.tmp_dir, 'README'), 'xxx')
- self.write_file((self.tmp_dir, 'somecode', '__init__.py'), '#')
- self.write_file((self.tmp_dir, 'setup.py'), SETUP_PY)
- os.chdir(self.tmp_dir)
-
- def tearDown(self):
- # back to normal
- os.chdir(self.old_path)
- super(SDistTestCase, self).tearDown()
-
- def get_cmd(self, metadata=None):
- """Returns a cmd"""
- if metadata is None:
- metadata = {'name': 'fake', 'version': '1.0',
- 'url': 'xxx', 'author': 'xxx',
- 'author_email': 'xxx'}
- dist = Distribution(metadata)
- dist.script_name = 'setup.py'
- dist.packages = ['somecode']
- dist.include_package_data = True
- cmd = sdist(dist)
- cmd.dist_dir = 'dist'
- def _warn(*args):
- pass
- cmd.warn = _warn
- return dist, cmd
-
- @unittest.skipUnless(zlib, "requires zlib")
- def test_prune_file_list(self):
- # this test creates a package with some vcs dirs in it
- # and launch sdist to make sure they get pruned
- # on all systems
-
- # creating VCS directories with some files in them
- os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
- self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
-
- os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
- self.write_file((self.tmp_dir, 'somecode', '.hg',
- 'ok'), 'xxx')
-
- os.mkdir(join(self.tmp_dir, 'somecode', '.git'))
- self.write_file((self.tmp_dir, 'somecode', '.git',
- 'ok'), 'xxx')
-
- # now building a sdist
- dist, cmd = self.get_cmd()
-
- # zip is available universally
- # (tar might not be installed under win32)
- cmd.formats = ['zip']
-
- cmd.ensure_finalized()
- cmd.run()
-
- # now let's check what we have
- dist_folder = join(self.tmp_dir, 'dist')
- files = os.listdir(dist_folder)
- self.assertEqual(files, ['fake-1.0.zip'])
-
- zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
- try:
- content = zip_file.namelist()
- finally:
- zip_file.close()
-
- # making sure everything has been pruned correctly
- self.assertEqual(len(content), 4)
-
- @unittest.skipUnless(zlib, "requires zlib")
- def test_make_distribution(self):
-
- # check if tar and gzip are installed
- if (find_executable('tar') is None or
- find_executable('gzip') is None):
- return
-
- # now building a sdist
- dist, cmd = self.get_cmd()
-
- # creating a gztar then a tar
- cmd.formats = ['gztar', 'tar']
- cmd.ensure_finalized()
- cmd.run()
-
- # making sure we have two files
- dist_folder = join(self.tmp_dir, 'dist')
- result = os.listdir(dist_folder)
- result.sort()
- self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'] )
-
- os.remove(join(dist_folder, 'fake-1.0.tar'))
- os.remove(join(dist_folder, 'fake-1.0.tar.gz'))
-
- # now trying a tar then a gztar
- cmd.formats = ['tar', 'gztar']
-
- cmd.ensure_finalized()
- cmd.run()
-
- result = os.listdir(dist_folder)
- result.sort()
- self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz'])
-
- @unittest.skipUnless(zlib, "requires zlib")
- def test_add_defaults(self):
-
- # http://bugs.python.org/issue2279
-
- # add_default should also include
- # data_files and package_data
- dist, cmd = self.get_cmd()
-
- # filling data_files by pointing files
- # in package_data
- dist.package_data = {'': ['*.cfg', '*.dat'],
- 'somecode': ['*.txt']}
- self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
- self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#')
-
- # adding some data in data_files
- data_dir = join(self.tmp_dir, 'data')
- os.mkdir(data_dir)
- self.write_file((data_dir, 'data.dt'), '#')
- some_dir = join(self.tmp_dir, 'some')
- os.mkdir(some_dir)
- self.write_file((self.tmp_dir, 'inroot.txt'), '#')
- self.write_file((some_dir, 'file.txt'), '#')
- self.write_file((some_dir, 'other_file.txt'), '#')
-
- dist.data_files = [('data', ['data/data.dt',
- 'inroot.txt',
- 'notexisting']),
- 'some/file.txt',
- 'some/other_file.txt']
-
- # adding a script
- script_dir = join(self.tmp_dir, 'scripts')
- os.mkdir(script_dir)
- self.write_file((script_dir, 'script.py'), '#')
- dist.scripts = [join('scripts', 'script.py')]
-
- cmd.formats = ['zip']
- cmd.use_defaults = True
-
- cmd.ensure_finalized()
- cmd.run()
-
- # now let's check what we have
- dist_folder = join(self.tmp_dir, 'dist')
- files = os.listdir(dist_folder)
- self.assertEqual(files, ['fake-1.0.zip'])
-
- zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
- try:
- content = zip_file.namelist()
- finally:
- zip_file.close()
-
- # making sure everything was added
- self.assertEqual(len(content), 11)
-
- # checking the MANIFEST
- f = open(join(self.tmp_dir, 'MANIFEST'))
- try:
- manifest = f.read()
- self.assertEqual(manifest, MANIFEST % {'sep': os.sep})
- finally:
- f.close()
-
- @unittest.skipUnless(zlib, "requires zlib")
- def test_metadata_check_option(self):
- # testing the `medata-check` option
- dist, cmd = self.get_cmd(metadata={})
-
- # this should raise some warnings !
- # with the `check` subcommand
- cmd.ensure_finalized()
- cmd.run()
- warnings = self.get_logs(WARN)
- self.assertEqual(len(warnings), 2)
-
- # trying with a complete set of metadata
- self.clear_logs()
- dist, cmd = self.get_cmd()
- cmd.ensure_finalized()
- cmd.metadata_check = 0
- cmd.run()
- warnings = self.get_logs(WARN)
- self.assertEqual(len(warnings), 0)
-
- def test_check_metadata_deprecated(self):
- # makes sure make_metadata is deprecated
- dist, cmd = self.get_cmd()
- with check_warnings() as w:
- warnings.simplefilter("always")
- cmd.check_metadata()
- self.assertEqual(len(w.warnings), 1)
-
- def test_show_formats(self):
- with captured_stdout() as stdout:
- show_formats()
-
- # the output should be a header line + one line per format
- num_formats = len(ARCHIVE_FORMATS.keys())
- output = [line for line in stdout.getvalue().split('\n')
- if line.strip().startswith('--formats=')]
- self.assertEqual(len(output), num_formats)
-
- def test_finalize_options(self):
-
- dist, cmd = self.get_cmd()
- cmd.finalize_options()
-
- # default options set by finalize
- self.assertEqual(cmd.manifest, 'MANIFEST')
- self.assertEqual(cmd.template, 'MANIFEST.in')
- self.assertEqual(cmd.dist_dir, 'dist')
-
- # formats has to be a string splitable on (' ', ',') or
- # a stringlist
- cmd.formats = 1
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
- cmd.formats = ['zip']
- cmd.finalize_options()
-
- # formats has to be known
- cmd.formats = 'supazipa'
- self.assertRaises(DistutilsOptionError, cmd.finalize_options)
-
- @unittest.skipUnless(zlib, "requires zlib")
- @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
- def test_make_distribution_owner_group(self):
-
- # check if tar and gzip are installed
- if (find_executable('tar') is None or
- find_executable('gzip') is None):
- return
-
- # now building a sdist
- dist, cmd = self.get_cmd()
-
- # creating a gztar and specifying the owner+group
- cmd.formats = ['gztar']
- cmd.owner = pwd.getpwuid(0)[0]
- cmd.group = grp.getgrgid(0)[0]
- cmd.ensure_finalized()
- cmd.run()
-
- # making sure we have the good rights
- archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
- archive = tarfile.open(archive_name)
- try:
- for member in archive.getmembers():
- self.assertEqual(member.uid, 0)
- self.assertEqual(member.gid, 0)
- finally:
- archive.close()
-
- # building a sdist again
- dist, cmd = self.get_cmd()
-
- # creating a gztar
- cmd.formats = ['gztar']
- cmd.ensure_finalized()
- cmd.run()
-
- # making sure we have the good rights
- archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
- archive = tarfile.open(archive_name)
-
- # note that we are not testing the group ownership here
- # because, depending on the platforms and the container
- # rights (see #7408)
- try:
- for member in archive.getmembers():
- self.assertEqual(member.uid, os.getuid())
- finally:
- archive.close()
-
- @unittest.skipUnless(zlib, "requires zlib")
- def test_get_file_list(self):
- # make sure MANIFEST is recalculated
- dist, cmd = self.get_cmd()
-
- # filling data_files by pointing files in package_data
- dist.package_data = {'somecode': ['*.txt']}
- self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
- cmd.ensure_finalized()
- cmd.run()
-
- f = open(cmd.manifest)
- try:
- manifest = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
- finally:
- f.close()
-
- self.assertEqual(len(manifest), 5)
-
- # adding a file
- self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#')
-
- # make sure build_py is reinitinialized, like a fresh run
- build_py = dist.get_command_obj('build_py')
- build_py.finalized = False
- build_py.ensure_finalized()
-
- cmd.run()
-
- f = open(cmd.manifest)
- try:
- manifest2 = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
- finally:
- f.close()
-
- # do we have the new file in MANIFEST ?
- self.assertEqual(len(manifest2), 6)
- self.assertIn('doc2.txt', manifest2[-1])
-
- def test_manifest_marker(self):
- # check that autogenerated MANIFESTs have a marker
- dist, cmd = self.get_cmd()
- cmd.ensure_finalized()
- cmd.run()
-
- f = open(cmd.manifest)
- try:
- manifest = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
- finally:
- f.close()
-
- self.assertEqual(manifest[0],
- '# file GENERATED by distutils, do NOT edit')
-
- def test_manual_manifest(self):
- # check that a MANIFEST without a marker is left alone
- dist, cmd = self.get_cmd()
- cmd.ensure_finalized()
- self.write_file((self.tmp_dir, cmd.manifest), 'README.manual')
- cmd.run()
-
- f = open(cmd.manifest)
- try:
- manifest = [line.strip() for line in f.read().split('\n')
- if line.strip() != '']
- finally:
- f.close()
-
- self.assertEqual(manifest, ['README.manual'])
-
-def test_suite():
- return unittest.makeSuite(SDistTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_spawn.py b/src/python/stdlib/distutils/tests/test_spawn.py
deleted file mode 100644
index 6caf039..0000000
--- a/src/python/stdlib/distutils/tests/test_spawn.py
+++ /dev/null
@@ -1,60 +0,0 @@
-"""Tests for distutils.spawn."""
-import unittest
-import os
-import time
-from test.test_support import captured_stdout
-
-from distutils.spawn import _nt_quote_args
-from distutils.spawn import spawn, find_executable
-from distutils.errors import DistutilsExecError
-from distutils.tests import support
-
-class SpawnTestCase(support.TempdirManager,
- support.LoggingSilencer,
- unittest.TestCase):
-
- def test_nt_quote_args(self):
-
- for (args, wanted) in ((['with space', 'nospace'],
- ['"with space"', 'nospace']),
- (['nochange', 'nospace'],
- ['nochange', 'nospace'])):
- res = _nt_quote_args(args)
- self.assertEqual(res, wanted)
-
-
- @unittest.skipUnless(os.name in ('nt', 'posix'),
- 'Runs only under posix or nt')
- def test_spawn(self):
- tmpdir = self.mkdtemp()
-
- # creating something executable
- # through the shell that returns 1
- if os.name == 'posix':
- exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!/bin/sh\nexit 1')
- os.chmod(exe, 0777)
- else:
- exe = os.path.join(tmpdir, 'foo.bat')
- self.write_file(exe, 'exit 1')
-
- os.chmod(exe, 0777)
- self.assertRaises(DistutilsExecError, spawn, [exe])
-
- # now something that works
- if os.name == 'posix':
- exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!/bin/sh\nexit 0')
- os.chmod(exe, 0777)
- else:
- exe = os.path.join(tmpdir, 'foo.bat')
- self.write_file(exe, 'exit 0')
-
- os.chmod(exe, 0777)
- spawn([exe]) # should work without any error
-
-def test_suite():
- return unittest.makeSuite(SpawnTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_sysconfig.py b/src/python/stdlib/distutils/tests/test_sysconfig.py
deleted file mode 100644
index 49570c4..0000000
--- a/src/python/stdlib/distutils/tests/test_sysconfig.py
+++ /dev/null
@@ -1,82 +0,0 @@
-"""Tests for distutils.sysconfig."""
-import os
-import test
-import unittest
-import shutil
-
-from distutils import sysconfig
-from distutils.tests import support
-from test.test_support import TESTFN
-
-class SysconfigTestCase(support.EnvironGuard,
- unittest.TestCase):
- def setUp(self):
- super(SysconfigTestCase, self).setUp()
- self.makefile = None
-
- def tearDown(self):
- if self.makefile is not None:
- os.unlink(self.makefile)
- self.cleanup_testfn()
- super(SysconfigTestCase, self).tearDown()
-
- def cleanup_testfn(self):
- path = test.test_support.TESTFN
- if os.path.isfile(path):
- os.remove(path)
- elif os.path.isdir(path):
- shutil.rmtree(path)
-
- def test_get_python_lib(self):
- lib_dir = sysconfig.get_python_lib()
- # XXX doesn't work on Linux when Python was never installed before
- #self.assertTrue(os.path.isdir(lib_dir), lib_dir)
- # test for pythonxx.lib?
- self.assertNotEqual(sysconfig.get_python_lib(),
- sysconfig.get_python_lib(prefix=TESTFN))
- _sysconfig = __import__('sysconfig')
- res = sysconfig.get_python_lib(True, True)
- self.assertEqual(_sysconfig.get_path('platstdlib'), res)
-
- def test_get_python_inc(self):
- inc_dir = sysconfig.get_python_inc()
- # This is not much of a test. We make sure Python.h exists
- # in the directory returned by get_python_inc() but we don't know
- # it is the correct file.
- self.assertTrue(os.path.isdir(inc_dir), inc_dir)
- python_h = os.path.join(inc_dir, "Python.h")
- self.assertTrue(os.path.isfile(python_h), python_h)
-
- def test_parse_makefile_base(self):
- self.makefile = test.test_support.TESTFN
- fd = open(self.makefile, 'w')
- try:
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- finally:
- fd.close()
- d = sysconfig.parse_makefile(self.makefile)
- self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
- 'OTHER': 'foo'})
-
- def test_parse_makefile_literal_dollar(self):
- self.makefile = test.test_support.TESTFN
- fd = open(self.makefile, 'w')
- try:
- fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
- fd.write('VAR=$OTHER\nOTHER=foo')
- finally:
- fd.close()
- d = sysconfig.parse_makefile(self.makefile)
- self.assertEqual(d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
- 'OTHER': 'foo'})
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(SysconfigTestCase))
- return suite
-
-
-if __name__ == '__main__':
- test.test_support.run_unittest(test_suite())
diff --git a/src/python/stdlib/distutils/tests/test_text_file.py b/src/python/stdlib/distutils/tests/test_text_file.py
deleted file mode 100644
index f1e32b6..0000000
--- a/src/python/stdlib/distutils/tests/test_text_file.py
+++ /dev/null
@@ -1,106 +0,0 @@
-"""Tests for distutils.text_file."""
-import os
-import unittest
-from distutils.text_file import TextFile
-from distutils.tests import support
-
-TEST_DATA = """# test file
-
-line 3 \\
-# intervening comment
- continues on next line
-"""
-
-class TextFileTestCase(support.TempdirManager, unittest.TestCase):
-
- def test_class(self):
- # old tests moved from text_file.__main__
- # so they are really called by the buildbots
-
- # result 1: no fancy options
- result1 = ['# test file\n', '\n', 'line 3 \\\n',
- '# intervening comment\n',
- ' continues on next line\n']
-
- # result 2: just strip comments
- result2 = ["\n",
- "line 3 \\\n",
- " continues on next line\n"]
-
- # result 3: just strip blank lines
- result3 = ["# test file\n",
- "line 3 \\\n",
- "# intervening comment\n",
- " continues on next line\n"]
-
- # result 4: default, strip comments, blank lines,
- # and trailing whitespace
- result4 = ["line 3 \\",
- " continues on next line"]
-
- # result 5: strip comments and blanks, plus join lines (but don't
- # "collapse" joined lines
- result5 = ["line 3 continues on next line"]
-
- # result 6: strip comments and blanks, plus join lines (and
- # "collapse" joined lines
- result6 = ["line 3 continues on next line"]
-
- def test_input(count, description, file, expected_result):
- result = file.readlines()
- self.assertEqual(result, expected_result)
-
- tmpdir = self.mkdtemp()
- filename = os.path.join(tmpdir, "test.txt")
- out_file = open(filename, "w")
- try:
- out_file.write(TEST_DATA)
- finally:
- out_file.close()
-
- in_file = TextFile(filename, strip_comments=0, skip_blanks=0,
- lstrip_ws=0, rstrip_ws=0)
- try:
- test_input(1, "no processing", in_file, result1)
- finally:
- in_file.close()
-
- in_file = TextFile(filename, strip_comments=1, skip_blanks=0,
- lstrip_ws=0, rstrip_ws=0)
- try:
- test_input(2, "strip comments", in_file, result2)
- finally:
- in_file.close()
-
- in_file = TextFile(filename, strip_comments=0, skip_blanks=1,
- lstrip_ws=0, rstrip_ws=0)
- try:
- test_input(3, "strip blanks", in_file, result3)
- finally:
- in_file.close()
-
- in_file = TextFile(filename)
- try:
- test_input(4, "default processing", in_file, result4)
- finally:
- in_file.close()
-
- in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
- join_lines=1, rstrip_ws=1)
- try:
- test_input(5, "join lines without collapsing", in_file, result5)
- finally:
- in_file.close()
-
- in_file = TextFile(filename, strip_comments=1, skip_blanks=1,
- join_lines=1, rstrip_ws=1, collapse_join=1)
- try:
- test_input(6, "join lines with collapsing", in_file, result6)
- finally:
- in_file.close()
-
-def test_suite():
- return unittest.makeSuite(TextFileTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_unixccompiler.py b/src/python/stdlib/distutils/tests/test_unixccompiler.py
deleted file mode 100644
index 3f233e2..0000000
--- a/src/python/stdlib/distutils/tests/test_unixccompiler.py
+++ /dev/null
@@ -1,129 +0,0 @@
-"""Tests for distutils.unixccompiler."""
-import sys
-import unittest
-
-from distutils import sysconfig
-from distutils.unixccompiler import UnixCCompiler
-
-class UnixCCompilerTestCase(unittest.TestCase):
-
- def setUp(self):
- self._backup_platform = sys.platform
- self._backup_get_config_var = sysconfig.get_config_var
- class CompilerWrapper(UnixCCompiler):
- def rpath_foo(self):
- return self.runtime_library_dir_option('/foo')
- self.cc = CompilerWrapper()
-
- def tearDown(self):
- sys.platform = self._backup_platform
- sysconfig.get_config_var = self._backup_get_config_var
-
- def test_runtime_libdir_option(self):
-
- # not tested under windows
- if sys.platform == 'win32':
- return
-
- # Issue#5900
- #
- # Ensure RUNPATH is added to extension modules with RPATH if
- # GNU ld is used
-
- # darwin
- sys.platform = 'darwin'
- self.assertEqual(self.cc.rpath_foo(), '-L/foo')
-
- # hp-ux
- sys.platform = 'hp-ux'
- old_gcv = sysconfig.get_config_var
- def gcv(v):
- return 'xxx'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), ['+s', '-L/foo'])
-
- def gcv(v):
- return 'gcc'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
-
- def gcv(v):
- return 'g++'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), ['-Wl,+s', '-L/foo'])
-
- sysconfig.get_config_var = old_gcv
-
- # irix646
- sys.platform = 'irix646'
- self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo'])
-
- # osf1V5
- sys.platform = 'osf1V5'
- self.assertEqual(self.cc.rpath_foo(), ['-rpath', '/foo'])
-
- # GCC GNULD
- sys.platform = 'bar'
- def gcv(v):
- if v == 'CC':
- return 'gcc'
- elif v == 'GNULD':
- return 'yes'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
-
- # GCC non-GNULD
- sys.platform = 'bar'
- def gcv(v):
- if v == 'CC':
- return 'gcc'
- elif v == 'GNULD':
- return 'no'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
-
- # GCC GNULD with fully qualified configuration prefix
- # see #7617
- sys.platform = 'bar'
- def gcv(v):
- if v == 'CC':
- return 'x86_64-pc-linux-gnu-gcc-4.4.2'
- elif v == 'GNULD':
- return 'yes'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), '-Wl,-R/foo')
-
-
- # non-GCC GNULD
- sys.platform = 'bar'
- def gcv(v):
- if v == 'CC':
- return 'cc'
- elif v == 'GNULD':
- return 'yes'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), '-R/foo')
-
- # non-GCC non-GNULD
- sys.platform = 'bar'
- def gcv(v):
- if v == 'CC':
- return 'cc'
- elif v == 'GNULD':
- return 'no'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), '-R/foo')
-
- # AIX C/C++ linker
- sys.platform = 'aix'
- def gcv(v):
- return 'xxx'
- sysconfig.get_config_var = gcv
- self.assertEqual(self.cc.rpath_foo(), '-R/foo')
-
-
-def test_suite():
- return unittest.makeSuite(UnixCCompilerTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_upload.py b/src/python/stdlib/distutils/tests/test_upload.py
deleted file mode 100644
index f45ee41..0000000
--- a/src/python/stdlib/distutils/tests/test_upload.py
+++ /dev/null
@@ -1,132 +0,0 @@
-"""Tests for distutils.command.upload."""
-# -*- encoding: utf8 -*-
-import sys
-import os
-import unittest
-
-from distutils.command import upload as upload_mod
-from distutils.command.upload import upload
-from distutils.core import Distribution
-
-from distutils.tests import support
-from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
-
-PYPIRC_LONG_PASSWORD = """\
-[distutils]
-
-index-servers =
- server1
- server2
-
-[server1]
-username:me
-password:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
-
-[server2]
-username:meagain
-password: secret
-realm:acme
-repository:http://another.pypi/
-"""
-
-
-PYPIRC_NOPASSWORD = """\
-[distutils]
-
-index-servers =
- server1
-
-[server1]
-username:me
-"""
-
-class FakeOpen(object):
-
- def __init__(self, url):
- self.url = url
- if not isinstance(url, str):
- self.req = url
- else:
- self.req = None
- self.msg = 'OK'
-
- def getcode(self):
- return 200
-
-
-class uploadTestCase(PyPIRCCommandTestCase):
-
- def setUp(self):
- super(uploadTestCase, self).setUp()
- self.old_open = upload_mod.urlopen
- upload_mod.urlopen = self._urlopen
- self.last_open = None
-
- def tearDown(self):
- upload_mod.urlopen = self.old_open
- super(uploadTestCase, self).tearDown()
-
- def _urlopen(self, url):
- self.last_open = FakeOpen(url)
- return self.last_open
-
- def test_finalize_options(self):
-
- # new format
- self.write_file(self.rc, PYPIRC)
- dist = Distribution()
- cmd = upload(dist)
- cmd.finalize_options()
- for attr, waited in (('username', 'me'), ('password', 'secret'),
- ('realm', 'pypi'),
- ('repository', 'http://pypi.python.org/pypi')):
- self.assertEqual(getattr(cmd, attr), waited)
-
- def test_saved_password(self):
- # file with no password
- self.write_file(self.rc, PYPIRC_NOPASSWORD)
-
- # make sure it passes
- dist = Distribution()
- cmd = upload(dist)
- cmd.finalize_options()
- self.assertEqual(cmd.password, None)
-
- # make sure we get it as well, if another command
- # initialized it at the dist level
- dist.password = 'xxx'
- cmd = upload(dist)
- cmd.finalize_options()
- self.assertEqual(cmd.password, 'xxx')
-
- def test_upload(self):
- tmp = self.mkdtemp()
- path = os.path.join(tmp, 'xxx')
- self.write_file(path)
- command, pyversion, filename = 'xxx', '2.6', path
- dist_files = [(command, pyversion, filename)]
- self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
-
- # lets run it
- pkg_dir, dist = self.create_dist(dist_files=dist_files, author=u'dédé')
- cmd = upload(dist)
- cmd.ensure_finalized()
- cmd.run()
-
- # what did we send ?
- self.assertIn('dédé', self.last_open.req.data)
- headers = dict(self.last_open.req.headers)
- self.assertEqual(headers['Content-length'], '2085')
- self.assertTrue(headers['Content-type'].startswith('multipart/form-data'))
- self.assertEqual(self.last_open.req.get_method(), 'POST')
- self.assertEqual(self.last_open.req.get_full_url(),
- 'http://pypi.python.org/pypi')
- self.assertTrue('xxx' in self.last_open.req.data)
- auth = self.last_open.req.headers['Authorization']
- self.assertFalse('\n' in auth)
-
-def test_suite():
- return unittest.makeSuite(uploadTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_util.py b/src/python/stdlib/distutils/tests/test_util.py
deleted file mode 100644
index 981ad00..0000000
--- a/src/python/stdlib/distutils/tests/test_util.py
+++ /dev/null
@@ -1,24 +0,0 @@
-"""Tests for distutils.util."""
-import sys
-import unittest
-
-from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
-from distutils.util import byte_compile
-
-class UtilTestCase(unittest.TestCase):
-
- def test_dont_write_bytecode(self):
- # makes sure byte_compile raise a DistutilsError
- # if sys.dont_write_bytecode is True
- old_dont_write_bytecode = sys.dont_write_bytecode
- sys.dont_write_bytecode = True
- try:
- self.assertRaises(DistutilsByteCompileError, byte_compile, [])
- finally:
- sys.dont_write_bytecode = old_dont_write_bytecode
-
-def test_suite():
- return unittest.makeSuite(UtilTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_version.py b/src/python/stdlib/distutils/tests/test_version.py
deleted file mode 100644
index 1d9fbc7..0000000
--- a/src/python/stdlib/distutils/tests/test_version.py
+++ /dev/null
@@ -1,70 +0,0 @@
-"""Tests for distutils.version."""
-import unittest
-from distutils.version import LooseVersion
-from distutils.version import StrictVersion
-
-class VersionTestCase(unittest.TestCase):
-
- def test_prerelease(self):
- version = StrictVersion('1.2.3a1')
- self.assertEqual(version.version, (1, 2, 3))
- self.assertEqual(version.prerelease, ('a', 1))
- self.assertEqual(str(version), '1.2.3a1')
-
- version = StrictVersion('1.2.0')
- self.assertEqual(str(version), '1.2')
-
- def test_cmp_strict(self):
- versions = (('1.5.1', '1.5.2b2', -1),
- ('161', '3.10a', ValueError),
- ('8.02', '8.02', 0),
- ('3.4j', '1996.07.12', ValueError),
- ('3.2.pl0', '3.1.1.6', ValueError),
- ('2g6', '11g', ValueError),
- ('0.9', '2.2', -1),
- ('1.2.1', '1.2', 1),
- ('1.1', '1.2.2', -1),
- ('1.2', '1.1', 1),
- ('1.2.1', '1.2.2', -1),
- ('1.2.2', '1.2', 1),
- ('1.2', '1.2.2', -1),
- ('0.4.0', '0.4', 0),
- ('1.13++', '5.5.kw', ValueError))
-
- for v1, v2, wanted in versions:
- try:
- res = StrictVersion(v1).__cmp__(StrictVersion(v2))
- except ValueError:
- if wanted is ValueError:
- continue
- else:
- raise AssertionError(("cmp(%s, %s) "
- "shouldn't raise ValueError")
- % (v1, v2))
- self.assertEqual(res, wanted,
- 'cmp(%s, %s) should be %s, got %s' %
- (v1, v2, wanted, res))
-
-
- def test_cmp(self):
- versions = (('1.5.1', '1.5.2b2', -1),
- ('161', '3.10a', 1),
- ('8.02', '8.02', 0),
- ('3.4j', '1996.07.12', -1),
- ('3.2.pl0', '3.1.1.6', 1),
- ('2g6', '11g', -1),
- ('0.960923', '2.2beta29', -1),
- ('1.13++', '5.5.kw', -1))
-
-
- for v1, v2, wanted in versions:
- res = LooseVersion(v1).__cmp__(LooseVersion(v2))
- self.assertEqual(res, wanted,
- 'cmp(%s, %s) should be %s, got %s' %
- (v1, v2, wanted, res))
-
-def test_suite():
- return unittest.makeSuite(VersionTestCase)
-
-if __name__ == "__main__":
- unittest.main(defaultTest="test_suite")
diff --git a/src/python/stdlib/distutils/tests/test_versionpredicate.py b/src/python/stdlib/distutils/tests/test_versionpredicate.py
deleted file mode 100644
index 8a60dbe..0000000
--- a/src/python/stdlib/distutils/tests/test_versionpredicate.py
+++ /dev/null
@@ -1,9 +0,0 @@
-"""Tests harness for distutils.versionpredicate.
-
-"""
-
-import distutils.versionpredicate
-import doctest
-
-def test_suite():
- return doctest.DocTestSuite(distutils.versionpredicate)