annotate tests/doctest.txt @ 53:a40f050812cb

start inspecting archive contents
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 01 Mar 2012 14:48:39 -0800
parents 59368c0bbd8d
children 73e6956c670a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
5ee4fe3decd9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
1 Test simpypi
5ee4fe3decd9 more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
2 ============
6
232e67cac00c stub testing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
232e67cac00c stub testing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 The obligatory imports::
232e67cac00c stub testing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
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
d9bc2a586ed4 add an import
Jeff Hammel <jhammel@mozilla.com>
parents: 43
diff changeset
8 >>> import shutil
6
232e67cac00c stub testing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 >>> import simpypi
52
59368c0bbd8d * addition sdist tests
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
10 >>> import tarfile
50
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
11 >>> import tempfile
33
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
12 >>> from paste.fixture import TestApp
6
232e67cac00c stub testing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
33
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
14 The directory is initially empty::
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
15
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
16 >>> os.listdir(directory)
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
17 []
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 Make a test application::
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
20
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
21 >>> app = simpypi.SimPyPI(directory)
058182b7b309 note test-requires.txt in the readme
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
22 >>> testapp = TestApp(app)
36
a02d08627d9c stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
23
a02d08627d9c stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
24 Upload a package::
a02d08627d9c stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
25
a02d08627d9c stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
26 >>> field = 'package'
a02d08627d9c stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
27 >>> filename = 'HelloWorld-0.0.tar.gz'
a02d08627d9c stub a test to upload a package
Jeff Hammel <jhammel@mozilla.com>
parents: 33
diff changeset
28 >>> contents = file(os.path.join(here, filename)).read()
37
1bdece293671 * fix calling signature in test
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
29 >>> 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
30
089d5650d7e2 check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
31 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
32
089d5650d7e2 check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
33 >>> os.listdir(directory)
089d5650d7e2 check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
34 ['HelloWorld']
089d5650d7e2 check for the package in the right place
Jeff Hammel <jhammel@mozilla.com>
parents: 37
diff changeset
35 >>> 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
36 ['HelloWorld-0.0.tar.gz']
47
cb24b5265557 clean out tmpdir
Jeff Hammel <jhammel@mozilla.com>
parents: 44
diff changeset
37
50
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
38 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
39
51
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
40 >>> 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
41 >>> sdist = pkginfo.sdist.SDist(path)
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
42 >>> sdist.name
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
43 'HelloWorld'
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
44 >>> sdist.version
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
45 '0.0'
52
59368c0bbd8d * addition sdist tests
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
46 >>> sdist.home_page
59368c0bbd8d * addition sdist tests
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
47 'http://helloworld.example.com/'
59368c0bbd8d * addition sdist tests
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
48 >>> sdist.author
59368c0bbd8d * addition sdist tests
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
49 'Jeff Hammel'
51
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
50
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
51 Install the package and inspect the installation::
6a8071eab89e add in smokescreen pkginfo tests
Jeff Hammel <jhammel@mozilla.com>
parents: 50
diff changeset
52
50
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
53 >>> tmpdir = tempfile.mkdtemp()
52
59368c0bbd8d * addition sdist tests
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
54 >>> archive = tarfile.TarFile.open(path)
53
a40f050812cb start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
55 >>> for member in archive.getmembers():
a40f050812cb start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
56 ... archive.extract(member, path=tmpdir)
a40f050812cb start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
57 >>> os.listdir(tmpdir)
a40f050812cb start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
58 ['HelloWorld-0.0']
a40f050812cb start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
59 >>> srcdir = os.path.join(tmpdir, 'HelloWorld-0.0')
a40f050812cb start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
60 >>> os.path.exists(os.path.join(srcdir, 'setup.py'))
a40f050812cb start inspecting archive contents
Jeff Hammel <jhammel@mozilla.com>
parents: 52
diff changeset
61 True
50
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
62 >>> shutil.rmtree(tmpdir)
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
63
47
cb24b5265557 clean out tmpdir
Jeff Hammel <jhammel@mozilla.com>
parents: 44
diff changeset
64 Upload the same package but with the wrong name::
cb24b5265557 clean out tmpdir
Jeff Hammel <jhammel@mozilla.com>
parents: 44
diff changeset
65
cb24b5265557 clean out tmpdir
Jeff Hammel <jhammel@mozilla.com>
parents: 44
diff changeset
66 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld'))
cb24b5265557 clean out tmpdir
Jeff Hammel <jhammel@mozilla.com>
parents: 44
diff changeset
67 >>> os.listdir(directory)
cb24b5265557 clean out tmpdir
Jeff Hammel <jhammel@mozilla.com>
parents: 44
diff changeset
68 []
49
ca456e08924f add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
69 >>> 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
70 >>> os.listdir(directory)
ca456e08924f add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
71 ['HelloWorld']
ca456e08924f add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
72 >>> os.listdir(os.path.join(directory, 'HelloWorld'))
ca456e08924f add a test for misnamed files
Jeff Hammel <jhammel@mozilla.com>
parents: 47
diff changeset
73 ['HelloWorld-0.0.tar.gz']
50
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
74 >>> shutil.rmtree(os.path.join(directory, 'HelloWorld'))
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
75 >>> os.listdir(directory)
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
76 []
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
77 >>> filename = 'MisleadingFilename.tar.gz'
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
78 >>> contents = file(os.path.join(here, filename)).read()
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
79 >>> response = testapp.post('/', upload_files=[(field, filename, contents)])
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
80 >>> os.listdir(directory)
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
81 ['HelloWorld']
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
82 >>> os.listdir(os.path.join(directory, 'HelloWorld'))
e4a97d6f2811 * add kinda a redundant test
Jeff Hammel <jhammel@mozilla.com>
parents: 49
diff changeset
83 ['HelloWorld-0.0.tar.gz']