Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: recipe_engine/third_party/setuptools/tests/test_test.py

Issue 1344583003: Recipe package system. (Closed) Base URL: git@github.com:luci/recipes-py.git@master
Patch Set: Recompiled proto Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # -*- coding: UTF-8 -*-
2
3 """develop tests
4 """
5 import os
6 import shutil
7 import site
8 import sys
9 import tempfile
10 import unittest
11
12 from distutils.errors import DistutilsError
13 from setuptools.compat import StringIO, PY2
14 from setuptools.command.test import test
15 from setuptools.command import easy_install as easy_install_pkg
16 from setuptools.dist import Distribution
17
18 SETUP_PY = """\
19 from setuptools import setup
20
21 setup(name='foo',
22 packages=['name', 'name.space', 'name.space.tests'],
23 namespace_packages=['name'],
24 test_suite='name.space.tests.test_suite',
25 )
26 """
27
28 NS_INIT = """# -*- coding: Latin-1 -*-
29 # Söme Arbiträry Ünicode to test Issüé 310
30 try:
31 __import__('pkg_resources').declare_namespace(__name__)
32 except ImportError:
33 from pkgutil import extend_path
34 __path__ = extend_path(__path__, __name__)
35 """
36 # Make sure this is Latin-1 binary, before writing:
37 if PY2:
38 NS_INIT = NS_INIT.decode('UTF-8')
39 NS_INIT = NS_INIT.encode('Latin-1')
40
41 TEST_PY = """import unittest
42
43 class TestTest(unittest.TestCase):
44 def test_test(self):
45 print "Foo" # Should fail under Python 3 unless 2to3 is used
46
47 test_suite = unittest.makeSuite(TestTest)
48 """
49
50 class TestTestTest(unittest.TestCase):
51
52 def setUp(self):
53 if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
54 return
55
56 # Directory structure
57 self.dir = tempfile.mkdtemp()
58 os.mkdir(os.path.join(self.dir, 'name'))
59 os.mkdir(os.path.join(self.dir, 'name', 'space'))
60 os.mkdir(os.path.join(self.dir, 'name', 'space', 'tests'))
61 # setup.py
62 setup = os.path.join(self.dir, 'setup.py')
63 f = open(setup, 'wt')
64 f.write(SETUP_PY)
65 f.close()
66 self.old_cwd = os.getcwd()
67 # name/__init__.py
68 init = os.path.join(self.dir, 'name', '__init__.py')
69 f = open(init, 'wb')
70 f.write(NS_INIT)
71 f.close()
72 # name/space/__init__.py
73 init = os.path.join(self.dir, 'name', 'space', '__init__.py')
74 f = open(init, 'wt')
75 f.write('#empty\n')
76 f.close()
77 # name/space/tests/__init__.py
78 init = os.path.join(self.dir, 'name', 'space', 'tests', '__init__.py')
79 f = open(init, 'wt')
80 f.write(TEST_PY)
81 f.close()
82
83 os.chdir(self.dir)
84 self.old_base = site.USER_BASE
85 site.USER_BASE = tempfile.mkdtemp()
86 self.old_site = site.USER_SITE
87 site.USER_SITE = tempfile.mkdtemp()
88
89 def tearDown(self):
90 if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
91 return
92
93 os.chdir(self.old_cwd)
94 shutil.rmtree(self.dir)
95 shutil.rmtree(site.USER_BASE)
96 shutil.rmtree(site.USER_SITE)
97 site.USER_BASE = self.old_base
98 site.USER_SITE = self.old_site
99
100 def test_test(self):
101 if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
102 return
103
104 dist = Distribution(dict(
105 name='foo',
106 packages=['name', 'name.space', 'name.space.tests'],
107 namespace_packages=['name'],
108 test_suite='name.space.tests.test_suite',
109 use_2to3=True,
110 ))
111 dist.script_name = 'setup.py'
112 cmd = test(dist)
113 cmd.user = 1
114 cmd.ensure_finalized()
115 cmd.install_dir = site.USER_SITE
116 cmd.user = 1
117 old_stdout = sys.stdout
118 sys.stdout = StringIO()
119 try:
120 try: # try/except/finally doesn't work in Python 2.4, so we need nes ted try-statements.
121 cmd.run()
122 except SystemExit: # The test runner calls sys.exit, stop that makin g an error.
123 pass
124 finally:
125 sys.stdout = old_stdout
126
OLDNEW
« no previous file with comments | « recipe_engine/third_party/setuptools/tests/test_svn.py ('k') | recipe_engine/third_party/setuptools/tests/test_upload_docs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698