# HG changeset patch # User Jeff Hammel # Date 1330644514 28800 # Node ID 143adebe4caa89db2c126569cd9d9f3b37ff479c # Parent 73e6956c670aa70eb04d37a0d667072e14db4a4a install package in a virtualenv and make sure importing is sane diff -r 73e6956c670a -r 143adebe4caa tests/doctest.txt --- a/tests/doctest.txt Thu Mar 01 15:04:27 2012 -0800 +++ b/tests/doctest.txt Thu Mar 01 15:28:34 2012 -0800 @@ -7,6 +7,7 @@ >>> import pkginfo >>> import shutil >>> import simpypi + >>> import subprocess >>> import tarfile >>> import tempfile >>> from paste.fixture import TestApp @@ -48,7 +49,7 @@ >>> sdist.author 'Jeff Hammel' -Install the package and inspect the installation:: +Unpack the archive and ensure the files are there:: >>> tmpdir = tempfile.mkdtemp() >>> archive = tarfile.TarFile.open(path) @@ -63,6 +64,30 @@ True >>> os.listdir(os.path.join(srcdir, 'helloworld')) ['__init__.py'] + +Install the package and inspect the installation:: + + >>> python = create_virtualenv(tmpdir) + +You should not be able to import ``helloworld`` yet:: + + >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + >>> code + 1 + +But after installation you should:: + + >>> subprocess.call([python, 'setup.py', 'install'], cwd=srcdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + 0 + >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + >>> code + 0 + >>> process = subprocess.Popen([python, '-c', 'import helloworld; print helloworld.hello'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + >>> stdout, stderr = process.communicate() + >>> process.returncode + 0 + >>> stdout + 'Hello, world!\n' >>> shutil.rmtree(tmpdir) Upload the same package but with the wrong name:: diff -r 73e6956c670a -r 143adebe4caa tests/test.py --- a/tests/test.py Thu Mar 01 15:04:27 2012 -0800 +++ b/tests/test.py Thu Mar 01 15:28:34 2012 -0800 @@ -9,8 +9,18 @@ import shutil import sys import tempfile +import virtualenv from optparse import OptionParser +def create_virtualenv(path): + """create a virtualenv and return the path to the python interpreter therein""" + virtualenv.create_environment(path) + for python in (('bin', 'python'), ('Scripts', 'python.exe')): + python = os.path.join(path, *python) + if os.path.exists(python): + return python + raise Exception("Python binary not found in %s" % path) + def run_tests(raise_on_error=False, report_first=False): # add results here @@ -18,7 +28,7 @@ # doctest arguments directory = os.path.dirname(os.path.abspath(__file__)) - extraglobs = {'here': directory} + extraglobs = {'here': directory, 'create_virtualenv': create_virtualenv} doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error) if report_first: doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE