changeset 55:143adebe4caa

install package in a virtualenv and make sure importing is sane
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 01 Mar 2012 15:28:34 -0800
parents 73e6956c670a
children 2e60fb704454
files tests/doctest.txt tests/test.py
diffstat 2 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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::
--- 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