def ctx(): old = context.RunContext().values context.clear() yield context.RunContext() context.RunContext().values = old
def test_prints_debug_info_if_verbose_lvl_ge_3(p_cprint): # type: (Mock) -> None files = types.FilesCollection.from_config({ 'paths': ['path1', 'path2'], }) context.RunContext().set('verbose', 3) fs.collect_files(files) context.RunContext().set('verbose', 0) assert next( (True for x in p_cprint.call_args_list if 'only_staged: ' in x[0][0]), False) assert next( (True for x in p_cprint.call_args_list if 'untracked: ' in x[0][0]), False) assert next( (True for x in p_cprint.call_args_list if 'whitelist: ' in x[0][0]), False) assert next( (True for x in p_cprint.call_args_list if 'blacklist: ' in x[0][0]), False)
def collect_files(files: types.FilesCollection) -> List[str]: """ Collect files using the given configuration. """ paths = [conf.proj_path(p) for p in files.paths] if context.RunContext().get('verbose', 0) >= 3: log.info("<35>Files:") log.info("only_staged: <33>{}".format(files.only_staged)) log.info("untracked: <33>{}".format(files.untracked)) log.info("whitelist: <33>\n{}".format('\n'.join(files.whitelist()))) log.info("blacklist: <33>\n{}".format('\n'.join(files.blacklist()))) if files.only_staged and files.include and not files.whitelist(): # include will be empty if none of the staged files match include # and thus the final fs walk will pick up everything. We want # to preserve the include patterns defined in `pelconf.yaml` # so nothing is picked if none of the staged files match. return [] return list( itertools.chain.from_iterable( filtered_walk(path, files.whitelist(), files.blacklist()) for path in paths))
def test_only_one_instance_is_ever_created(): a = context.RunContext() b = context.RunContext() assert a is b