PyXR

c:\python24\lib \ distutils \ tests \ test_build_py.py



0001 """Tests for distutils.command.build_py."""
0002 
0003 import os
0004 import unittest
0005 
0006 from distutils.command.build_py import build_py
0007 from distutils.core import Distribution
0008 
0009 from distutils.tests import support
0010 
0011 
0012 class BuildPyTestCase(support.TempdirManager,
0013                       support.LoggingSilencer,
0014                       unittest.TestCase):
0015 
0016     def test_package_data(self):
0017         sources = self.mkdtemp()
0018         f = open(os.path.join(sources, "__init__.py"), "w")
0019         f.write("# Pretend this is a package.")
0020         f.close()
0021         f = open(os.path.join(sources, "README.txt"), "w")
0022         f.write("Info about this package")
0023         f.close()
0024 
0025         destination = self.mkdtemp()
0026 
0027         dist = Distribution({"packages": ["pkg"],
0028                              "package_dir": {"pkg": sources}})
0029         # script_name need not exist, it just need to be initialized
0030         dist.script_name = os.path.join(sources, "setup.py")
0031         dist.command_obj["build"] = support.DummyCommand(
0032             force=0,
0033             build_lib=destination)
0034         dist.packages = ["pkg"]
0035         dist.package_data = {"pkg": ["README.txt"]}
0036         dist.package_dir = {"pkg": sources}
0037 
0038         cmd = build_py(dist)
0039         cmd.compile = 1
0040         cmd.ensure_finalized()
0041         self.assertEqual(cmd.package_data, dist.package_data)
0042 
0043         cmd.run()
0044 
0045         # This makes sure the list of outputs includes byte-compiled
0046         # files for Python modules but not for package data files
0047         # (there shouldn't *be* byte-code files for those!).
0048         #
0049         self.assertEqual(len(cmd.get_outputs()), 3)
0050         pkgdest = os.path.join(destination, "pkg")
0051         files = os.listdir(pkgdest)
0052         self.assert_("__init__.py" in files)
0053         self.assert_("__init__.pyc" in files)
0054         self.assert_("README.txt" in files)
0055 
0056 
0057 def test_suite():
0058     return unittest.makeSuite(BuildPyTestCase)
0059 
0060 if __name__ == "__main__":
0061     unittest.main(defaultTest="test_suite")
0062 

Generated by PyXR 0.9.4
SourceForge.net Logo