2004-06-17 17:16:19 -03:00
|
|
|
"""Tests for distutils.command.build_py."""
|
|
|
|
|
|
|
|
import os
|
2007-06-01 04:29:12 -03:00
|
|
|
import sys
|
|
|
|
import StringIO
|
2004-06-17 17:16:19 -03:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from distutils.command.build_py import build_py
|
|
|
|
from distutils.core import Distribution
|
2007-06-01 04:29:12 -03:00
|
|
|
from distutils.errors import DistutilsFileError
|
2004-06-17 17:16:19 -03:00
|
|
|
|
|
|
|
from distutils.tests import support
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
from test.test_support import run_unittest
|
2004-06-17 17:16:19 -03:00
|
|
|
|
|
|
|
|
2004-08-03 15:53:07 -03:00
|
|
|
class BuildPyTestCase(support.TempdirManager,
|
|
|
|
support.LoggingSilencer,
|
|
|
|
unittest.TestCase):
|
2004-06-17 17:16:19 -03:00
|
|
|
|
2010-02-22 20:24:49 -04:00
|
|
|
def _setup_package_data(self):
|
2004-06-17 17:16:19 -03:00
|
|
|
sources = self.mkdtemp()
|
|
|
|
f = open(os.path.join(sources, "__init__.py"), "w")
|
2010-11-06 01:06:18 -03:00
|
|
|
try:
|
|
|
|
f.write("# Pretend this is a package.")
|
|
|
|
finally:
|
|
|
|
f.close()
|
2004-06-17 17:16:19 -03:00
|
|
|
f = open(os.path.join(sources, "README.txt"), "w")
|
2010-11-06 01:06:18 -03:00
|
|
|
try:
|
|
|
|
f.write("Info about this package")
|
|
|
|
finally:
|
|
|
|
f.close()
|
2004-06-17 17:16:19 -03:00
|
|
|
|
|
|
|
destination = self.mkdtemp()
|
|
|
|
|
|
|
|
dist = Distribution({"packages": ["pkg"],
|
|
|
|
"package_dir": {"pkg": sources}})
|
|
|
|
# script_name need not exist, it just need to be initialized
|
|
|
|
dist.script_name = os.path.join(sources, "setup.py")
|
|
|
|
dist.command_obj["build"] = support.DummyCommand(
|
|
|
|
force=0,
|
|
|
|
build_lib=destination)
|
|
|
|
dist.packages = ["pkg"]
|
|
|
|
dist.package_data = {"pkg": ["README.txt"]}
|
|
|
|
dist.package_dir = {"pkg": sources}
|
|
|
|
|
|
|
|
cmd = build_py(dist)
|
2004-07-21 15:53:06 -03:00
|
|
|
cmd.compile = 1
|
2004-06-17 17:16:19 -03:00
|
|
|
cmd.ensure_finalized()
|
|
|
|
self.assertEqual(cmd.package_data, dist.package_data)
|
|
|
|
|
|
|
|
cmd.run()
|
|
|
|
|
2004-07-21 15:53:06 -03:00
|
|
|
# This makes sure the list of outputs includes byte-compiled
|
|
|
|
# files for Python modules but not for package data files
|
|
|
|
# (there shouldn't *be* byte-code files for those!).
|
|
|
|
#
|
|
|
|
self.assertEqual(len(cmd.get_outputs()), 3)
|
2004-06-17 17:16:19 -03:00
|
|
|
pkgdest = os.path.join(destination, "pkg")
|
|
|
|
files = os.listdir(pkgdest)
|
2010-02-22 20:24:49 -04:00
|
|
|
return files
|
|
|
|
|
|
|
|
def test_package_data(self):
|
|
|
|
files = self._setup_package_data()
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue("__init__.py" in files)
|
|
|
|
self.assertTrue("README.txt" in files)
|
2004-06-17 17:16:19 -03:00
|
|
|
|
2010-02-22 20:24:49 -04:00
|
|
|
@unittest.skipIf(sys.flags.optimize >= 2,
|
|
|
|
"pyc files are not written with -O2 and above")
|
|
|
|
def test_package_data_pyc(self):
|
|
|
|
files = self._setup_package_data()
|
|
|
|
self.assertTrue("__init__.pyc" in files)
|
|
|
|
|
2007-06-01 04:29:12 -03:00
|
|
|
def test_empty_package_dir (self):
|
|
|
|
# See SF 1668596/1720897.
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
|
|
|
# create the distribution files.
|
|
|
|
sources = self.mkdtemp()
|
|
|
|
open(os.path.join(sources, "__init__.py"), "w").close()
|
|
|
|
|
|
|
|
testdir = os.path.join(sources, "doc")
|
|
|
|
os.mkdir(testdir)
|
|
|
|
open(os.path.join(testdir, "testfile"), "w").close()
|
|
|
|
|
|
|
|
os.chdir(sources)
|
2009-11-01 18:33:45 -04:00
|
|
|
old_stdout = sys.stdout
|
2007-06-01 04:29:12 -03:00
|
|
|
sys.stdout = StringIO.StringIO()
|
|
|
|
|
|
|
|
try:
|
|
|
|
dist = Distribution({"packages": ["pkg"],
|
|
|
|
"package_dir": {"pkg": ""},
|
|
|
|
"package_data": {"pkg": ["doc/*"]}})
|
|
|
|
# script_name need not exist, it just need to be initialized
|
|
|
|
dist.script_name = os.path.join(sources, "setup.py")
|
|
|
|
dist.script_args = ["build"]
|
|
|
|
dist.parse_command_line()
|
|
|
|
|
|
|
|
try:
|
|
|
|
dist.run_commands()
|
|
|
|
except DistutilsFileError:
|
|
|
|
self.fail("failed package_data test when package_dir is ''")
|
|
|
|
finally:
|
|
|
|
# Restore state.
|
|
|
|
os.chdir(cwd)
|
2009-11-01 18:33:45 -04:00
|
|
|
sys.stdout = old_stdout
|
2004-06-17 17:16:19 -03:00
|
|
|
|
2009-10-24 12:10:37 -03:00
|
|
|
def test_dont_write_bytecode(self):
|
|
|
|
# makes sure byte_compile is not used
|
|
|
|
pkg_dir, dist = self.create_dist()
|
|
|
|
cmd = build_py(dist)
|
|
|
|
cmd.compile = 1
|
|
|
|
cmd.optimize = 1
|
|
|
|
|
|
|
|
old_dont_write_bytecode = sys.dont_write_bytecode
|
|
|
|
sys.dont_write_bytecode = True
|
|
|
|
try:
|
|
|
|
cmd.byte_compile([])
|
|
|
|
finally:
|
|
|
|
sys.dont_write_bytecode = old_dont_write_bytecode
|
|
|
|
|
2009-10-24 12:51:30 -03:00
|
|
|
self.assertTrue('byte-compiling is disabled' in self.logs[0][1])
|
2009-10-24 12:10:37 -03:00
|
|
|
|
2004-06-17 17:16:19 -03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(BuildPyTestCase)
|
2004-06-25 16:04:21 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
run_unittest(test_suite())
|