def test_changing_prefix_works(): pyconfig.etcd(prefix='pyconfig/other') eq_(pyconfig.etcd().prefix, '/pyconfig/other/') conf = pyconfig.etcd().load() eq_(conf, {}) pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test') eq_(pyconfig.etcd().prefix, '/pyconfig_test/test/')
def test_watching(): # Enable watching os.environ['PYCONFIG_ETCD_WATCH'] = 'true' pyconfig.Config().clear() pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/watching') pyconfig.reload() # Wait for 20ms before writing to ensure the watcher thread is ready time.sleep(0.020) # Write a new value directly to etcd pyconfig.etcd().client.write('pyconfig_test/watching/it.works', pytool.json.as_json(True)) # Try to get the value... this is a bit sloppy but good luck doing # something better retry = 50 while retry: retry -= 1 if pyconfig.get('it.works', None) is not None: break # Wait 20ms more for it to show up time.sleep(0.020) eq_(pyconfig.get('it.works', False), True)
def main(): """Create a bdb entry.""" parser = argparse.ArgumentParser( description="Create a BDB entry. The BDB entry (.bdb) or WHY NOT\ (.whynot) file, log and json files will be created in a separate\ directory using the given pdb_id and the directory structure:\ BDB_ROOT/ab/1abc/1abc.(bdb|whynot|log|json)") parser.add_argument("-v", "--verbose", help="show verbose output", action="store_true") parser.add_argument("bdb_root_path", help="Root directory of the bdb data.", type=lambda x: is_valid_directory(parser, x)) parser.add_argument("pdb_file_path", help="PDB file location.", type=lambda x: is_valid_file(parser, x)) parser.add_argument("pdb_id", help="PDB accession code.", type=lambda x: is_valid_pdbid(parser, x)) args = parser.parse_args() pyconfig.set("BDB_FILE_DIR_PATH", get_bdb_entry_outdir(args.bdb_root_path, args.pdb_id)) init_logger(args.pdb_id, args.verbose) # Check that the system has the required programs and libraries installed check_deps() if create_bdb_entry(pdb_file_path=args.pdb_file_path, pdb_id=args.pdb_id, verbose=args.verbose): _log.debug("Finished bdb entry.")
def test_setting_change(): class Test(object): setting = pyconfig.Setting('test_setting_change', 'value') eq_(Test.setting, 'value') eq_(Test().setting, 'value') pyconfig.set('test_setting_change', 'value2') eq_(Test.setting, 'value2') eq_(Test().setting, 'value2')
def test_inheritance_works(): pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2') conf = pyconfig.etcd().load() eq_(conf.get('pyconfig.json'), {"a": "b"}) eq_(conf.get('pyconfig.string'), 'Value') eq_(conf.get('pyconfig.boolean'), True) eq_(conf.get('pyconfig.number'), 2) eq_(conf.get('config.inherit'), '/pyconfig_test/test/') pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test')
def test_setting_no_default(): class Test(object): setting_no_default = pyconfig.Setting('test_setting_no_default', allow_default=False) # lambda because assert_raises needs a callable assert_raises(LookupError, lambda: Test.setting_no_default) pyconfig.set('test_setting_no_default', 'new_value') eq_(Test.setting_no_default, 'new_value')
def test_ensure_index_can_be_skipped(): class Test(Document): config_database = database_name() config_collection = 'test' config_indexes = [Index('value')] value = 'v' with DBTest: with mock.patch.object(Test, 'collection') as coll: coll.find_one.__name__ = 'find_one' pyconfig.set('humbledb.ensure_indexes', False) Test.find_one() pyconfig.set('humbledb.ensure_indexes', True) eq_(coll.ensure_index.called, False)
def setup(): if not pyconfig.etcd().module: raise SkipTest("etcd not installed") if not pyconfig.etcd().configured: raise SkipTest("etcd not configured") pyconfig.set('pyconfig.etcd.prefix', '/pyconfig_test/test/') client = pyconfig.etcd().client client.set('pyconfig_test/test/pyconfig.number', pytool.json.as_json(1)) client.set('pyconfig_test/test/pyconfig.boolean', pytool.json.as_json(True)) client.set('pyconfig_test/test/pyconfig.string', pytool.json.as_json("Value")) client.set('pyconfig_test/test/pyconfig.json', pytool.json.as_json({"a": "b"})) client.set('pyconfig_test/test2/pyconfig.number', pytool.json.as_json(2)) client.set('pyconfig_test/test2/config.inherit', pytool.json.as_json('/pyconfig_test/test/'))
def test_import_all_beards_return_None(self): pyconfig.set('config_file', os.path.abspath('config.yml.example')) with open(pyconfig.get('config_file')) as config_file: for k, v in yaml.load(config_file).items(): pyconfig.set(k, v) beard_paths = pyconfig.get('beard_paths') pyconfig.set('beard_paths', [os.path.expanduser(x) for x in beard_paths]) stache_paths = pyconfig.get('stache_paths') pyconfig.set('stache_paths', [os.path.expanduser(x) for x in stache_paths]) for path in pyconfig.get('beard_paths'): with PythonPathContext(path): for beard in pyconfig.get('beards'): try: importlib.import_module(beard) except ImportError: pass # Once the modules are imported (or not), reimporting will return only # the module. If we get an ImportError here, then one of them has gone # wrong successfully_imported_modules = [] import_exceptions = [] for beard in pyconfig.get('beards'): try: mod = importlib.import_module(beard) successfully_imported_modules.append(mod) except ImportError as e: import_exceptions.append(e) if import_exceptions: self.fail("We got problems: {}".format("\n".join( str(e) for e in import_exceptions)))
def test_get_flag_return_cli_flags(): pyconfig.set('cli.flags.fly', True) assert get_flag('fly') is True
"""Configure logging and user settings.""" import logging # Configure logging LOG = logging.getLogger(__name__) FILE = logging.FileHandler('mongo-bdb.log', 'a') LOG.addHandler(FILE) FORMATTER = logging.Formatter('%(asctime)s | %(levelname)-7s | %(message)s ') LOG.setLevel(logging.DEBUG) FILE.setFormatter(FORMATTER) LOG.debug('Initialized logger.') import json import pyconfig with open('settings.json', 'r') as file_handle: settings = json.load(file_handle) for key, value in settings.iteritems(): pyconfig.set(key, value) LOG.debug('Read settings.')
def test_case_sensitive(): pyconfig.set('pyconfig.case_sensitive', True) pyconfig.set('CaseSensitive', True) eq_(pyconfig.get('CaseSensitive'), True) eq_(pyconfig.get('casesensitive'), None) pyconfig.reload(clear=True)
def test_set_get_change(): pyconfig.set('set_get_change', 'testing') eq_(pyconfig.get('set_get_change'), 'testing') pyconfig.set('set_get_change', 'tested') eq_(pyconfig.get('set_get_change'), 'tested')
def test_reload_work_with_inheritance(): pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2') pyconfig.reload()
def test_case_insensitivity(): pyconfig.set('SomeSetting', True) eq_(pyconfig.get('SomeSetting'), True) eq_(pyconfig.get('somesetting'), True)
def test_autoloading_etcd_config_works(): pyconfig.Config().clear() pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2') pyconfig.reload() eq_(pyconfig.get('pyconfig.string'), 'Value') eq_(pyconfig.get('pyconfig.number'), 2)
def setup_beards(cls, key, db_url): """Perform setup necessary for all beards.""" pyconfig.set('key', key) pyconfig.set('db_url', db_url) cls.key = key cls.db_url = db_url
# BDB: A databank of PDB entries with full isotropic B-factors. # Copyright (C) 2014 Wouter G. Touw (<*****@*****.**>) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License in the # LICENSE file that should have been included as part of this package. # If not, see <http://www.gnu.org/licenses/>. import pyconfig # Default path to the dir with BDB, log, json and WHY NOT files pyconfig.set("BDB_FILE_DIR_PATH", ".") # TLSANL log file names pyconfig.set("TLSANL_LOG", "tlsanl.log") pyconfig.set("TLSANL_ERR", "tlsanl.err")
def test_set_and_get(): pyconfig.set('set_and_get', 'tested') eq_(pyconfig.get('set_and_get'), 'tested')
parser.add_argument('--start-server', action='store_const', const=True, default=False) parser.add_argument('--no-auto-pip', action='store_const', const=True, default=False) parser.add_argument('--auto-pip-upgrade', action='store_const', const=True, default=False) parsed = parser.parse_args() pyconfig.set('config_file', os.path.abspath(parsed.config_file)) # Load the config file and put it into pyconfig with open(pyconfig.get('config_file')) as config_file: for k, v in yaml.load(config_file).items(): pyconfig.set(k, v) beard_paths = pyconfig.get('beard_paths') pyconfig.set('beard_paths', [os.path.expanduser(x) for x in beard_paths]) stache_paths = pyconfig.get('stache_paths') pyconfig.set('stache_paths', [os.path.expanduser(x) for x in stache_paths]) pyconfig.set('loglevel', parsed.loglevel) pyconfig.set('start_server', parsed.start_server) pyconfig.set('no_auto_pip', parsed.no_auto_pip) pyconfig.set('auto_pip_upgrade', parsed.auto_pip_upgrade)
def set_flag(flag: str, value: Any) -> None: """Store a CLI flag in the config as "cli.flags.FLAG".""" pyconfig.set(f"cli.flags.{flag}", value)
async def bot_message_loop_and_aiothttp_session(): async with aiohttp.ClientSession() as session: pyconfig.set('aiohttp_session', session) await bot.message_loop()
def do_set_flag(flag: str, value: Any) -> None: """Store config values in global singleton config.""" pyconfig.set(f"{flag}", value)
import argparse import pyconfig import logging import yaml parser = argparse.ArgumentParser() parser.add_argument("--config", help="The config file to load", default="config.yaml", type=str) args = parser.parse_args() logging.basicConfig() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logger.info("loading config file") with open (args.config, "r") as f: config = yaml.load(f) logger.info("setting up default values") for key, value in config.items(): pyconfig.set(key, value) import service from rpyc.utils.server import ThreadedServer t = ThreadedServer(service.FreedomService, hostname = config['host'], port = config['port'], logger=logger, protocol_config = {"allow_public_attrs" : True}) t.start()
def do_set_multi_flag(data: List[Tuple]) -> None: """Multi - Store a CLI flag in the config as "FLAG".""" for d in data: pyconfig.set(f"{d[0]}", d[1])