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)
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)
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)
def test_dot_in_key(self): root = Root(''' server.token.salt: 1345 ''') self.assertEqual(root['server.token.salt'], 1345) self.assertFalse(hasattr(root, 'server'))
def test_dot_in_key(self): root = Root(''' server.token.salt: 1345 ''') assert root['server.token.salt'] == 1345 assert not hasattr(root, 'server')
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]
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')
def test_binary(self): root = Root(''' app: name: MyApp secret: !!binary YWJj\n ''') assert root.app.name == 'MyApp' assert root.secret == b'abc'
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')
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')
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))
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)
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)
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
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)
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
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))
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)
def test_merge_errors(self): root = Root() with pytest.raises(TypeError): root.merge(None)
def test_merge_empty_object(self): root = Root() root.merge('') assert len(root.keys()) == 0
def test_callable_context(self): def context(): return dict(c=3) root = Root('a: %(c)s', context) assert root.a == 3
def test_callable_context(self): def context(): return dict(c=3) root = Root('a: %(c)s', context) self.assertEqual(3, root.a)
def test_merge_empty_object(self): root = Root() root.merge('') self.assertEqual(0, len(root.keys()))
def test_merge_errors(self): root = Root() with self.assertRaises(TypeError): root.merge(None)