def test_client_invalid_sleep(self): """Pass an invalid sleep duration""" print(FCN_FMT % function_name()) argv = str_to_argv('%s --port=12345 --sleep=XYZ' % LOG_CLIENT_NAME) with self.assertRaises(SystemExit) as err: log_client.process_cmd_line(argv[1:]) self.assertEqual(err.exception.code, 1)
def test_client_invalid_count(self): """Pass an invalid message count""" print(FCN_FMT % function_name()) argv = str_to_argv('%s --port=12345 --count=XYZ' % LOG_CLIENT_NAME) with self.assertRaises(SystemExit) as cm: log_client.process_cmd_line(argv[1:]) self.assertEqual(cm.exception.code, 1)
def test_client_invalid_option(self): """Try to use an invalid option""" print(FCN_FMT % function_name()) argv = str_to_argv('%s --Xport=12345' % LOG_CLIENT_NAME) with self.assertRaises(SystemExit) as err: log_client.process_cmd_line(argv[1:]) self.assertEqual(err.exception.code, 1)
def test_client_valid_float_sleep(self): """Pass valid sleep duration""" print(FCN_FMT % function_name()) argv = str_to_argv('%s --port=12345 --sleep=1.5' % LOG_CLIENT_NAME) params = log_client.process_cmd_line(argv[1:]) self.assertAlmostEqual(params['sleep'], 1.5)
def test_client_end_msg_to_server(self): """Sending EXIT_SERVER to the server changes the count to 1. Otherwise the client will wait to send the remainder of the count messages.""" print(FCN_FMT % function_name()) argv = str_to_argv('%s --log_msg=%s --count=10000' % (LOG_CLIENT_NAME, log_client.EXIT_SERVER)) params = log_client.process_cmd_line(argv[1:]) self.assertEqual(params['count'], 1) self.assertEqual(params['log_msg'], log_client.EXIT_SERVER) self.assertEqual(params['sleep'], 0)
def test_client_all_params_changed(self): """Change all params from their defaults and check for valid""" print(FCN_FMT % function_name()) port = 12345 count = 10 host = '192.168.1.80' log_msg = 'a_message' svr_exit = 'blah' sleep = 3.1416 echo = True argv = str_to_argv( '%s --port=%d --count=%d --echo=True --sleep=3.1416 --host=%s --log_msg=%s --svr_exit=%s' % (LOG_CLIENT_NAME, port, count, host, log_msg, svr_exit)) params = log_client.process_cmd_line(argv[1:]) self.assertEqual(params['port'], port) self.assertEqual(params['count'], count) self.assertEqual(params['host'], host) self.assertEqual(params['log_msg'], log_msg) self.assertEqual(params['svr_exit'], False) self.assertEqual(params['echo'], echo) self.assertAlmostEqual(params['sleep'], sleep)