Beispiel #1
0
class TestConfigSpec(object):
    def setup_method(self):
        self.config_spec = ConfigSpec()

    @pytest.mark.parametrize("option", [
        ('name', basestring, 'default'),
        (u'name', basestring, None),
        (b'name', basestring, None),
        ('name', int, 3),
    ])
    def test_add_option(self, option):
        self.config_spec.add_option(option[0], option[1], option[2])

    def test_add_option_invalid_name(self):
        with pytest.raises(TypeError):
            self.config_spec.add_option(3, int)

    def test_add_option_invalid_type(self):
        with pytest.raises(TypeError):
            self.config_spec.add_option('name', 'string')

    def test_return_value_or_default_nonexistent(self):
        with pytest.raises(KeyError):
            self.config_spec.return_value_or_default('foobar', 30)

    def test_return_value_or_default_wrong_type(self):
        name = 'name'
        default = 'default'
        self.config_spec.add_option(name, basestring, default)
        assert self.config_spec.return_value_or_default(name, 3) == default

    def test_return_value_or_default_none(self):
        name = 'name'
        default = 'default'
        self.config_spec.add_option(name, basestring, default)
        assert self.config_spec.return_value_or_default(name, None) == default

    def test_return_value_or_default_value(self):
        name = 'name'
        default = 'default'
        self.config_spec.add_option(name, basestring, default)

        value = 'value'
        assert self.config_spec.return_value_or_default(name, value) == value
Beispiel #2
0
                            metavar='channel',
                            help='list of channels to connect to on startup')

    arg_parser.add_argument('-p',
                            '--plugins',
                            nargs='*',
                            metavar='plugin',
                            help='list of plugins to load on startup')

    arg_parser.add_argument('--config',
                            metavar='config',
                            help='custom config location')

    # Define the config spec and create a parser for our internal config
    spec = ConfigSpec()
    spec.add_option('nickname', basestring, 'Cardinal')
    spec.add_option('password', basestring, None)
    spec.add_option('network', basestring, 'irc.freenode.net')
    spec.add_option('port', int, 6667)
    spec.add_option('server_password', basestring, None)
    spec.add_option('ssl', bool, False)
    spec.add_option(
        'storage', basestring,
        os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
                     'storage'))
    spec.add_option('channels', list, ['#bots'])
    spec.add_option('plugins', list, [
        'ping', 'help', 'admin', 'join_on_invite', 'urls', 'calculator',
        'lastfm', 'remind', 'weather', 'youtube', 'urbandict'
    ])
    spec.add_option('logging', dict, None)
Beispiel #3
0
    arg_parser.add_argument('-o', '--port', type=int, metavar='port',
        help='network port to connect to')
    arg_parser.add_argument('-P', '--spassword', metavar='server_password',
        help='password to connect to the network with')
    arg_parser.add_argument('-s', '--ssl', action='store_true',
        help='you must set this flag for SSL connections')
    arg_parser.add_argument('-c', '--channels', nargs='*', metavar='channel',
        help='list of channels to connect to on startup')
    arg_parser.add_argument('-p', '--plugins', nargs='*', metavar='plugin',
        help='list of plugins to load on startup')
    arg_parser.add_argument('--config', metavar='config',
        help='custom config location')

    # Define the config spec and create a parser for our internal config
    spec = ConfigSpec()
    spec.add_option('nickname', basestring, 'Cardinal')
    spec.add_option('password', basestring, None)
    spec.add_option('network', basestring, 'irc.freenode.net')
    spec.add_option('port', int, 6667)
    spec.add_option('server_password', basestring, None)
    spec.add_option('ssl', bool, False)
    spec.add_option('channels', list, ['#bots'])
    spec.add_option('plugins', list, [
        'ping',
        'help',
        'admin',
        'join_on_invite',
        'urls',
        'calculator',
        'lastfm',
        'remind',
Beispiel #4
0
below.

https://github.com/JohnMaguire/Cardinal
""", formatter_class=argparse.RawDescriptionHelpFormatter)

    arg_parser.add_argument('-n', '--nickname', metavar='nickname', help='nickname to connect as')
    arg_parser.add_argument('--password', action='store_true', help='set this flag to get a password prompt for identifying')
    arg_parser.add_argument('-i', '--network', metavar='network', help='network to connect to')
    arg_parser.add_argument('-o', '--port', type=int, metavar='port', help='network port to connect to')
    arg_parser.add_argument('-s', '--ssl', action='store_true', help='you must set this flag for SSL connections')
    arg_parser.add_argument('-c', '--channels', nargs='*', metavar='channel', help='list of channels to connect to on startup')
    arg_parser.add_argument('-p', '--plugins', nargs='*', metavar='plugin', help='list of plugins to load on startup')

    # Define the config spec and create a parser for our internal config
    spec = ConfigSpec()
    spec.add_option('nickname', basestring, 'hackercat')
    spec.add_option('password', basestring, None)
    spec.add_option('network', basestring, 'irc.freenode.net')
    spec.add_option('port', int, 6697)
    spec.add_option('ssl', bool, True)
    spec.add_option('channels', list, ['#57N'])
    spec.add_option('plugins', list, [
        'ping',
        'help',
        'admin',
        'join_on_invite',
        'urls',
        'calculator',
        'lastfm',
        'remind',
        'weather',