def test_dry_run_args(get_data_mock, items):
    with cli_args(['epicsarch-qs', 'xpplv6818', '--dry-run']):
        with patch('hutch_python.epics_arch.get_items', return_value=items):
            with patch('hutch_python.epics_arch.print_dry_run') as mock:
                main()
            mock.assert_called_once()
            get_data_mock.assert_called_once
Exemple #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)
Exemple #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()
Exemple #4
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()
Exemple #5
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)
Exemple #6
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()
Exemple #7
0
def test_main_no_args(no_ipython_launch):
    logger.debug('test_main_no_args')

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

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

    with cli_args(['hutch_python', '--cfg', CFG, '--sim']):
        with restore_logging():
            setup_cli_env()
Exemple #10
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()
Exemple #11
0
def test_setup_cli_normal():
    logger.debug('test_setup_cli')

    with cli_args(['hutch_python', '--cfg', CFG]):
        with restore_logging():
            setup_cli_env()
def test_create_file_with_bad_path_args(path_mock):
    with cli_args(['epicsarch-qs', 'xpplv6818', '--path', '/my/path/xpp/']):
        with pytest.raises(OSError):
            main()
def test_create_file_with_path_args(path_mock, create_mock):
    with cli_args(['epicsarch-qs', 'xpplv6818', '--path', '/my/path/xpp/']):
        with patch('hutch_python.epics_arch.get_items', return_value=items):
            main()
        create_mock.assert_called_once()
def test_epics_arch_args():
    with cli_args(['epicsarch-qs', 'xpplv6818']):
        with patch('hutch_python.epics_arch.create_file') as mock:
            main()
        mock.assert_called_once()