예제 #1
0
파일: console_test.py 프로젝트: leotrs/decu
def test_exec_empty_file(tmpdir):
    """`decu exec` on an empty file should error out."""
    main.init(str(tmpdir))
    src_dir = config['Script']['scripts_dir']
    empty_fn = tmpdir.join(src_dir, 'empty.py')
    empty_fn.open('w+').close()
    with pytest.raises(CalledProcessError):
        check_call(['decu', 'exec', str(empty_fn)])
예제 #2
0
파일: console_test.py 프로젝트: leotrs/decu
def test_exec_no_class(tmpdir):
    """`decu exec` on a file without a Script class should error out."""
    main.init(str(tmpdir))
    src_dir = config['Script']['scripts_dir']
    filename = tmpdir.join(src_dir, 'empty.py')
    with filename.open('w+') as file:
        file.write('import decu\nclass MyScript():\n    pass')
    with pytest.raises(CalledProcessError):
        check_call(['decu', 'exec', str(filename)])
예제 #3
0
파일: console_test.py 프로젝트: leotrs/decu
def test_already_initialized_init(tmpdir):
    """`decu init` on an already initialized project shouldn't harm it."""
    dir_names = [
        tmpdir.join(v) for k, v in config['Script'].items()
        if k.endswith('_dir')
    ]
    main.init(str(tmpdir))

    test_dir = tmpdir.join(config['Script']['scripts_dir'])
    test_filename = test_dir.join('foo.txt')
    with test_filename.open('w+') as file:
        file.write('this is a test')

    main.init(str(tmpdir))
    for name in dir_names:
        assert name in tmpdir.listdir()
    assert test_filename in test_dir.listdir()
예제 #4
0
파일: console_test.py 프로젝트: leotrs/decu
def test_init(tmpdir):
    """`decu init` should create the appropriate directories."""
    dir_names = [
        tmpdir.join(v) for k, v in config['Script'].items()
        if k.endswith('_dir')
    ]
    for name in dir_names:
        assert name not in tmpdir.listdir()
    assert main.init(str(tmpdir)) == 0
    for name in dir_names:
        assert name in tmpdir.listdir()
예제 #5
0
파일: config_test.py 프로젝트: leotrs/decu
def test_local_override(tmpdir):
    """A local config file should override the default options."""
    config_filename = 'decu.cfg'
    new_opt = '${time}.log'
    config = '[logging]\nlog_file = {}'.format(new_opt)

    main.init(str(tmpdir))

    with tmpdir.join(config_filename).open('w+') as file:
        file.write(config)

    script = 'import decu\nprint(decu.config["logging"]["log_file"])'
    script_file = tmpdir.join(
        decu.config['Script']['scripts_dir']).join('script.py')
    with script_file.open('w+') as file:
        file.write(script)

    from subprocess import check_output
    curdir = os.getcwd()
    os.chdir(str(tmpdir))
    output = check_output(['python', str(script_file)])
    assert output.decode().strip() == new_opt
    os.chdir(curdir)