Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.32 KB)

1
"""develop tests
2
"""
3
import sys
4
import os, shutil, tempfile, unittest
5
import tempfile
6
import site
7
from StringIO import StringIO
8

    
9
from distutils.errors import DistutilsError
10
from setuptools.command.develop import develop
11
from setuptools.command import easy_install as easy_install_pkg
12
from setuptools.dist import Distribution
13

    
14
SETUP_PY = """\
15
from setuptools import setup
16

17
setup(name='foo')
18
"""
19

    
20
class TestDevelopTest(unittest.TestCase):
21

    
22
    def setUp(self):
23
        self.dir = tempfile.mkdtemp()
24
        setup = os.path.join(self.dir, 'setup.py')
25
        f = open(setup, 'w')
26
        f.write(SETUP_PY)
27
        f.close()
28
        self.old_cwd = os.getcwd()
29
        os.chdir(self.dir)
30
        if sys.version >= "2.6":
31
            self.old_base = site.USER_BASE
32
            site.USER_BASE = tempfile.mkdtemp()
33
            self.old_site = site.USER_SITE
34
            site.USER_SITE = tempfile.mkdtemp()
35

    
36
    def tearDown(self):
37
        os.chdir(self.old_cwd)
38
        shutil.rmtree(self.dir)
39
        if sys.version >= "2.6":
40
            shutil.rmtree(site.USER_BASE)
41
            shutil.rmtree(site.USER_SITE)
42
            site.USER_BASE = self.old_base
43
            site.USER_SITE = self.old_site
44

    
45
    def test_develop(self):
46
        if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
47
            return
48
        dist = Distribution()
49
        dist.script_name = 'setup.py'
50
        cmd = develop(dist)
51
        cmd.user = 1
52
        cmd.ensure_finalized()
53
        cmd.install_dir = site.USER_SITE
54
        cmd.user = 1
55
        old_stdout = sys.stdout
56
        sys.stdout = StringIO()
57
        try:
58
            cmd.run()
59
        finally:
60
            sys.stdout = old_stdout
61

    
62
        # let's see if we got our egg link at the right place
63
        content = os.listdir(site.USER_SITE)
64
        content.sort()
65
        self.assertEquals(content, ['UNKNOWN.egg-link', 'easy-install.pth'])
66

    
67
    def test_develop_with_setup_requires(self):
68

    
69
        wanted = ("Could not find suitable distribution for "
70
                  "Requirement.parse('I-DONT-EXIST')")
71
        old_dir = os.getcwd()
72
        os.chdir(self.dir)
73
        try:
74
            try:
75
                dist = Distribution({'setup_requires': ['I_DONT_EXIST']})
76
            except DistutilsError, e:
77
                error = str(e)
78
                if error ==  wanted:
79
                    pass
80
        finally:
81
            os.chdir(old_dir)
82