Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / distutils / tests / test_build_py.py
CommitLineData
920dae64
AT
1"""Tests for distutils.command.build_py."""
2
3import os
4import unittest
5
6from distutils.command.build_py import build_py
7from distutils.core import Distribution
8
9from distutils.tests import support
10
11
12class BuildPyTestCase(support.TempdirManager,
13 support.LoggingSilencer,
14 unittest.TestCase):
15
16 def test_package_data(self):
17 sources = self.mkdtemp()
18 f = open(os.path.join(sources, "__init__.py"), "w")
19 f.write("# Pretend this is a package.")
20 f.close()
21 f = open(os.path.join(sources, "README.txt"), "w")
22 f.write("Info about this package")
23 f.close()
24
25 destination = self.mkdtemp()
26
27 dist = Distribution({"packages": ["pkg"],
28 "package_dir": {"pkg": sources}})
29 # script_name need not exist, it just need to be initialized
30 dist.script_name = os.path.join(sources, "setup.py")
31 dist.command_obj["build"] = support.DummyCommand(
32 force=0,
33 build_lib=destination)
34 dist.packages = ["pkg"]
35 dist.package_data = {"pkg": ["README.txt"]}
36 dist.package_dir = {"pkg": sources}
37
38 cmd = build_py(dist)
39 cmd.compile = 1
40 cmd.ensure_finalized()
41 self.assertEqual(cmd.package_data, dist.package_data)
42
43 cmd.run()
44
45 # This makes sure the list of outputs includes byte-compiled
46 # files for Python modules but not for package data files
47 # (there shouldn't *be* byte-code files for those!).
48 #
49 self.assertEqual(len(cmd.get_outputs()), 3)
50 pkgdest = os.path.join(destination, "pkg")
51 files = os.listdir(pkgdest)
52 self.assert_("__init__.py" in files)
53 self.assert_("__init__.pyc" in files)
54 self.assert_("README.txt" in files)
55
56
57def test_suite():
58 return unittest.makeSuite(BuildPyTestCase)
59
60if __name__ == "__main__":
61 unittest.main(defaultTest="test_suite")