comparison tests/doctest.txt @ 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 6bfe6c59b64a
comparison
equal deleted inserted replaced
54:73e6956c670a 55:143adebe4caa
5 5
6 >>> import os 6 >>> import os
7 >>> import pkginfo 7 >>> import pkginfo
8 >>> import shutil 8 >>> import shutil
9 >>> import simpypi 9 >>> import simpypi
10 >>> import subprocess
10 >>> import tarfile 11 >>> import tarfile
11 >>> import tempfile 12 >>> import tempfile
12 >>> from paste.fixture import TestApp 13 >>> from paste.fixture import TestApp
13 14
14 The directory is initially empty:: 15 The directory is initially empty::
46 >>> sdist.home_page 47 >>> sdist.home_page
47 'http://helloworld.example.com/' 48 'http://helloworld.example.com/'
48 >>> sdist.author 49 >>> sdist.author
49 'Jeff Hammel' 50 'Jeff Hammel'
50 51
51 Install the package and inspect the installation:: 52 Unpack the archive and ensure the files are there::
52 53
53 >>> tmpdir = tempfile.mkdtemp() 54 >>> tmpdir = tempfile.mkdtemp()
54 >>> archive = tarfile.TarFile.open(path) 55 >>> archive = tarfile.TarFile.open(path)
55 >>> for member in archive.getmembers(): 56 >>> for member in archive.getmembers():
56 ... archive.extract(member, path=tmpdir) 57 ... archive.extract(member, path=tmpdir)
61 True 62 True
62 >>> 'helloworld' in os.listdir(srcdir) 63 >>> 'helloworld' in os.listdir(srcdir)
63 True 64 True
64 >>> os.listdir(os.path.join(srcdir, 'helloworld')) 65 >>> os.listdir(os.path.join(srcdir, 'helloworld'))
65 ['__init__.py'] 66 ['__init__.py']
67
68 Install the package and inspect the installation::
69
70 >>> python = create_virtualenv(tmpdir)
71
72 You should not be able to import ``helloworld`` yet::
73
74 >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
75 >>> code
76 1
77
78 But after installation you should::
79
80 >>> subprocess.call([python, 'setup.py', 'install'], cwd=srcdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
81 0
82 >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
83 >>> code
84 0
85 >>> process = subprocess.Popen([python, '-c', 'import helloworld; print helloworld.hello'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
86 >>> stdout, stderr = process.communicate()
87 >>> process.returncode
88 0
89 >>> stdout
90 'Hello, world!\n'
66 >>> shutil.rmtree(tmpdir) 91 >>> shutil.rmtree(tmpdir)
67 92
68 Upload the same package but with the wrong name:: 93 Upload the same package but with the wrong name::
69 94
70 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld')) 95 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld'))