comparison venv/lib/python2.7/site-packages/setuptools/tests/test_develop.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 """develop tests
2 """
3 import os
4 import shutil
5 import site
6 import sys
7 import tempfile
8
9 from setuptools.command.develop import develop
10 from setuptools.dist import Distribution
11
12 SETUP_PY = """\
13 from setuptools import setup
14
15 setup(name='foo',
16 packages=['foo'],
17 use_2to3=True,
18 )
19 """
20
21 INIT_PY = """print "foo"
22 """
23
24 class TestDevelopTest:
25
26 def setup_method(self, method):
27 if hasattr(sys, 'real_prefix'):
28 return
29
30 # Directory structure
31 self.dir = tempfile.mkdtemp()
32 os.mkdir(os.path.join(self.dir, 'foo'))
33 # setup.py
34 setup = os.path.join(self.dir, 'setup.py')
35 f = open(setup, 'w')
36 f.write(SETUP_PY)
37 f.close()
38 self.old_cwd = os.getcwd()
39 # foo/__init__.py
40 init = os.path.join(self.dir, 'foo', '__init__.py')
41 f = open(init, 'w')
42 f.write(INIT_PY)
43 f.close()
44
45 os.chdir(self.dir)
46 self.old_base = site.USER_BASE
47 site.USER_BASE = tempfile.mkdtemp()
48 self.old_site = site.USER_SITE
49 site.USER_SITE = tempfile.mkdtemp()
50
51 def teardown_method(self, method):
52 if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
53 return
54
55 os.chdir(self.old_cwd)
56 shutil.rmtree(self.dir)
57 shutil.rmtree(site.USER_BASE)
58 shutil.rmtree(site.USER_SITE)
59 site.USER_BASE = self.old_base
60 site.USER_SITE = self.old_site
61
62 def test_develop(self):
63 if hasattr(sys, 'real_prefix'):
64 return
65 dist = Distribution(
66 dict(name='foo',
67 packages=['foo'],
68 use_2to3=True,
69 version='0.0',
70 ))
71 dist.script_name = 'setup.py'
72 cmd = develop(dist)
73 cmd.user = 1
74 cmd.ensure_finalized()
75 cmd.install_dir = site.USER_SITE
76 cmd.user = 1
77 old_stdout = sys.stdout
78 #sys.stdout = StringIO()
79 try:
80 cmd.run()
81 finally:
82 sys.stdout = old_stdout
83
84 # let's see if we got our egg link at the right place
85 content = os.listdir(site.USER_SITE)
86 content.sort()
87 assert content == ['easy-install.pth', 'foo.egg-link']
88
89 # Check that we are using the right code.
90 egg_link_file = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt')
91 try:
92 path = egg_link_file.read().split()[0].strip()
93 finally:
94 egg_link_file.close()
95 init_file = open(os.path.join(path, 'foo', '__init__.py'), 'rt')
96 try:
97 init = init_file.read().strip()
98 finally:
99 init_file.close()
100 if sys.version < "3":
101 assert init == 'print "foo"'
102 else:
103 assert init == 'print("foo")'