From: <pj...@us...> - 2009-04-11 00:25:05
|
Revision: 6212 http://jython.svn.sourceforge.net/jython/?rev=6212&view=rev Author: pjenvey Date: 2009-04-11 00:24:56 +0000 (Sat, 11 Apr 2009) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_cmd_line.py@54387 Modified Paths: -------------- trunk/jython/Lib/test/test_cmd_line.py Modified: trunk/jython/Lib/test/test_cmd_line.py =================================================================== --- trunk/jython/Lib/test/test_cmd_line.py 2009-04-10 23:09:34 UTC (rev 6211) +++ trunk/jython/Lib/test/test_cmd_line.py 2009-04-11 00:24:56 UTC (rev 6212) @@ -1,4 +1,3 @@ -# from CPython 2.4, changing Python to Jython in test_version import test.test_support, unittest import sys @@ -7,14 +6,20 @@ class CmdLineTest(unittest.TestCase): def start_python(self, cmd_line): - outfp, infp = popen2.popen4('%s %s' % (sys.executable, cmd_line)) + outfp, infp = popen2.popen4('"%s" %s' % (sys.executable, cmd_line)) infp.close() data = outfp.read() outfp.close() + # try to cleanup the child so we don't appear to leak when running + # with regrtest -R. This should be a no-op on Windows. + popen2._cleanup() return data - def exit_code(self, cmd_line): - return subprocess.call([sys.executable, cmd_line], stderr=subprocess.PIPE) + def exit_code(self, *args): + cmd_line = [sys.executable] + cmd_line.extend(args) + return subprocess.call(cmd_line, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) def test_directories(self): self.assertNotEqual(self.exit_code('.'), 0) @@ -22,7 +27,7 @@ def verify_valid_flag(self, cmd_line): data = self.start_python(cmd_line) - self.assertTrue(data == '' or data.endswith('\n'), repr(data)) + self.assertTrue(data == '' or data.endswith('\n')) self.assertTrue('Traceback' not in data) def test_environment(self): @@ -42,16 +47,47 @@ self.verify_valid_flag('-S') def test_usage(self): - result = self.start_python('-h') - self.assertTrue('usage' in result, repr(result)) + self.assertTrue('usage' in self.start_python('-h')) def test_version(self): - version = 'Jython %d.%d' % sys.version_info[:2] - result = self.start_python('-V') - self.assertTrue(result.startswith(version), repr(result)) + version = 'Python %d.%d' % sys.version_info[:2] + self.assertTrue(self.start_python('-V').startswith(version)) + def test_run_module(self): + # Test expected operation of the '-m' switch + # Switch needs an argument + self.assertNotEqual(self.exit_code('-m'), 0) + # Check we get an error for a nonexistent module + self.assertNotEqual( + self.exit_code('-m', 'fnord43520xyz'), + 0) + # Check the runpy module also gives an error for + # a nonexistent module + self.assertNotEqual( + self.exit_code('-m', 'runpy', 'fnord43520xyz'), + 0) + # All good if module is located and run successfully + self.assertEqual( + self.exit_code('-m', 'timeit', '-n', '1'), + 0) + + def test_run_code(self): + # Test expected operation of the '-c' switch + # Switch needs an argument + self.assertNotEqual(self.exit_code('-c'), 0) + # Check we get an error for an uncaught exception + self.assertNotEqual( + self.exit_code('-c', 'raise Exception'), + 0) + # All good if execution is successful + self.assertEqual( + self.exit_code('-c', 'pass'), + 0) + + def test_main(): test.test_support.run_unittest(CmdLineTest) + test.test_support.reap_children() if __name__ == "__main__": test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |