1 | n/a | """Tests for distutils.command.bdist_dumb.""" |
---|
2 | n/a | |
---|
3 | n/a | import os |
---|
4 | n/a | import sys |
---|
5 | n/a | import zipfile |
---|
6 | n/a | import unittest |
---|
7 | n/a | from test.support import run_unittest |
---|
8 | n/a | |
---|
9 | n/a | from distutils.core import Distribution |
---|
10 | n/a | from distutils.command.bdist_dumb import bdist_dumb |
---|
11 | n/a | from distutils.tests import support |
---|
12 | n/a | |
---|
13 | n/a | SETUP_PY = """\ |
---|
14 | n/a | from distutils.core import setup |
---|
15 | n/a | import foo |
---|
16 | n/a | |
---|
17 | n/a | setup(name='foo', version='0.1', py_modules=['foo'], |
---|
18 | n/a | url='xxx', author='xxx', author_email='xxx') |
---|
19 | n/a | |
---|
20 | n/a | """ |
---|
21 | n/a | |
---|
22 | n/a | try: |
---|
23 | n/a | import zlib |
---|
24 | n/a | ZLIB_SUPPORT = True |
---|
25 | n/a | except ImportError: |
---|
26 | n/a | ZLIB_SUPPORT = False |
---|
27 | n/a | |
---|
28 | n/a | |
---|
29 | n/a | class BuildDumbTestCase(support.TempdirManager, |
---|
30 | n/a | support.LoggingSilencer, |
---|
31 | n/a | support.EnvironGuard, |
---|
32 | n/a | unittest.TestCase): |
---|
33 | n/a | |
---|
34 | n/a | def setUp(self): |
---|
35 | n/a | super(BuildDumbTestCase, self).setUp() |
---|
36 | n/a | self.old_location = os.getcwd() |
---|
37 | n/a | self.old_sys_argv = sys.argv, sys.argv[:] |
---|
38 | n/a | |
---|
39 | n/a | def tearDown(self): |
---|
40 | n/a | os.chdir(self.old_location) |
---|
41 | n/a | sys.argv = self.old_sys_argv[0] |
---|
42 | n/a | sys.argv[:] = self.old_sys_argv[1] |
---|
43 | n/a | super(BuildDumbTestCase, self).tearDown() |
---|
44 | n/a | |
---|
45 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
---|
46 | n/a | def test_simple_built(self): |
---|
47 | n/a | |
---|
48 | n/a | # let's create a simple package |
---|
49 | n/a | tmp_dir = self.mkdtemp() |
---|
50 | n/a | pkg_dir = os.path.join(tmp_dir, 'foo') |
---|
51 | n/a | os.mkdir(pkg_dir) |
---|
52 | n/a | self.write_file((pkg_dir, 'setup.py'), SETUP_PY) |
---|
53 | n/a | self.write_file((pkg_dir, 'foo.py'), '#') |
---|
54 | n/a | self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') |
---|
55 | n/a | self.write_file((pkg_dir, 'README'), '') |
---|
56 | n/a | |
---|
57 | n/a | dist = Distribution({'name': 'foo', 'version': '0.1', |
---|
58 | n/a | 'py_modules': ['foo'], |
---|
59 | n/a | 'url': 'xxx', 'author': 'xxx', |
---|
60 | n/a | 'author_email': 'xxx'}) |
---|
61 | n/a | dist.script_name = 'setup.py' |
---|
62 | n/a | os.chdir(pkg_dir) |
---|
63 | n/a | |
---|
64 | n/a | sys.argv = ['setup.py'] |
---|
65 | n/a | cmd = bdist_dumb(dist) |
---|
66 | n/a | |
---|
67 | n/a | # so the output is the same no matter |
---|
68 | n/a | # what is the platform |
---|
69 | n/a | cmd.format = 'zip' |
---|
70 | n/a | |
---|
71 | n/a | cmd.ensure_finalized() |
---|
72 | n/a | cmd.run() |
---|
73 | n/a | |
---|
74 | n/a | # see what we have |
---|
75 | n/a | dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) |
---|
76 | n/a | base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name) |
---|
77 | n/a | |
---|
78 | n/a | self.assertEqual(dist_created, [base]) |
---|
79 | n/a | |
---|
80 | n/a | # now let's check what we have in the zip file |
---|
81 | n/a | fp = zipfile.ZipFile(os.path.join('dist', base)) |
---|
82 | n/a | try: |
---|
83 | n/a | contents = fp.namelist() |
---|
84 | n/a | finally: |
---|
85 | n/a | fp.close() |
---|
86 | n/a | |
---|
87 | n/a | contents = sorted(os.path.basename(fn) for fn in contents) |
---|
88 | n/a | wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py'] |
---|
89 | n/a | if not sys.dont_write_bytecode: |
---|
90 | n/a | wanted.append('foo.%s.pyc' % sys.implementation.cache_tag) |
---|
91 | n/a | self.assertEqual(contents, sorted(wanted)) |
---|
92 | n/a | |
---|
93 | n/a | def test_suite(): |
---|
94 | n/a | return unittest.makeSuite(BuildDumbTestCase) |
---|
95 | n/a | |
---|
96 | n/a | if __name__ == '__main__': |
---|
97 | n/a | run_unittest(test_suite()) |
---|