def get_error(passed_keys, known_keys): try: check_keys(passed_keys, known_keys) except ValueError as e: return str(e) else: raise AssertionError("ValueError not raised")
def branch(self, branch_id): """ Get the branch with a given ID. In case of multiple branches with the same ID (which should Never Ever Happen), behaviour is undefined. If there is no such branch, LookupErrors will materialise. """ branches_by_id = {x["id"]: x for x in self.branches} check_keys((branch_id,), branches_by_id.keys(), exception=LookupError) return branches_by_id[branch_id]
def from_json(cls, description): """Generate constraints from a JSON description.""" check_keys( description.keys(), ( "anonymous", "named", "era", "required_tags", "excluded_tags", "joined_before", "joined_after", ), ) if "anonymous" in description: warnings.warn("The `anonymous` flag no longer has any effect.") if "named" in description: warnings.warn("The `named` flag no longer has any effect.") def get_maybe_date(key): try: string_date = description[key] except KeyError: return None parsed_date = dateutil.parser.parse(string_date) if parsed_date.tzinfo is None: raise ValueError("Constraint dates must explicitly include timezones.") return parsed_date return cls( era=description.get("era"), required_tags=description.get("required_tags", ()), excluded_tags=description.get("excluded_tags", ()), joined_before=get_maybe_date("joined_before"), joined_after=get_maybe_date("joined_after"), )
to target, picking up the WSGI application from `app`. In this case, the configuration file can be specified through the environment variable `JACQUARD_CONFIG`; if left unspecified, the file 'config.cfg' in the current working directory is assumed. """ import os import logging from jacquard.utils import check_keys from jacquard.config import load_config from jacquard.service import get_wsgi_app from jacquard.constants import DEFAULT_CONFIG_FILE_PATH LOG_LEVEL = os.environ.get("JACQUARD_LOG_LEVEL", "info").lower() KNOWN_LOG_LEVELS = { "debug": logging.DEBUG, "info": logging.INFO, "errors": logging.ERROR } check_keys((LOG_LEVEL,), KNOWN_LOG_LEVELS, RuntimeError) logging.basicConfig(level=KNOWN_LOG_LEVELS[LOG_LEVEL]) wsgi_logger = logging.getLogger("jacquard.wsgi") wsgi_logger.warning("Logging warnings in Jacquard") wsgi_logger.info("Logging informational messages in Jacquard") wsgi_logger.debug("Emitting debug messages from Jacquard") app = get_wsgi_app(load_config(DEFAULT_CONFIG_FILE_PATH))
def test_accepts_with_all_known_keys(keys, included): known_keys = keys used_keys = [ key for key in keys if included.draw(hypothesis.strategies.booleans()) ] check_keys(used_keys, known_keys)