Beispiel #1
0
    def __init__(self):
        from gongish import __version__

        context = {"gongish_version": __version__}
        context.update(os.environ)
        data = {"debug": True}
        self.config = Root(data=data, context=context)
Beispiel #2
0
class ConfigurationMixin:
    def __init__(self):
        from gongish import __version__

        context = {"gongish_version": __version__}
        context.update(os.environ)
        data = {"debug": True}
        self.config = Root(data=data, context=context)

    def configure(self, filename: str):
        self.config.loadfile(filename)
Beispiel #3
0
    def test_merge_list(self):
        root = Root()
        root.merge('''
          a:
            b:
             - 1
             - 2
          c: []
        ''')

        self.assertEqual([1, 2], root.a.b)

        root.c.merge(root.a.b.copy())
        root.a.b.append(3)
        self.assertEqual([1, 2, 3], root.a.b)
        self.assertEqual([1, 2], root.c)
Beispiel #4
0
    def test_dot_in_key(self):
        root = Root('''
            server.token.salt: 1345
        ''')

        self.assertEqual(root['server.token.salt'], 1345)
        self.assertFalse(hasattr(root, 'server'))
Beispiel #5
0
    def test_dot_in_key(self):
        root = Root('''
            server.token.salt: 1345
        ''')

        assert root['server.token.salt'] == 1345
        assert not hasattr(root, 'server')
Beispiel #6
0
    def test_merge_list(self):
        root = Root()
        root.merge('''
          a:
            b:
             - 1
             - 2
          c: []
        ''')

        assert root.a.b == [1, 2]

        root.c.merge(root.a.b.copy())
        root.a.b.append(3)
        assert root.a.b == [1, 2, 3]
        assert root.c == [1, 2]
Beispiel #7
0
    def test_binary(self):
        root = Root('''
            app:
              name: MyApp
            secret: !!binary YWJj\n
        ''')

        self.assertEqual(root.app.name, 'MyApp')
        self.assertEqual(root.secret, b'abc')
Beispiel #8
0
    def test_binary(self):
        root = Root('''
            app:
              name: MyApp
            secret: !!binary YWJj\n
        ''')

        assert root.app.name == 'MyApp'
        assert root.secret == b'abc'
Beispiel #9
0
    def test_load_file(self):
        here = path.dirname(__file__)
        filename = path.join(here, 'files/sample.yml')
        root = Root()
        root.load_file(filename)
        self.assertEqual(2, root.a.b)

        with self.assertRaises(FileNotFoundError):
            root.load_file('not/exists')
Beispiel #10
0
    def test_load_file(self):
        here = path.dirname(__file__)
        filename = path.join(here, 'files/sample.yml')
        root = Root()
        root.load_file(filename)
        assert root.a.b == 2

        with pytest.raises(FileNotFoundError):
            root.load_file('not/exists')
Beispiel #11
0
    def test_simple_syntax(self):
        """
        Testing simple Yaml syntax
        """

        cm = Root(self._builtin)
        self.assertEqual(cm.app.name, "MyApp")
        self.assertEqual(len(cm.app.listen), 2)
        self.assertEqual(cm.app.listen.sock1.addr, "192.168.0.1")
        self.assertEqual(cm.app.listen.sock1.port, 8080)
        self.assertEqual(cm.app.listen.sock2.addr, "127.0.0.1")
        self.assertEqual(cm.app.listen.sock2.port, '89')
        self.assertEqual(cm.logging.logfile, "/var/log/myapp.log")

        self.assertEqual(len(cm.app.languages), 2)
        self.assertEqual(cm.app.languages[0], 'english')
        self.assertEqual(cm.app.languages[1].language, 'persian')
        self.assertEqual(cm.app.languages[1].country, 'iran')
        self.assertEqual(cm.logging.formatter, str)
        self.assertTrue(isinstance(cm.logging.writer, MyWriter))
Beispiel #12
0
    def test_simple_syntax(self):
        """
        Testing simple Yaml syntax
        """

        cm = Root(self._builtin)
        assert cm.app.name == 'MyApp'
        assert len(cm.app.listen) == 2
        assert cm.app.listen.sock1.addr == '192.168.0.1'
        assert cm.app.listen.sock1.port == 8080
        assert cm.app.listen.sock2.addr == '127.0.0.1'
        assert cm.app.listen.sock2.port == '89'
        assert cm.logging.logfile == '/var/log/myapp.log'

        assert len(cm.app.languages) == 2
        assert cm.app.languages[0] == 'english'
        assert cm.app.languages[1].language == 'persian'
        assert cm.app.languages[1].country == 'iran'
        assert cm.logging.formatter == str
        assert isinstance(cm.logging.writer, MyWriter)
