def _update_autocomplete(): from jina.main.parser import get_main_parser, set_pea_parser, \ set_hw_parser, set_flow_parser, set_pod_parser, \ set_check_parser, set_gateway_parser, set_ping_parser, set_client_cli_parser, set_logger_parser def _gaa(parser): _compl = [] for v in parser._actions: if v.option_strings: _compl.extend(v.option_strings) elif v.choices: _compl.extend(v.choices) # filer out single dash, as they serve as abbrev _compl = [k for k in _compl if (not k.startswith('-') or k.startswith('--'))] return _compl compl = { 'commands': _gaa(get_main_parser()), 'completions': { 'pea': _gaa(set_pea_parser()), 'hello-world': _gaa(set_hw_parser()), 'flow': _gaa(set_flow_parser()), 'pod': _gaa(set_pod_parser()), 'check': _gaa(set_check_parser()), 'gateway': _gaa(set_gateway_parser()), 'ping': _gaa(set_ping_parser()), 'client': _gaa(set_client_cli_parser()), 'log': _gaa(set_logger_parser()) } } with open(__file__, 'a') as fp: fp.write(f'\nac_table = {compl}\n')
def test_ping(self): a1 = set_pea_parser().parse_args([]) a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port_ctrl), '--print-response']) a3 = set_ping_parser().parse_args(['0.0.0.1', str(a1.port_ctrl), '--timeout', '1000']) with self.assertRaises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a2) self.assertEqual(cm.exception.code, 0) # test with bad addresss with self.assertRaises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a3) self.assertEqual(cm.exception.code, 1)
def test_ping(): a1 = set_pea_parser().parse_args([]) a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port_ctrl), '--print-response']) a3 = set_ping_parser().parse_args(['0.0.0.1', str(a1.port_ctrl), '--timeout', '1000']) with pytest.raises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a2) assert cm.value.code == 0 # test with bad addresss with pytest.raises(SystemExit) as cm: with BasePea(a1): NetworkChecker(a3) assert cm.value.code == 1
def test_container_ping(self): a4 = set_pea_parser().parse_args(['--image', img_name]) a5 = set_ping_parser().parse_args(['0.0.0.0', str(a4.port_ctrl), '--print-response']) # test with container with self.assertRaises(SystemExit) as cm: with BasePea(a4): NetworkChecker(a5) self.assertEqual(cm.exception.code, 0)