ยปCore Development>Code coverage>Lib/distutils/tests/test_bdist_dumb.py

Python code coverage for Lib/distutils/tests/test_bdist_dumb.py

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