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 |
| 5 | |
| 6 | class CmdLineTest(unittest.TestCase): |
| 7 | def start_python(self, cmd_line): |
| 8 | outfp, infp = popen2.popen4('%s %s' % (sys.executable, cmd_line)) |
| 9 | infp.close() |
| 10 | data = outfp.read() |
| 11 | outfp.close() |
| 12 | return data |
| 13 | |
| 14 | def test_directories(self): |
| 15 | self.assertTrue('is a directory' in self.start_python('.')) |
| 16 | self.assertTrue('is a directory' in self.start_python('< .')) |
| 17 | |
| 18 | def verify_valid_flag(self, cmd_line): |
| 19 | data = self.start_python(cmd_line) |
| 20 | self.assertTrue(data.endswith('\n')) |
| 21 | self.assertTrue('Traceback' not in data) |
| 22 | |
| 23 | def test_environment(self): |
| 24 | self.verify_valid_flag('-E') |
| 25 | |
| 26 | def test_optimize(self): |
| 27 | self.verify_valid_flag('-O') |
| 28 | self.verify_valid_flag('-OO') |
| 29 | |
| 30 | def test_q(self): |
| 31 | self.verify_valid_flag('-Qold') |
| 32 | self.verify_valid_flag('-Qnew') |
| 33 | self.verify_valid_flag('-Qwarn') |
| 34 | self.verify_valid_flag('-Qwarnall') |
| 35 | |
| 36 | def test_site_flag(self): |
| 37 | self.verify_valid_flag('-S') |
| 38 | |
| 39 | def test_usage(self): |
| 40 | self.assertTrue('usage' in self.start_python('-h')) |
| 41 | |
| 42 | def test_version(self): |
| 43 | version = 'Python %d.%d' % sys.version_info[:2] |
| 44 | self.assertTrue(self.start_python('-V').startswith(version)) |
| 45 | |
| 46 | def test_main(): |
| 47 | test.test_support.run_unittest(CmdLineTest) |
| 48 | |
| 49 | if __name__ == "__main__": |
| 50 | test_main() |