Example #1
0
def test_setup_logging():
    logger.debug('test_setup_logging')
    dir_logs = Path(__file__).parent / 'logs'

    with restore_logging():
        setup_logging()

    with restore_logging():
        setup_logging(dir_logs=dir_logs)

    assert dir_logs.exists()
Example #2
0
def create_arg_test(env=None):
    hutch = 'temp_create'
    test_dir = CFG_PATH.parent.parent.parent / hutch
    if test_dir.exists():
        shutil.rmtree(test_dir)

    with cli_args(['hutch_python', '--create', hutch]):
        with restore_logging():
            setup_cli_env()

    assert test_dir.exists()

    # Make sure conf.yml is valid
    load(str(test_dir / 'conf.yml'))

    # Make sure we picked the correct env
    if env is not None:
        with (test_dir / 'temp_createversion').open() as f:
            lines = f.readlines()
        has_env = False
        for line in lines:
            if 'CONDA_ENVNAME' in line:
                has_env = True
                assert env == line.split("'")[-2]
                break
        assert has_env

    shutil.rmtree(test_dir)
Example #3
0
def test_run_script():
    logger.debug('test_run_script')

    # Will throw a name error unless we run the script inside the full env
    with cli_args([
            'hutch_python', '--cfg', CFG, '--debug',
            str(Path(__file__).parent / 'script.py')
    ]):
        with restore_logging():
            main()
Example #4
0
def test_console_handler(log_queue):
    logger.debug('test_console_handler')

    with pytest.raises(RuntimeError):
        handler = get_console_handler()

    with restore_logging():
        setup_queue_console()
        handler = get_console_handler()
        assert isinstance(handler, QueueHandler)
Example #5
0
def test_get_session_logfiles():
    logger.debug('test_get_session_logfiles')
    with restore_logging():
        # Create a parent log file
        setup_logging(dir_logs=Path(__file__).parent / 'logs')
        debug_handler = get_debug_handler()
        debug_handler.doRollover()
        debug_handler.doRollover()
        assert len(get_session_logfiles()) == 3
        assert all([log.startswith(debug_handler.baseFilename)
                    for log in get_session_logfiles()])
Example #6
0
def test_start_user():
    logger.debug('test_start_user')

    with cli_args(['hutch_python', '--cfg', CFG]):
        with restore_logging():
            setup_cli_env()

    # OSError from opening ipython shell
    with pytest.raises(OSError):
        start_user()

    script = str(Path(__file__).parent / 'script.py')

    with cli_args(['hutch_python', '--cfg', CFG, script]):
        with restore_logging():
            setup_cli_env()

    # No OSError because we're just running a print script
    # Setting the name that script.py needs should avoid a NameError because
    # this is supposed to run the script in the enclosing frame
    unique_device = 4  # NOQA
    start_user()
Example #7
0
def test_create_arg():
    logger.debug('test_create_arg_dev')
    hutch = 'temp_create'
    test_dir = CFG_PATH.parent.parent.parent / hutch
    if test_dir.exists():
        shutil.rmtree(test_dir)

    with cli_args(['hutch_python', '--create', hutch]):
        with restore_logging():
            main()

    assert test_dir.exists()

    # Make sure conf.yml is valid
    load(str(test_dir / 'conf.yml'))
    shutil.rmtree(test_dir)
Example #8
0
def test_sim_arg(no_ipython_launch):
    logger.debug('test_sim_arg')

    with cli_args(['hutch_python', '--cfg', CFG, '--sim']):
        with restore_logging():
            main()
Example #9
0
def test_main_no_args(no_ipython_launch):
    logger.debug('test_main_no_args')

    with cli_args(['hutch_python']):
        with restore_logging():
            main()
Example #10
0
def test_main_normal(no_ipython_launch):
    logger.debug('test_main_normal')

    with cli_args(['hutch_python', '--cfg', CFG]):
        with restore_logging():
            main()
Example #11
0
def test_sim_arg():
    logger.debug('test_sim_arg')

    with cli_args(['hutch_python', '--cfg', CFG, '--sim']):
        with restore_logging():
            setup_cli_env()
Example #12
0
def test_setup_cli_no_args():
    logger.debug('test_setup_cli_no_args')

    with cli_args(['hutch_python']):
        with restore_logging():
            setup_cli_env()
Example #13
0
def test_setup_cli_normal():
    logger.debug('test_setup_cli')

    with cli_args(['hutch_python', '--cfg', CFG]):
        with restore_logging():
            setup_cli_env()