1
"""Tests for distutils.command.build_py."""
8
from distutils.command.build_py import build_py
9
from distutils.core import Distribution
10
from distutils.errors import DistutilsFileError
12
from distutils.tests import support
15
class BuildPyTestCase(support.TempdirManager,
16
support.LoggingSilencer,
19
def test_package_data(self):
20
sources = self.mkdtemp()
21
f = open(os.path.join(sources, "__init__.py"), "w")
22
f.write("# Pretend this is a package.")
24
f = open(os.path.join(sources, "README.txt"), "w")
25
f.write("Info about this package")
28
destination = self.mkdtemp()
30
dist = Distribution({"packages": ["pkg"],
31
"package_dir": {"pkg": sources}})
32
# script_name need not exist, it just need to be initialized
33
dist.script_name = os.path.join(sources, "setup.py")
34
dist.command_obj["build"] = support.DummyCommand(
36
build_lib=destination)
37
dist.packages = ["pkg"]
38
dist.package_data = {"pkg": ["README.txt"]}
39
dist.package_dir = {"pkg": sources}
43
cmd.ensure_finalized()
44
self.assertEqual(cmd.package_data, dist.package_data)
48
# This makes sure the list of outputs includes byte-compiled
49
# files for Python modules but not for package data files
50
# (there shouldn't *be* byte-code files for those!).
52
self.assertEqual(len(cmd.get_outputs()), 3)
53
pkgdest = os.path.join(destination, "pkg")
54
files = os.listdir(pkgdest)
55
self.assert_("__init__.py" in files)
56
self.assert_("__init__.pyc" in files)
57
self.assert_("README.txt" in files)
59
def test_empty_package_dir (self):
60
# See SF 1668596/1720897.
63
# create the distribution files.
64
sources = self.mkdtemp()
65
open(os.path.join(sources, "__init__.py"), "w").close()
67
testdir = os.path.join(sources, "doc")
69
open(os.path.join(testdir, "testfile"), "w").close()
72
sys.stdout = StringIO.StringIO()
75
dist = Distribution({"packages": ["pkg"],
76
"package_dir": {"pkg": ""},
77
"package_data": {"pkg": ["doc/*"]}})
78
# script_name need not exist, it just need to be initialized
79
dist.script_name = os.path.join(sources, "setup.py")
80
dist.script_args = ["build"]
81
dist.parse_command_line()
85
except DistutilsFileError:
86
self.fail("failed package_data test when package_dir is ''")
90
sys.stdout = sys.__stdout__
93
return unittest.makeSuite(BuildPyTestCase)
95
if __name__ == "__main__":
96
unittest.main(defaultTest="test_suite")