def test_configure_execfile(tmpdir): file = tmpdir.join('foo.py') file.write('MY_CUSTOM_SETTING = "foo"') assert not hasattr(settings, 'MY_CUSTOM_SETTING') settings.configure(str(file)) assert settings.MY_CUSTOM_SETTING == 'foo' delattr(settings, 'MY_CUSTOM_SETTING')
def test_configure_import(tmpdir): file = tmpdir.join('foo.py') file.write('MY_CUSTOM_SETTING = "foo"') sys.path.insert(0, str(tmpdir)) filename = os.path.basename(str(file)).replace('.py', '') assert not hasattr(settings, 'MY_CUSTOM_SETTING') settings.configure(filename) assert settings.MY_CUSTOM_SETTING == 'foo' delattr(settings, 'MY_CUSTOM_SETTING')
def test_custom_plugin_priorities(tmpdir): file = tmpdir.join('foo.py') file.write('\n'.join([ 'PLUGIN_PRIORITY_LOW = 1', 'PLUGIN_PRIORITY_NORMAL = 42', 'PLUGIN_PRIORITY_HIGH = 9000', ])) settings.configure(str(file)) from helga import plugins reload(plugins) assert plugins.PRIORITY_LOW == 1 assert plugins.PRIORITY_NORMAL == 42 assert plugins.PRIORITY_HIGH == 9000
def main(): """ Main entry point for the helga console script """ parser = argparse.ArgumentParser(description='The helga IRC bot') parser.add_argument('--settings', help=( 'Custom helga settings overrides. This should be an importable python module ' 'like "foo.bar.baz" or a path to a settings file like "path/to/settings.py". ' 'This can also be set via the HELGA_SETTINGS environment variable, however ' 'this flag takes precedence.' )) args = parser.parse_args() settings_file = os.environ.get('HELGA_SETTINGS', '') if args.settings: settings_file = args.settings settings.configure(settings_file) run()
def main(): """ Main entry point for the helga console script """ parser = argparse.ArgumentParser(description='The helga IRC bot') parser.add_argument( '--settings', help= ('Custom helga settings overrides. This should be an importable python module ' 'like "foo.bar.baz" or a path to a settings file like "path/to/settings.py". ' 'This can also be set via the HELGA_SETTINGS environment variable, however ' 'this flag takes precedence.')) args = parser.parse_args() settings_file = os.environ.get('HELGA_SETTINGS', '') if args.settings: settings_file = args.settings settings.configure(settings_file) run()
def test_configure_import_raises(): with pytest.raises(ImportError): settings.configure('foo.bar')