Beispiel #13
0
def init_config(config_file=None):
    global _cfg
    if not path.exists(data_dir):
        mkdir(data_dir)

    _cfg = Root(__builtin_config__,
                context=dict(data_dir=data_dir,
                             time_format='"%Y-%m-%d %H:%M"',
                             date_format='"%Y-%m-%d"'))

    if path.exists(user_config_file):
        _cfg.load_file(user_config_file)

    if config_file:
        _cfg.load_file(config_file)
Beispiel #14
0
    def test_merge_deep_object(self):
        root = Root()
        root.merge('''
          a:
            b:
              c: 3
        ''')

        assert root.a.b.c == 3
        root.merge('''
          d:
            e: 1
        ''')

        assert isinstance(root.d, Mergable)

        root.d.merge(root.a)
        assert root.d.b.c == 3

        root.a.b = 2
        assert root.a.b == 2
        assert root.d.b.c == 3
Beispiel #15
0
    def test_merge_deep_object(self):
        root = Root()
        root.merge('''
          a:
            b:
              c: 3
        ''')

        self.assertEqual(3, root.a.b.c)
        root.merge('''
          d:
            e: 1
        ''')

        self.assertIsInstance(root.d, Mergable)

        root.d.merge(root.a)
        self.assertEqual(3, root.d.b.c)

        root.a.b = 2
        self.assertEqual(2, root.a.b)
        self.assertEqual(3, root.d.b.c)
Beispiel #16
0
    def test_constructor(self):
        context = dict(
            c=3
        )

        builtin = '''
          a:
            a1: 1

          b:
          - 1
          - 2
          - %(c)s
        '''

        root = Root(builtin, context)
        assert root.a.a1 == 1
        assert root.b[0] == 1
        assert root.b[1] == 2
        assert root.b[2] == 3

        root.merge('''
          a:
            a2: 2
        ''')
        assert root.a.a2 == 2

        root.a.a3 = 3
        assert root.a.a1 == 1
        assert root.a.a2 == 2
        assert root.a.a3 == 3

        root.merge('''
          b:
            - 4
        ''')
        assert root.b[0] == 4
        assert len(root.b) == 1
Beispiel #17
0
    def test_constructor(self):
        context = dict(c=3)

        builtin = '''
          a:
            a1: 1

          b:
          - 1
          - 2
          - %(c)s
        '''

        root = Root(builtin, context)
        self.assertEqual(root.a.a1, 1)
        self.assertEqual(root.b[0], 1)
        self.assertEqual(root.b[1], 2)
        self.assertEqual(root.b[2], 3)

        root.merge('''
          a:
            a2: 2
        ''')
        self.assertEqual(root.a.a2, 2)

        root.a.a3 = 3
        self.assertEqual(root.a.a1, 1)
        self.assertEqual(root.a.a2, 2)
        self.assertEqual(root.a.a3, 3)

        root.merge('''
          b:
            - 4
        ''')
        self.assertEqual(root.b[0], 4)
        self.assertEqual(1, len(root.b))
Beispiel #18
0
from discord.ext import commands
from urssediscord.commands.StandardCommands import StandardCommands
from urssediscord.commands.SkillTreeCommands import SkillTreeCommands
from urssediscord.events.imagebomb.ImageBomb import ImageBomb
from urssediscord.utilities.Roles import has_role
from urssediscord.events.OnReady import on_ready
from urssediscord.events.OnJoin import on_join

from pymlconf import Root

config = Root()
config.load_file('config/app.yaml')


class SSEBot(commands.Bot):
    def __init__(self,
                 command_prefix,
                 formatter=None,
                 description=None,
                 pm_help=False,
                 **options):
        super().__init__(command_prefix, formatter, description, pm_help,
                         **options)
        self.add_cog(StandardCommands(self))
        self.add_cog(SkillTreeCommands(self))

    async def on_ready(self):
        # This command is commented out for now.
        # When starting the bot, this will give any user without a text channel their own text channel.
        #
        await on_ready(self)
Beispiel #19
0
 def test_merge_errors(self):
     root = Root()
     with pytest.raises(TypeError):
         root.merge(None)
Beispiel #20
0
 def test_merge_empty_object(self):
     root = Root()
     root.merge('')
     assert len(root.keys()) == 0
Beispiel #21
0
    def test_callable_context(self):
        def context():
            return dict(c=3)

        root = Root('a: %(c)s', context)
        assert root.a == 3
Beispiel #22
0
    def test_callable_context(self):
        def context():
            return dict(c=3)

        root = Root('a: %(c)s', context)
        self.assertEqual(3, root.a)
Beispiel #23
0
 def test_merge_empty_object(self):
     root = Root()
     root.merge('')
     self.assertEqual(0, len(root.keys()))
Beispiel #24
0
 def test_merge_errors(self):
     root = Root()
     with self.assertRaises(TypeError):
         root.merge(None)