def test_hplugin_shortnme_attrib_error(hplugin): "Test for errors if plugin class has empty required attributes" for a in ("okname", "verylongnameexceeeeeeeding", "is spaces allowed?"): setattr(hplugin, "SHORTNAME", a) if len(a) > constants.plugin_shortname_length: with pytest.raises(hp_exceptions.PluginAttributeError) as excinfo: hpm = plugins._plugin_load( hplugin, 'test', _logger=mock.Mock(spec=hlogger.Logger), _manager=PluginManager()) assert "shortname cannot exceed" in str(excinfo.value) else: hpm = plugins._plugin_load(hplugin, 'test', _logger=mock.Mock(spec=hlogger.Logger), _manager=PluginManager())
def test_hplugin_missing_attrib_error(): "Test for errors if plugin class has ommited required attributes" hplugin = type("HPlugin", (), {}) for a, v in (("ID", ""), ("NAME", ""), ("VERSION", (0, 0, 0)), ("AUTHOR", ""), ("DESCRIPTION", "")): with pytest.raises(hp_exceptions.PluginAttributeError) as excinfo: hpm = plugins._plugin_load(hplugin, 'test') assert "attribute is missing" in str(excinfo.value) setattr(hplugin, a, v)
def test_hplugin_empty_attrib_error(hplugin): "Test for errors if plugin class has empty required attributes" for a, v in (("ID", ""), ("NAME", ""), ("VERSION", ()), ("AUTHOR", ""), ("DESCRIPTION", "")): old = getattr(hplugin, a) setattr(hplugin, a, v) with pytest.raises(hp_exceptions.PluginAttributeError) as excinfo: hpm = plugins._plugin_load(hplugin, 'test') assert "attribute cannot be empty" in str(excinfo.value) setattr(hplugin, a, old)
def test_hplugin_logger_creation(m_open, hplugin): "Test plugin-specific logger is created" plugins.registered = PluginManager() p = os.path.join(os.getcwd(), "plugin") p_log = "plugin.log" enc = 'utf-8' hplugin.NAME = "test" node = plugins._plugin_load(hplugin, p) m_open.assert_called_with(os.path.join(p, p_log), 'a', encoding=enc) assert node.logger._logger.name == 'HPX Plugin.' + hplugin.NAME
def start(): utils.setup_dirs() args = parser.parse_args() utils.parse_options(args) utils.setup_logger(args) if args.generate_config: constants.config.save() print("Generated configuration file at '{}'".format( io_cmd.CoreFS(constants.settings_file).path)) return log.i("HPX SERVER START") if not args.only_web: constants.available_commands = command.get_available_commands() constants.core_plugin = plugins._plugin_load( "happypanda.core.coreplugin", "core", _logger=log) if not args.safe: plugins.plugin_loader(constants.dir_plugin) else: plugins.registered.init_plugins() log.i("Starting webserver... ({}:{})".format(constants.host_web, constants.port_web), stdout=True) web_args = (constants.host_web, constants.port_web, constants.dev if args.only_web else False) if args.only_web: server.WebServer().run(*web_args) else: Process(target=server.WebServer().run, args=web_args, daemon=True).start() server.HPServer().run(interactive=args.interact) if not args.only_web: constants.config.save() log.i("HPX SERVER END")
def test_plugin_load(m_open, hplugin): "Test if a plugin can be loaded" hpm = plugins._plugin_load(hplugin, 'test')
def test_hplugin_validuuid_error(hplugin): "Test for error on invalid plugin id" hplugin.ID = "123" with pytest.raises(hp_exceptions.PluginIDError): hpm = plugins._plugin_load(hplugin, 'test')