OLD | NEW |
(Empty) | |
| 1 """develop tests |
| 2 """ |
| 3 import os |
| 4 import shutil |
| 5 import site |
| 6 import sys |
| 7 import tempfile |
| 8 import unittest |
| 9 |
| 10 from distutils.errors import DistutilsError |
| 11 from setuptools.command.develop import develop |
| 12 from setuptools.dist import Distribution |
| 13 |
| 14 SETUP_PY = """\ |
| 15 from setuptools import setup |
| 16 |
| 17 setup(name='foo', |
| 18 packages=['foo'], |
| 19 use_2to3=True, |
| 20 ) |
| 21 """ |
| 22 |
| 23 INIT_PY = """print "foo" |
| 24 """ |
| 25 |
| 26 class TestDevelopTest(unittest.TestCase): |
| 27 |
| 28 def setUp(self): |
| 29 if sys.version < "2.6" or hasattr(sys, 'real_prefix'): |
| 30 return |
| 31 |
| 32 # Directory structure |
| 33 self.dir = tempfile.mkdtemp() |
| 34 os.mkdir(os.path.join(self.dir, 'foo')) |
| 35 # setup.py |
| 36 setup = os.path.join(self.dir, 'setup.py') |
| 37 f = open(setup, 'w') |
| 38 f.write(SETUP_PY) |
| 39 f.close() |
| 40 self.old_cwd = os.getcwd() |
| 41 # foo/__init__.py |
| 42 init = os.path.join(self.dir, 'foo', '__init__.py') |
| 43 f = open(init, 'w') |
| 44 f.write(INIT_PY) |
| 45 f.close() |
| 46 |
| 47 os.chdir(self.dir) |
| 48 self.old_base = site.USER_BASE |
| 49 site.USER_BASE = tempfile.mkdtemp() |
| 50 self.old_site = site.USER_SITE |
| 51 site.USER_SITE = tempfile.mkdtemp() |
| 52 |
| 53 def tearDown(self): |
| 54 if sys.version < "2.6" or hasattr(sys, 'real_prefix') or (hasattr(sys, '
base_prefix') and sys.base_prefix != sys.prefix): |
| 55 return |
| 56 |
| 57 os.chdir(self.old_cwd) |
| 58 shutil.rmtree(self.dir) |
| 59 shutil.rmtree(site.USER_BASE) |
| 60 shutil.rmtree(site.USER_SITE) |
| 61 site.USER_BASE = self.old_base |
| 62 site.USER_SITE = self.old_site |
| 63 |
| 64 def test_develop(self): |
| 65 if sys.version < "2.6" or hasattr(sys, 'real_prefix'): |
| 66 return |
| 67 dist = Distribution( |
| 68 dict(name='foo', |
| 69 packages=['foo'], |
| 70 use_2to3=True, |
| 71 version='0.0', |
| 72 )) |
| 73 dist.script_name = 'setup.py' |
| 74 cmd = develop(dist) |
| 75 cmd.user = 1 |
| 76 cmd.ensure_finalized() |
| 77 cmd.install_dir = site.USER_SITE |
| 78 cmd.user = 1 |
| 79 old_stdout = sys.stdout |
| 80 #sys.stdout = StringIO() |
| 81 try: |
| 82 cmd.run() |
| 83 finally: |
| 84 sys.stdout = old_stdout |
| 85 |
| 86 # let's see if we got our egg link at the right place |
| 87 content = os.listdir(site.USER_SITE) |
| 88 content.sort() |
| 89 self.assertEqual(content, ['easy-install.pth', 'foo.egg-link']) |
| 90 |
| 91 # Check that we are using the right code. |
| 92 egg_link_file = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt') |
| 93 try: |
| 94 path = egg_link_file.read().split()[0].strip() |
| 95 finally: |
| 96 egg_link_file.close() |
| 97 init_file = open(os.path.join(path, 'foo', '__init__.py'), 'rt') |
| 98 try: |
| 99 init = init_file.read().strip() |
| 100 finally: |
| 101 init_file.close() |
| 102 if sys.version < "3": |
| 103 self.assertEqual(init, 'print "foo"') |
| 104 else: |
| 105 self.assertEqual(init, 'print("foo")') |
| 106 |
| 107 def notest_develop_with_setup_requires(self): |
| 108 |
| 109 wanted = ("Could not find suitable distribution for " |
| 110 "Requirement.parse('I-DONT-EXIST')") |
| 111 old_dir = os.getcwd() |
| 112 os.chdir(self.dir) |
| 113 try: |
| 114 try: |
| 115 Distribution({'setup_requires': ['I_DONT_EXIST']}) |
| 116 except DistutilsError: |
| 117 e = sys.exc_info()[1] |
| 118 error = str(e) |
| 119 if error == wanted: |
| 120 pass |
| 121 finally: |
| 122 os.chdir(old_dir) |
OLD | NEW |