def pre(rel_source): """To be executed in a Click sub command. Needed because if this code is in cli() it will be executed when the user runs: <command> <sub command> --help :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py. """ # Setup logging. if not NO_EXECUTE: setup_logging(verbose=config.verbose, colors=not config.no_colors) log = logging.getLogger(__name__) # Change current working directory. if config.chdir: os.chdir(config.chdir) log.debug('Working directory: %s', os.getcwd()) else: config.update(dict(chdir=os.getcwd()), overwrite=True) # Get and verify git root. try: config.update( dict(git_root=get_root(config.git_root or os.getcwd())), overwrite=True) except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError # Look for local config. if config.no_local_conf: config.update(dict(local_conf=None), overwrite=True) elif not config.local_conf: candidates = [ p for p in (os.path.join(s, 'conf.py') for s in rel_source) if os.path.isfile(p) ] if candidates: config.update(dict(local_conf=candidates[0]), overwrite=True) else: log.debug("Didn't find a conf.py in any REL_SOURCE.") elif os.path.basename(config.local_conf) != 'conf.py': log.error('Path "%s" must end with conf.py.', config.local_conf) raise HandledError
def pre(rel_source): """To be executed in a Click sub command. Needed because if this code is in cli() it will be executed when the user runs: <command> <sub command> --help :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py. """ # Setup logging. if not NO_EXECUTE: setup_logging(verbose=config.verbose, colors=not config.no_colors) log = logging.getLogger(__name__) # Change current working directory. if config.chdir: os.chdir(config.chdir) log.debug('Working directory: %s', os.getcwd()) else: config.update(dict(chdir=os.getcwd()), overwrite=True) # Get and verify git root. try: config.update(dict(git_root=get_root(config.git_root or os.getcwd())), overwrite=True) except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError # Look for local config. if config.no_local_conf: config.update(dict(local_conf=None), overwrite=True) elif not config.local_conf: candidates = [p for p in (os.path.join(s, 'conf.py') for s in rel_source) if os.path.isfile(p)] if candidates: config.update(dict(local_conf=candidates[0]), overwrite=True) else: log.debug("Didn't find a conf.py in any REL_SOURCE.") elif os.path.basename(config.local_conf) != 'conf.py': log.error('Path "%s" must end with conf.py.', config.local_conf) raise HandledError
def test_stdout_stderr(capsys, request, verbose): """Verify proper statements go to stdout or stderr. :param capsys: pytest fixture. :param request: pytest fixture. :param int verbose: Verbosity level. """ name = '{}_{}'.format(request.function.__name__, verbose) setup_logging(verbose=verbose, name=name) # Emit. logger = logging.getLogger(name) for attr in ('debug', 'info', 'warning', 'error', 'critical'): getattr(logger, attr)('Test {}.'.format(attr)) time.sleep(0.01) # Collect. stdout, stderr = capsys.readouterr() # Check normal/verbose console. if verbose: assert name in stdout assert name in stderr assert 'Test debug.' in stdout else: assert name not in stdout assert name not in stderr assert 'Test debug.' not in stdout assert 'Test debug.' not in stderr assert 'Test info.' in stdout assert 'Test warning.' not in stdout assert 'Test error.' not in stdout assert 'Test critical.' not in stdout assert 'Test info.' not in stderr assert 'Test warning.' in stderr assert 'Test error.' in stderr assert 'Test critical.' in stderr