0001 """Tests for distutils.command.build_scripts.""" 0002 0003 import os 0004 import unittest 0005 0006 from distutils.command.build_scripts import build_scripts 0007 from distutils.core import Distribution 0008 0009 from distutils.tests import support 0010 0011 0012 class BuildScriptsTestCase(support.TempdirManager, 0013 support.LoggingSilencer, 0014 unittest.TestCase): 0015 0016 def test_default_settings(self): 0017 cmd = self.get_build_scripts_cmd("/foo/bar", []) 0018 self.assert_(not cmd.force) 0019 self.assert_(cmd.build_dir is None) 0020 0021 cmd.finalize_options() 0022 0023 self.assert_(cmd.force) 0024 self.assertEqual(cmd.build_dir, "/foo/bar") 0025 0026 def test_build(self): 0027 source = self.mkdtemp() 0028 target = self.mkdtemp() 0029 expected = self.write_sample_scripts(source) 0030 0031 cmd = self.get_build_scripts_cmd(target, 0032 [os.path.join(source, fn) 0033 for fn in expected]) 0034 cmd.finalize_options() 0035 cmd.run() 0036 0037 built = os.listdir(target) 0038 for name in expected: 0039 self.assert_(name in built) 0040 0041 def get_build_scripts_cmd(self, target, scripts): 0042 import sys 0043 dist = Distribution() 0044 dist.scripts = scripts 0045 dist.command_obj["build"] = support.DummyCommand( 0046 build_scripts=target, 0047 force=1, 0048 executable=sys.executable 0049 ) 0050 return build_scripts(dist) 0051 0052 def write_sample_scripts(self, dir): 0053 expected = [] 0054 expected.append("script1.py") 0055 self.write_script(dir, "script1.py", 0056 ("#! /usr/bin/env python2.3\n" 0057 "# bogus script w/ Python sh-bang\n" 0058 "pass\n")) 0059 expected.append("script2.py") 0060 self.write_script(dir, "script2.py", 0061 ("#!/usr/bin/python\n" 0062 "# bogus script w/ Python sh-bang\n" 0063 "pass\n")) 0064 expected.append("shell.sh") 0065 self.write_script(dir, "shell.sh", 0066 ("#!/bin/sh\n" 0067 "# bogus shell script w/ sh-bang\n" 0068 "exit 0\n")) 0069 return expected 0070 0071 def write_script(self, dir, name, text): 0072 f = open(os.path.join(dir, name), "w") 0073 f.write(text) 0074 f.close() 0075 0076 0077 def test_suite(): 0078 return unittest.makeSuite(BuildScriptsTestCase) 0079 0080 if __name__ == "__main__": 0081 unittest.main(defaultTest="test_suite") 0082
Generated by PyXR 0.9.4