def test_parse_arguments_normal(self): argv = "exename -p 3000 -c 127.0.0.1:3001".split() port_number, coder_ip, coder_port = parse_arguments(argv) self.assertEqual(port_number, 3000) self.assertEqual(coder_ip, "127.0.0.1") self.assertEqual(coder_port, 3001) argv = "exename --port 3000 --coder 127.0.0.1:3001".split() port_number, coder_ip, coder_port = parse_arguments(argv) self.assertEqual(port_number, 3000) self.assertEqual(coder_ip, "127.0.0.1") self.assertEqual(coder_port, 3001)
def test_parse_arguments_extra(self): capturedOutput = io.StringIO() sys.stdout = capturedOutput argv = "exename -p 3000 -c 127.0.0.1:3001 -o".split() with self.assertRaises(SystemExit) as cm: port_number, coder_ip, coder_port = parse_arguments(argv) sys.stdout = sys.__stdout__ stdout_msg = capturedOutput.getvalue() self.assertEqual(cm.exception.code, 2) self.assertIn(USAGE_MESSAGE, stdout_msg)