Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/setuptools/tests/test_packageindex.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 import sys | |
2 import distutils.errors | |
3 | |
4 from setuptools.compat import httplib, HTTPError, unicode, pathname2url | |
5 | |
6 import pkg_resources | |
7 import setuptools.package_index | |
8 from setuptools.tests.server import IndexServer | |
9 | |
10 | |
11 class TestPackageIndex: | |
12 | |
13 def test_bad_url_bad_port(self): | |
14 index = setuptools.package_index.PackageIndex() | |
15 url = 'http://127.0.0.1:0/nonesuch/test_package_index' | |
16 try: | |
17 v = index.open_url(url) | |
18 except Exception as v: | |
19 assert url in str(v) | |
20 else: | |
21 assert isinstance(v, HTTPError) | |
22 | |
23 def test_bad_url_typo(self): | |
24 # issue 16 | |
25 # easy_install inquant.contentmirror.plone breaks because of a typo | |
26 # in its home URL | |
27 index = setuptools.package_index.PackageIndex( | |
28 hosts=('www.example.com',) | |
29 ) | |
30 | |
31 url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk' | |
32 try: | |
33 v = index.open_url(url) | |
34 except Exception as v: | |
35 assert url in str(v) | |
36 else: | |
37 assert isinstance(v, HTTPError) | |
38 | |
39 def test_bad_url_bad_status_line(self): | |
40 index = setuptools.package_index.PackageIndex( | |
41 hosts=('www.example.com',) | |
42 ) | |
43 | |
44 def _urlopen(*args): | |
45 raise httplib.BadStatusLine('line') | |
46 | |
47 index.opener = _urlopen | |
48 url = 'http://example.com' | |
49 try: | |
50 v = index.open_url(url) | |
51 except Exception as v: | |
52 assert 'line' in str(v) | |
53 else: | |
54 raise AssertionError('Should have raise here!') | |
55 | |
56 def test_bad_url_double_scheme(self): | |
57 """ | |
58 A bad URL with a double scheme should raise a DistutilsError. | |
59 """ | |
60 index = setuptools.package_index.PackageIndex( | |
61 hosts=('www.example.com',) | |
62 ) | |
63 | |
64 # issue 20 | |
65 url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk' | |
66 try: | |
67 index.open_url(url) | |
68 except distutils.errors.DistutilsError as error: | |
69 msg = unicode(error) | |
70 assert 'nonnumeric port' in msg or 'getaddrinfo failed' in msg or 'Name or service not known' in msg | |
71 return | |
72 raise RuntimeError("Did not raise") | |
73 | |
74 def test_bad_url_screwy_href(self): | |
75 index = setuptools.package_index.PackageIndex( | |
76 hosts=('www.example.com',) | |
77 ) | |
78 | |
79 # issue #160 | |
80 if sys.version_info[0] == 2 and sys.version_info[1] == 7: | |
81 # this should not fail | |
82 url = 'http://example.com' | |
83 page = ('<a href="http://www.famfamfam.com](' | |
84 'http://www.famfamfam.com/">') | |
85 index.process_index(url, page) | |
86 | |
87 def test_url_ok(self): | |
88 index = setuptools.package_index.PackageIndex( | |
89 hosts=('www.example.com',) | |
90 ) | |
91 url = 'file:///tmp/test_package_index' | |
92 assert index.url_ok(url, True) | |
93 | |
94 def test_links_priority(self): | |
95 """ | |
96 Download links from the pypi simple index should be used before | |
97 external download links. | |
98 https://bitbucket.org/tarek/distribute/issue/163 | |
99 | |
100 Usecase : | |
101 - someone uploads a package on pypi, a md5 is generated | |
102 - someone manually copies this link (with the md5 in the url) onto an | |
103 external page accessible from the package page. | |
104 - someone reuploads the package (with a different md5) | |
105 - while easy_installing, an MD5 error occurs because the external link | |
106 is used | |
107 -> Setuptools should use the link from pypi, not the external one. | |
108 """ | |
109 if sys.platform.startswith('java'): | |
110 # Skip this test on jython because binding to :0 fails | |
111 return | |
112 | |
113 # start an index server | |
114 server = IndexServer() | |
115 server.start() | |
116 index_url = server.base_url() + 'test_links_priority/simple/' | |
117 | |
118 # scan a test index | |
119 pi = setuptools.package_index.PackageIndex(index_url) | |
120 requirement = pkg_resources.Requirement.parse('foobar') | |
121 pi.find_packages(requirement) | |
122 server.stop() | |
123 | |
124 # the distribution has been found | |
125 assert 'foobar' in pi | |
126 # we have only one link, because links are compared without md5 | |
127 assert len(pi['foobar'])==1 | |
128 # the link should be from the index | |
129 assert 'correct_md5' in pi['foobar'][0].location | |
130 | |
131 def test_parse_bdist_wininst(self): | |
132 parse = setuptools.package_index.parse_bdist_wininst | |
133 | |
134 actual = parse('reportlab-2.5.win32-py2.4.exe') | |
135 expected = 'reportlab-2.5', '2.4', 'win32' | |
136 assert actual == expected | |
137 | |
138 actual = parse('reportlab-2.5.win32.exe') | |
139 expected = 'reportlab-2.5', None, 'win32' | |
140 assert actual == expected | |
141 | |
142 actual = parse('reportlab-2.5.win-amd64-py2.7.exe') | |
143 expected = 'reportlab-2.5', '2.7', 'win-amd64' | |
144 assert actual == expected | |
145 | |
146 actual = parse('reportlab-2.5.win-amd64.exe') | |
147 expected = 'reportlab-2.5', None, 'win-amd64' | |
148 assert actual == expected | |
149 | |
150 def test__vcs_split_rev_from_url(self): | |
151 """ | |
152 Test the basic usage of _vcs_split_rev_from_url | |
153 """ | |
154 vsrfu = setuptools.package_index.PackageIndex._vcs_split_rev_from_url | |
155 url, rev = vsrfu('https://example.com/bar@2995') | |
156 assert url == 'https://example.com/bar' | |
157 assert rev == '2995' | |
158 | |
159 def test_local_index(self, tmpdir): | |
160 """ | |
161 local_open should be able to read an index from the file system. | |
162 """ | |
163 index_file = tmpdir / 'index.html' | |
164 with index_file.open('w') as f: | |
165 f.write('<div>content</div>') | |
166 url = 'file:' + pathname2url(str(tmpdir)) + '/' | |
167 res = setuptools.package_index.local_open(url) | |
168 assert 'content' in res.read() | |
169 | |
170 | |
171 class TestContentCheckers: | |
172 | |
173 def test_md5(self): | |
174 checker = setuptools.package_index.HashChecker.from_url( | |
175 'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478') | |
176 checker.feed('You should probably not be using MD5'.encode('ascii')) | |
177 assert checker.hash.hexdigest() == 'f12895fdffbd45007040d2e44df98478' | |
178 assert checker.is_valid() | |
179 | |
180 def test_other_fragment(self): | |
181 "Content checks should succeed silently if no hash is present" | |
182 checker = setuptools.package_index.HashChecker.from_url( | |
183 'http://foo/bar#something%20completely%20different') | |
184 checker.feed('anything'.encode('ascii')) | |
185 assert checker.is_valid() | |
186 | |
187 def test_blank_md5(self): | |
188 "Content checks should succeed if a hash is empty" | |
189 checker = setuptools.package_index.HashChecker.from_url( | |
190 'http://foo/bar#md5=') | |
191 checker.feed('anything'.encode('ascii')) | |
192 assert checker.is_valid() | |
193 | |
194 def test_get_hash_name_md5(self): | |
195 checker = setuptools.package_index.HashChecker.from_url( | |
196 'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478') | |
197 assert checker.hash_name == 'md5' | |
198 | |
199 def test_report(self): | |
200 checker = setuptools.package_index.HashChecker.from_url( | |
201 'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478') | |
202 rep = checker.report(lambda x: x, 'My message about %s') | |
203 assert rep == 'My message about md5' |