Tarek Ziadé | 6d327b0 | 2009-02-23 12:47:55 +0000 | [diff] [blame] | 1 | """Tests for distutils.command.bdist_dumb.""" |
| 2 | |
| 3 | import unittest |
| 4 | import sys |
| 5 | import os |
Éric Araujo | 70ec44a | 2010-11-06 02:44:43 +0000 | [diff] [blame] | 6 | from test.support import run_unittest |
Tarek Ziadé | 6d327b0 | 2009-02-23 12:47:55 +0000 | [diff] [blame] | 7 | |
| 8 | from distutils.core import Distribution |
| 9 | from distutils.command.bdist_dumb import bdist_dumb |
| 10 | from distutils.tests import support |
| 11 | |
| 12 | SETUP_PY = """\ |
| 13 | from distutils.core import setup |
| 14 | import foo |
| 15 | |
| 16 | setup(name='foo', version='0.1', py_modules=['foo'], |
| 17 | url='xxx', author='xxx', author_email='xxx') |
| 18 | |
| 19 | """ |
| 20 | |
| 21 | class BuildDumbTestCase(support.TempdirManager, |
| 22 | support.LoggingSilencer, |
Tarek Ziadé | 430fb63 | 2009-10-18 11:34:51 +0000 | [diff] [blame] | 23 | support.EnvironGuard, |
Tarek Ziadé | 6d327b0 | 2009-02-23 12:47:55 +0000 | [diff] [blame] | 24 | unittest.TestCase): |
| 25 | |
| 26 | def setUp(self): |
Hirokazu Yamamoto | 2703fd9 | 2009-05-29 09:14:04 +0000 | [diff] [blame] | 27 | super(BuildDumbTestCase, self).setUp() |
Tarek Ziadé | 6d327b0 | 2009-02-23 12:47:55 +0000 | [diff] [blame] | 28 | self.old_location = os.getcwd() |
Tarek Ziadé | 430fb63 | 2009-10-18 11:34:51 +0000 | [diff] [blame] | 29 | self.old_sys_argv = sys.argv, sys.argv[:] |
Tarek Ziadé | 6d327b0 | 2009-02-23 12:47:55 +0000 | [diff] [blame] | 30 | |
| 31 | def tearDown(self): |
| 32 | os.chdir(self.old_location) |
Tarek Ziadé | 430fb63 | 2009-10-18 11:34:51 +0000 | [diff] [blame] | 33 | sys.argv = self.old_sys_argv[0] |
| 34 | sys.argv[:] = self.old_sys_argv[1] |
Hirokazu Yamamoto | 2703fd9 | 2009-05-29 09:14:04 +0000 | [diff] [blame] | 35 | super(BuildDumbTestCase, self).tearDown() |
Tarek Ziadé | 6d327b0 | 2009-02-23 12:47:55 +0000 | [diff] [blame] | 36 | |
| 37 | def test_simple_built(self): |
| 38 | |
| 39 | # let's create a simple package |
| 40 | tmp_dir = self.mkdtemp() |
| 41 | pkg_dir = os.path.join(tmp_dir, 'foo') |
| 42 | os.mkdir(pkg_dir) |
| 43 | self.write_file((pkg_dir, 'setup.py'), SETUP_PY) |
| 44 | self.write_file((pkg_dir, 'foo.py'), '#') |
| 45 | self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') |
| 46 | self.write_file((pkg_dir, 'README'), '') |
| 47 | |
| 48 | dist = Distribution({'name': 'foo', 'version': '0.1', |
| 49 | 'py_modules': ['foo'], |
| 50 | 'url': 'xxx', 'author': 'xxx', |
| 51 | 'author_email': 'xxx'}) |
| 52 | dist.script_name = 'setup.py' |
| 53 | os.chdir(pkg_dir) |
| 54 | |
| 55 | sys.argv = ['setup.py'] |
| 56 | cmd = bdist_dumb(dist) |
| 57 | |
| 58 | # so the output is the same no matter |
| 59 | # what is the platform |
| 60 | cmd.format = 'zip' |
| 61 | |
| 62 | cmd.ensure_finalized() |
| 63 | cmd.run() |
| 64 | |
| 65 | # see what we have |
| 66 | dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) |
| 67 | base = "%s.%s" % (dist.get_fullname(), cmd.plat_name) |
| 68 | if os.name == 'os2': |
| 69 | base = base.replace(':', '-') |
| 70 | |
| 71 | wanted = ['%s.zip' % base] |
| 72 | self.assertEquals(dist_created, wanted) |
| 73 | |
| 74 | # now let's check what we have in the zip file |
| 75 | # XXX to be done |
| 76 | |
Tarek Ziadé | 6d327b0 | 2009-02-23 12:47:55 +0000 | [diff] [blame] | 77 | def test_suite(): |
| 78 | return unittest.makeSuite(BuildDumbTestCase) |
| 79 | |
| 80 | if __name__ == '__main__': |
Éric Araujo | 70ec44a | 2010-11-06 02:44:43 +0000 | [diff] [blame] | 81 | run_unittest(test_suite()) |