def test_plugin_with_unsupporetd_option_type_in_spec(plugin_manager_fixture): """Tests that the user get a proper error :param plugin_manager_fixture: Fixture object which yields InfraredPluginManger object """ plugin_dir = os.path.join(SAMPLE_PLUGINS_DIR, 'plugin_with_unsupported_option_type_in_spec') plugin_dict = get_plugin_spec_flatten_dict(plugin_dir) plugin_manager = plugin_manager_fixture() plugin_manager.add_plugin(plugin_dir) from infrared.main import main as ir_main with pytest.raises(IRUnsupportedSpecOptionType): ir_main([plugin_dict['name'], '--help'])
def test_list_yamls_in_help_screen(plugin_manager_fixture): # noqa """Tests that __LISTYAMLS__ placeholder works '__LISTYAMLS__' placeholder in help field of spec's option should be replaced with a list pf available YAML files :param plugin_manager_fixture: Fixture object which yields InfraredPluginManger object """ topology_help = """ --topology TOPOLOGY help of topology option Available values: {}""".format( list(set(['undercloud', 'compute'])) ) topology_network_help = """ --topology-networks TOPOLOGY-NETWORKS help of topology-networks option Available values: """.format( list(set(['3_nics', '2_nics', '1_nics'])) ) plugin_manager = plugin_manager_fixture() plugin_dir = os.path.join(SAMPLE_PLUGINS_DIR, 'help_screen_plugin_with_list_yamls') plugin_dict = get_plugin_spec_flatten_dict(plugin_dir) plugin_manager.add_plugin(plugin_dir) help_cmd = ['ir', plugin_dict['name'], '--help'] # Also replaces sys.argv[0] from 'pytest' to 'ir' sys.argv = help_cmd sys.stdout = mystdout = StringIO() try: # argparse raises SystemExit after printing help screen with pytest.raises(SystemExit) as ex: ir_main() assert ex.value.code == 0, \ "Return code of help cmd '{}' is {}".format( ' '.join(help_cmd), ex.code) finally: sys.stdout = sys.__stdout__ rtrn_str = mystdout.getvalue() returned_str = rtrn_str[:rtrn_str.rfind('<StringIO.StringIO instance')] assert topology_help in returned_str assert topology_network_help in returned_str
def test_plugin_cli(plugin_manager_fixture, input_args, plugins_conf): """Tests that plugin CLI works :param plugin_manager_fixture: Fixture object which yields InfraredPluginManger object :param input_args: infrared's testing arguments :param plugins_conf: Plugins conf data as a dictionary """ plugin_manager_fixture(plugins_conf) from infrared.main import main as ir_main rc = ir_main(input_args.split()) assert rc == 0, \ "Return code ({}) != 0, cmd='infrared {}'".format(rc, input_args)