Project

General

Profile

Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / distribute-0.6.19-py2.7.egg / setuptools / tests / test_packageindex.py @ 1a305335

History | View | Annotate | Download (4.27 KB)

1 1a305335 officers
"""Package Index Tests
2
"""
3
# More would be better!
4
import sys
5
import os, shutil, tempfile, unittest, urllib2
6
import pkg_resources
7
import setuptools.package_index
8
from server import IndexServer
9
10
class TestPackageIndex(unittest.TestCase):
11
12
    def test_bad_urls(self):
13
        index = setuptools.package_index.PackageIndex()
14
        url = 'http://127.0.0.1:0/nonesuch/test_package_index'
15
        try:
16
            v = index.open_url(url)
17
        except Exception, v:
18
            self.assert_(url in str(v))
19
        else:
20
            self.assert_(isinstance(v,urllib2.HTTPError))
21
22
        # issue 16
23
        # easy_install inquant.contentmirror.plone breaks because of a typo
24
        # in its home URL
25
        index = setuptools.package_index.PackageIndex(
26
            hosts=('www.example.com',)
27
        )
28
29
        url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk'
30
        try:
31
            v = index.open_url(url)
32
        except Exception, v:
33
            self.assert_(url in str(v))
34
        else:
35
            self.assert_(isinstance(v, urllib2.HTTPError))
36
37
        def _urlopen(*args):
38
            import httplib
39
            raise httplib.BadStatusLine('line')
40
41
        old_urlopen = urllib2.urlopen
42
        urllib2.urlopen = _urlopen
43
        url = 'http://example.com'
44
        try:
45
            try:
46
                v = index.open_url(url)
47
            except Exception, v:
48
                self.assert_('line' in str(v))
49
            else:
50
                raise AssertionError('Should have raise here!')
51
        finally:
52
            urllib2.urlopen = old_urlopen
53
54
        # issue 20
55
        url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk'
56
        try:
57
            index.open_url(url)
58
        except Exception, v:
59
            self.assert_('nonnumeric port' in str(v))
60
61
62
        # issue #160
63
        if sys.version_info[0] == 2 and sys.version_info[1] == 7:
64
            # this should not fail
65
            url = 'http://example.com'
66
            page = ('<a href="http://www.famfamfam.com]('
67
                    'http://www.famfamfam.com/">')
68
            index.process_index(url, page)
69
70
71
    def test_url_ok(self):
72
        index = setuptools.package_index.PackageIndex(
73
            hosts=('www.example.com',)
74
        )
75
        url = 'file:///tmp/test_package_index'
76
        self.assert_(index.url_ok(url, True))
77
78
    def test_links_priority(self):
79
        """
80
        Download links from the pypi simple index should be used before
81
        external download links.
82
        http://bitbucket.org/tarek/distribute/issue/163/md5-validation-error
83

84
        Usecase :
85
        - someone uploads a package on pypi, a md5 is generated
86
        - someone manually copies this link (with the md5 in the url) onto an
87
          external page accessible from the package page.
88
        - someone reuploads the package (with a different md5)
89
        - while easy_installing, an MD5 error occurs because the external link
90
          is used
91
        -> Distribute should use the link from pypi, not the external one.
92
        """
93
        # start an index server
94
        server = IndexServer()
95
        server.start()
96
        index_url = server.base_url() + 'test_links_priority/simple/'
97
98
        # scan a test index
99
        pi = setuptools.package_index.PackageIndex(index_url)
100
        requirement = pkg_resources.Requirement.parse('foobar')
101
        pi.find_packages(requirement)
102
        server.stop()
103
104
        # the distribution has been found
105
        self.assert_('foobar' in pi)
106
        # we have only one link, because links are compared without md5
107
        self.assert_(len(pi['foobar'])==1)
108
        # the link should be from the index
109
        self.assert_('correct_md5' in pi['foobar'][0].location)
110
111
    def test_parse_bdist_wininst(self):
112
        self.assertEqual(setuptools.package_index.parse_bdist_wininst(
113
            'reportlab-2.5.win32-py2.4.exe'), ('reportlab-2.5', '2.4', 'win32'))
114
        self.assertEqual(setuptools.package_index.parse_bdist_wininst(
115
            'reportlab-2.5.win32.exe'), ('reportlab-2.5', None, 'win32'))
116
        self.assertEqual(setuptools.package_index.parse_bdist_wininst(
117
            'reportlab-2.5.win-amd64-py2.7.exe'), ('reportlab-2.5', '2.7', 'win-amd64'))
118
        self.assertEqual(setuptools.package_index.parse_bdist_wininst(
119
            'reportlab-2.5.win-amd64.exe'), ('reportlab-2.5', None, 'win-amd64'))
120