blob: fc0c2d2c31b84852fbdb37edee3e03a22dfcedfa [file] [log] [blame]
Neal Norwitz11bd1192005-10-03 00:54:56 +00001
2import test.test_support, unittest
3import sys
4import popen2
5
6class 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
46def test_main():
47 test.test_support.run_unittest(CmdLineTest)
48
49if __name__ == "__main__":
50 test_main()