0001 """Tests for distutils.dist.""" 0002 0003 import distutils.cmd 0004 import distutils.dist 0005 import os 0006 import shutil 0007 import sys 0008 import tempfile 0009 import unittest 0010 0011 from test.test_support import TESTFN 0012 0013 0014 class test_dist(distutils.cmd.Command): 0015 """Sample distutils extension command.""" 0016 0017 user_options = [ 0018 ("sample-option=", "S", "help text"), 0019 ] 0020 0021 def initialize_options(self): 0022 self.sample_option = None 0023 0024 0025 class TestDistribution(distutils.dist.Distribution): 0026 """Distribution subclasses that avoids the default search for 0027 configuration files. 0028 0029 The ._config_files attribute must be set before 0030 .parse_config_files() is called. 0031 """ 0032 0033 def find_config_files(self): 0034 return self._config_files 0035 0036 0037 class DistributionTestCase(unittest.TestCase): 0038 0039 def setUp(self): 0040 self.argv = sys.argv[:] 0041 del sys.argv[1:] 0042 0043 def tearDown(self): 0044 sys.argv[:] = self.argv 0045 0046 def create_distribution(self, configfiles=()): 0047 d = TestDistribution() 0048 d._config_files = configfiles 0049 d.parse_config_files() 0050 d.parse_command_line() 0051 return d 0052 0053 def test_command_packages_unspecified(self): 0054 sys.argv.append("build") 0055 d = self.create_distribution() 0056 self.assertEqual(d.get_command_packages(), ["distutils.command"]) 0057 0058 def test_command_packages_cmdline(self): 0059 sys.argv.extend(["--command-packages", 0060 "foo.bar,distutils.tests", 0061 "test_dist", 0062 "-Ssometext", 0063 ]) 0064 d = self.create_distribution() 0065 # let's actually try to load our test command: 0066 self.assertEqual(d.get_command_packages(), 0067 ["distutils.command", "foo.bar", "distutils.tests"]) 0068 cmd = d.get_command_obj("test_dist") 0069 self.assert_(isinstance(cmd, test_dist)) 0070 self.assertEqual(cmd.sample_option, "sometext") 0071 0072 def test_command_packages_configfile(self): 0073 sys.argv.append("build") 0074 f = open(TESTFN, "w") 0075 try: 0076 print >>f, "[global]" 0077 print >>f, "command_packages = foo.bar, splat" 0078 f.close() 0079 d = self.create_distribution([TESTFN]) 0080 self.assertEqual(d.get_command_packages(), 0081 ["distutils.command", "foo.bar", "splat"]) 0082 0083 # ensure command line overrides config: 0084 sys.argv[1:] = ["--command-packages", "spork", "build"] 0085 d = self.create_distribution([TESTFN]) 0086 self.assertEqual(d.get_command_packages(), 0087 ["distutils.command", "spork"]) 0088 0089 # Setting --command-packages to '' should cause the default to 0090 # be used even if a config file specified something else: 0091 sys.argv[1:] = ["--command-packages", "", "build"] 0092 d = self.create_distribution([TESTFN]) 0093 self.assertEqual(d.get_command_packages(), ["distutils.command"]) 0094 0095 finally: 0096 os.unlink(TESTFN) 0097 0098 0099 def test_suite(): 0100 return unittest.makeSuite(DistributionTestCase) 0101
Generated by PyXR 0.9.4