def test_build_parser_legacy(): """Assert parser's namespace exposes legacy's options (default values)""" parser = build_parser() options = parser.parse_args(['legacy']) assert isinstance(options, argparse.Namespace) assert hasattr(options, 'config') assert hasattr(options, 'configdir') assert hasattr(options, 'daemonize') assert hasattr(options, 'quiet') assert hasattr(options, 'quit') assert hasattr(options, 'kill') assert hasattr(options, 'restart') assert hasattr(options, 'version') assert hasattr(options, 'version_legacy') assert hasattr(options, 'wizard') assert hasattr(options, 'mod_wizard') assert hasattr(options, 'list_configs') assert options.config == 'default' assert options.configdir == config.DEFAULT_HOMEDIR assert options.daemonize is False assert options.quiet is False assert options.quit is False assert options.kill is False assert options.restart is False assert options.version is False assert options.version_legacy is False assert options.wizard is False assert options.mod_wizard is False assert options.list_configs is False
def test_build_parser_legacy_list_config(): parser = build_parser() options = parser.parse_args(['legacy', '-l']) assert options.list_configs is True options = parser.parse_args(['legacy', '--list']) assert options.list_configs is True
def test_build_parser_legacy_restart(): parser = build_parser() options = parser.parse_args(['legacy', '-r']) assert options.restart is True options = parser.parse_args(['legacy', '--restart']) assert options.restart is True
def test_build_parser_legacy_config(): parser = build_parser() options = parser.parse_args(['legacy', '-c', 'custom']) assert options.config == 'custom' options = parser.parse_args(['legacy', '--config', 'custom']) assert options.config == 'custom'
def test_build_parser_legacy_kill(): parser = build_parser() options = parser.parse_args(['legacy', '-k']) assert options.kill is True options = parser.parse_args(['legacy', '--kill']) assert options.kill is True
def test_build_parser_legacy_quit(): parser = build_parser() options = parser.parse_args(['legacy', '-q']) assert options.quit is True options = parser.parse_args(['legacy', '--quit']) assert options.quit is True
def test_build_parser_legacy_daemonize(): parser = build_parser() options = parser.parse_args(['legacy', '-d']) assert options.daemonize is True options = parser.parse_args(['legacy', '--fork']) assert options.daemonize is True
def get_opts(self): parser = build_parser() if not len(sys.argv[1:]): argv = ['legacy'] else: argv = sys.argv[1:] return parser.parse_args(argv)
def test_build_parser_start_daemonize(): parser = build_parser() options = parser.parse_args(['start', '-d']) assert options.daemonize is True options = parser.parse_args(['start', '--fork']) assert options.daemonize is True
def test_build_parser_restart_config(): parser = build_parser() options = parser.parse_args(['restart', '-c', 'custom']) assert options.config == 'custom' options = parser.parse_args(['restart', '--config', 'custom']) assert options.config == 'custom'
def test_get_pid_filename_default(): """Assert function returns the default filename from given ``pid_dir``""" pid_dir = '/pid' parser = build_parser() options = parser.parse_args(['legacy']) result = get_pid_filename(options, pid_dir) assert result == pid_dir + '/sopel.pid'
def test_get_pid_filename_ext_not_cfg(): """Assert function keeps the config file extension when it is not cfg""" pid_dir = '/pid' parser = build_parser() options = parser.parse_args(['legacy', '-c', 'test.ini']) result = get_pid_filename(options, pid_dir) assert result == pid_dir + '/sopel-test.ini.pid'
def test_build_parser_stop_kill(): parser = build_parser() options = parser.parse_args(['stop', '-k']) assert options.kill is True options = parser.parse_args(['stop', '--kill']) assert options.kill is True
def test_build_parser_restart(): """Assert parser's namespace exposes restart's options (default values)""" parser = build_parser() options = parser.parse_args(['restart']) assert isinstance(options, argparse.Namespace) assert hasattr(options, 'config') assert hasattr(options, 'quiet') assert options.config is None assert options.quiet is False
def test_build_parser_configure(): """Assert parser's namespace exposes configure's options (default values)""" parser = build_parser() options = parser.parse_args(['configure']) assert isinstance(options, argparse.Namespace) assert hasattr(options, 'config') assert hasattr(options, 'modules') assert options.config is None assert options.modules is False
def test_build_parser_legacy_version(): parser = build_parser() options = parser.parse_args(['legacy', '-v']) assert options.version is False assert options.version_legacy is True options = parser.parse_args(['legacy', '-V']) assert options.version is True assert options.version_legacy is False options = parser.parse_args(['legacy', '--version']) assert options.version is True assert options.version_legacy is False
def test_build_parser_legacy_wizard(): parser = build_parser() options = parser.parse_args(['legacy', '-w']) assert options.wizard is True assert options.mod_wizard is False options = parser.parse_args(['legacy', '--configure-all']) assert options.wizard is True assert options.mod_wizard is False options = parser.parse_args(['legacy', '--configure-modules']) assert options.wizard is False assert options.mod_wizard is True
def test_get_configuration(tmpdir): """Assert function returns a Sopel ``Config`` object""" working_dir = tmpdir.mkdir("working") working_dir.join('default.cfg').write('\n'.join( ['[core]', 'owner = TestName'])) parser = build_parser() options = parser.parse_args(['legacy', '-c', 'default.cfg']) with cd(working_dir.strpath): result = get_configuration(options) assert isinstance(result, config.Config) assert result.core.owner == 'TestName'
def test_build_parser_configure(): """Assert parser's namespace exposes configure's options (default values)""" parser = build_parser() options = parser.parse_args(['configure']) assert isinstance(options, argparse.Namespace) assert hasattr(options, 'config') assert hasattr(options, 'configdir') assert hasattr(options, 'plugins') assert options.config == 'default' assert options.configdir == config.DEFAULT_HOMEDIR assert options.plugins is False
def test_build_parser_stop(): """Assert parser's namespace exposes stop's options (default values)""" parser = build_parser() options = parser.parse_args(['stop']) assert isinstance(options, argparse.Namespace) assert hasattr(options, 'config') assert hasattr(options, 'configdir') assert hasattr(options, 'kill') assert hasattr(options, 'quiet') assert options.config == 'default' assert options.configdir == config.DEFAULT_HOMEDIR assert options.kill is False assert options.quiet is False
def test_get_pid_filename_named(): """Assert function returns a specific filename when config (with extension) is set""" pid_dir = '/pid' parser = build_parser() # With extension options = parser.parse_args(['legacy', '-c', 'test.cfg']) result = get_pid_filename(options, pid_dir) assert result == pid_dir + '/sopel-test.pid' # Without extension options = parser.parse_args(['legacy', '-c', 'test']) result = get_pid_filename(options, pid_dir) assert result == pid_dir + '/sopel-test.pid'
def __init__(self): self.dict = {} # Load config parser = build_parser() if not len(sys.argv[1:]): argv = ['legacy'] else: argv = sys.argv[1:] opts = parser.parse_args(argv) self.config = get_configuration(opts) self.setup_config() # load as dict config = configparser.ConfigParser() config.read(self.config.filename) for each_section in config.sections(): if each_section.lower() not in list(self.dict.keys()): self.dict[each_section.lower()] = dict() for (each_key, each_val) in config.items(each_section): if each_key.lower() not in list( self.dict[each_section.lower()].keys()): self.dict[each_section.lower()][ each_key.lower()] = each_val
def test_build_parser_configure_modules(): parser = build_parser() options = parser.parse_args(['configure', '--plugins']) assert options.plugins is True
def test_build_parser_configure_configdir(): parser = build_parser() options = parser.parse_args(['configure', '--config-dir', 'custom']) assert options.configdir == 'custom'
def test_build_parser_restart_quiet(): parser = build_parser() options = parser.parse_args(['restart', '--quiet']) assert options.quiet is True
def test_build_parser_stop_quiet(): parser = build_parser() options = parser.parse_args(['stop', '--quiet']) assert options.quiet is True