Home | History | Annotate | Download | only in tests
      1 """Tests for distutils.command.bdist_dumb."""
      2 
      3 import unittest
      4 import sys
      5 import os
      6 
      7 # zlib is not used here, but if it's not available

      8 # test_simple_built will fail

      9 try:
     10     import zlib
     11 except ImportError:
     12     zlib = None
     13 
     14 from test.test_support import run_unittest
     15 
     16 from distutils.core import Distribution
     17 from distutils.command.bdist_dumb import bdist_dumb
     18 from distutils.tests import support
     19 
     20 SETUP_PY = """\
     21 from distutils.core import setup
     22 import foo
     23 
     24 setup(name='foo', version='0.1', py_modules=['foo'],
     25       url='xxx', author='xxx', author_email='xxx')
     26 
     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, "requires zlib")
     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" % (dist.get_fullname(), cmd.plat_name)
     77         if os.name == 'os2':
     78             base = base.replace(':', '-')
     79 
     80         wanted = ['%s.zip' % base]
     81         self.assertEqual(dist_created, wanted)
     82 
     83         # now let's check what we have in the zip file

     84         # XXX to be done

     85 
     86     def test_finalize_options(self):
     87         pkg_dir, dist = self.create_dist()
     88         os.chdir(pkg_dir)
     89         cmd = bdist_dumb(dist)
     90         self.assertEqual(cmd.bdist_dir, None)
     91         cmd.finalize_options()
     92 
     93         # bdist_dir is initialized to bdist_base/dumb if not set

     94         base = cmd.get_finalized_command('bdist').bdist_base
     95         self.assertEqual(cmd.bdist_dir, os.path.join(base, 'dumb'))
     96 
     97         # the format is set to a default value depending on the os.name

     98         default = cmd.default_format[os.name]
     99         self.assertEqual(cmd.format, default)
    100 
    101 def test_suite():
    102     return unittest.makeSuite(BuildDumbTestCase)
    103 
    104 if __name__ == '__main__':
    105     run_unittest(test_suite())
    106