Mercurial > hg > simpypi
annotate 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 |
rev | line source |
---|---|
7 | 1 Test simpypi |
2 ============ | |
6 | 3 |
4 The obligatory imports:: | |
5 | |
33
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
6 >>> import os |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
7 >>> import pkginfo |
44 | 8 >>> import shutil |
6 | 9 >>> import simpypi |
55
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
10 >>> import subprocess |
52 | 11 >>> import tarfile |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
12 >>> import tempfile |
33
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
13 >>> from paste.fixture import TestApp |
6 | 14 |
33
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
15 The directory is initially empty:: |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
16 |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
17 >>> os.listdir(directory) |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
18 [] |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
19 |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
20 Make a test application:: |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
21 |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
22 >>> app = simpypi.SimPyPI(directory) |
058182b7b309
note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
23 >>> testapp = TestApp(app) |
36
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
24 |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
25 Upload a package:: |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
26 |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
27 >>> field = 'package' |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
28 >>> filename = 'HelloWorld-0.0.tar.gz' |
a02d08627d9c
stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents:
33
diff
changeset
|
29 >>> contents = file(os.path.join(here, filename)).read() |
37
1bdece293671
* fix calling signature in test
Jeff Hammel <jhammel@mozilla.com>
parents:
36
diff
changeset
|
30 >>> response = testapp.post('/', upload_files=[(field, filename, contents)]) |
43
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
31 |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
32 Ensure that package is in the right place:: |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
33 |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
34 >>> os.listdir(directory) |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
35 ['HelloWorld'] |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
36 >>> os.listdir(os.path.join(directory, 'HelloWorld')) |
089d5650d7e2
check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
37
diff
changeset
|
37 ['HelloWorld-0.0.tar.gz'] |
47 | 38 |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
39 Ensure the package is what you expect it to be:: |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
40 |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
41 >>> path = os.path.join(directory, 'HelloWorld', 'HelloWorld-0.0.tar.gz') |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
42 >>> sdist = pkginfo.sdist.SDist(path) |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
43 >>> sdist.name |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
44 'HelloWorld' |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
45 >>> sdist.version |
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
46 '0.0' |
52 | 47 >>> sdist.home_page |
48 'http://helloworld.example.com/' | |
49 >>> sdist.author | |
50 'Jeff Hammel' | |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
51 |
55
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
52 Unpack the archive and ensure the files are there:: |
51
6a8071eab89e
add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents:
50
diff
changeset
|
53 |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
54 >>> tmpdir = tempfile.mkdtemp() |
52 | 55 >>> archive = tarfile.TarFile.open(path) |
53
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
56 >>> for member in archive.getmembers(): |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
57 ... archive.extract(member, path=tmpdir) |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
58 >>> os.listdir(tmpdir) |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
59 ['HelloWorld-0.0'] |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
60 >>> srcdir = os.path.join(tmpdir, 'HelloWorld-0.0') |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
61 >>> os.path.exists(os.path.join(srcdir, 'setup.py')) |
a40f050812cb
start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
62 True |
54
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
63 >>> 'helloworld' in os.listdir(srcdir) |
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
64 True |
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
65 >>> os.listdir(os.path.join(srcdir, 'helloworld')) |
73e6956c670a
ensure all the files are in the right place
Jeff Hammel <jhammel@mozilla.com>
parents:
53
diff
changeset
|
66 ['__init__.py'] |
55
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
67 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
68 Install the package and inspect the installation:: |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
69 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
70 >>> python = create_virtualenv(tmpdir) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
71 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
72 You should not be able to import ``helloworld`` yet:: |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
73 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
74 >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
75 >>> code |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
76 1 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
77 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
78 But after installation you should:: |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
79 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
80 >>> subprocess.call([python, 'setup.py', 'install'], cwd=srcdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
81 0 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
82 >>> code = subprocess.call([python, '-c', 'import helloworld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
83 >>> code |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
84 0 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
85 >>> process = subprocess.Popen([python, '-c', 'import helloworld; print helloworld.hello'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
86 >>> stdout, stderr = process.communicate() |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
87 >>> process.returncode |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
88 0 |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
89 >>> stdout |
143adebe4caa
install package in a virtualenv and make sure importing is sane
Jeff Hammel <jhammel@mozilla.com>
parents:
54
diff
changeset
|
90 'Hello, world!\n' |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
91 >>> shutil.rmtree(tmpdir) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
92 |
47 | 93 Upload the same package but with the wrong name:: |
94 | |
95 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld')) | |
96 >>> os.listdir(directory) | |
97 [] | |
49
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
98 >>> response = testapp.post('/', upload_files=[(field, 'MisleadingName.tar.gz', contents)]) |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
99 >>> os.listdir(directory) |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
100 ['HelloWorld'] |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
101 >>> os.listdir(os.path.join(directory, 'HelloWorld')) |
ca456e08924f
add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
102 ['HelloWorld-0.0.tar.gz'] |
50
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
103 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld')) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
104 >>> os.listdir(directory) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
105 [] |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
106 >>> filename = 'MisleadingFilename.tar.gz' |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
107 >>> contents = file(os.path.join(here, filename)).read() |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
108 >>> response = testapp.post('/', upload_files=[(field, filename, contents)]) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
109 >>> os.listdir(directory) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
110 ['HelloWorld'] |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
111 >>> os.listdir(os.path.join(directory, 'HelloWorld')) |
e4a97d6f2811
* add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents:
49
diff
changeset
|
112 ['HelloWorld-0.0.tar.gz'] |