Neal Norwitz | 11bd119 | 2005-10-03 00:54:56 +0000 | [diff] [blame] | 1 | |
| 2 | import test.test_support, unittest |
| 3 | import sys |
| 4 | import popen2 |
Walter Dörwald | 9356fb9 | 2005-11-25 15:22:10 +0000 | [diff] [blame^] | 5 | import subprocess |
Neal Norwitz | 11bd119 | 2005-10-03 00:54:56 +0000 | [diff] [blame] | 6 | |
| 7 | class CmdLineTest(unittest.TestCase): |
| 8 | def start_python(self, cmd_line): |
| 9 | outfp, infp = popen2.popen4('%s %s' % (sys.executable, cmd_line)) |
| 10 | infp.close() |
| 11 | data = outfp.read() |
| 12 | outfp.close() |
| 13 | return data |
| 14 | |
Walter Dörwald | 9356fb9 | 2005-11-25 15:22:10 +0000 | [diff] [blame^] | 15 | def exit_code(self, cmd_line): |
| 16 | return subprocess.call([sys.executable, cmd_line], stderr=subprocess.PIPE) |
| 17 | |
Neal Norwitz | 11bd119 | 2005-10-03 00:54:56 +0000 | [diff] [blame] | 18 | def test_directories(self): |
Walter Dörwald | 9356fb9 | 2005-11-25 15:22:10 +0000 | [diff] [blame^] | 19 | if sys.platform == 'win32': |
| 20 | # Exit code for "python .", Error 13: permission denied = 2 |
| 21 | expected_exit_code = 2 |
Tim Peters | 383d3c0 | 2005-10-30 01:15:38 +0000 | [diff] [blame] | 22 | else: |
Walter Dörwald | 9356fb9 | 2005-11-25 15:22:10 +0000 | [diff] [blame^] | 23 | # Linux has no problem with "python .", Exit code = 0 |
| 24 | expected_exit_code = 0 |
| 25 | self.assertEqual(self.exit_code('.'), expected_exit_code) |
| 26 | |
| 27 | self.assertTrue(self.exit_code('< .') != 0) |
Neal Norwitz | 11bd119 | 2005-10-03 00:54:56 +0000 | [diff] [blame] | 28 | |
| 29 | def verify_valid_flag(self, cmd_line): |
| 30 | data = self.start_python(cmd_line) |
Guido van Rossum | c252c59 | 2005-10-08 20:04:35 +0000 | [diff] [blame] | 31 | self.assertTrue(data == '' or data.endswith('\n')) |
Neal Norwitz | 11bd119 | 2005-10-03 00:54:56 +0000 | [diff] [blame] | 32 | self.assertTrue('Traceback' not in data) |
| 33 | |
| 34 | def test_environment(self): |
| 35 | self.verify_valid_flag('-E') |
| 36 | |
| 37 | def test_optimize(self): |
| 38 | self.verify_valid_flag('-O') |
| 39 | self.verify_valid_flag('-OO') |
| 40 | |
| 41 | def test_q(self): |
| 42 | self.verify_valid_flag('-Qold') |
| 43 | self.verify_valid_flag('-Qnew') |
| 44 | self.verify_valid_flag('-Qwarn') |
| 45 | self.verify_valid_flag('-Qwarnall') |
| 46 | |
| 47 | def test_site_flag(self): |
| 48 | self.verify_valid_flag('-S') |
| 49 | |
| 50 | def test_usage(self): |
| 51 | self.assertTrue('usage' in self.start_python('-h')) |
| 52 | |
| 53 | def test_version(self): |
| 54 | version = 'Python %d.%d' % sys.version_info[:2] |
| 55 | self.assertTrue(self.start_python('-V').startswith(version)) |
| 56 | |
| 57 | def test_main(): |
| 58 | test.test_support.run_unittest(CmdLineTest) |
| 59 | |
| 60 | if __name__ == "__main__": |
| 61 | test_main() |