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