Example #1
0
def test_from_string(c):
    '''Functional test Config from string'''
    host = 'leon'
    cmd = '{} -E="{}" {}'.format(c.loadconfig_cmd, c.conf, host)
    ret = run(cmd)
    assert 'export SYSTEM_PATH="/data/salt/system"' in ret.stdout
    assert 'export HOST="{}"'.format(host) in ret.stdout
Example #2
0
def test_run_inexistent_cmd():
    ret = run('not_script.sh')
    assert isinstance(ret, text_type)
    assert '' == ret
    assert ret.stderr.startswith('/bin/sh: not_script.sh:')
    assert 127 == ret.code
    assert 127 == ret._r['code']
Example #3
0
def test_from_string(c):
    '''Functional test Config from string'''
    host = 'leon'
    cmd = '{} -E="{}" {}'.format(c.loadconfig_cmd, c.conf, host)
    ret = run(cmd)
    assert 'export SYSTEM_PATH="/data/salt/system"' in ret.stdout
    assert 'export HOST="{}"'.format(host) in ret.stdout
Example #4
0
def test_run_inexistent_cmd():
    ret = run('not_script.sh')
    assert isinstance(ret, text_type)
    assert '' == ret
    assert ret.stderr.startswith('/bin/sh: not_script.sh:')
    assert 127 == ret.code
    assert 127 == ret._r['code']
Example #5
0
def test_extra_config_have_precedenced(c):
    host = 'leon'
    with tempdir() as tmpdir:
        with open('{}/config.conf'.format(tmpdir), 'w') as fh:
            fh.write(c.conf)
        cmd = '{} -C="{}" -E="system_path: /tmp/systest" {}'.format(
            c.loadconfig_cmd, tmpdir, host)
        ret = run(cmd)
    assert 'export SYSTEM_PATH="/tmp/systest"' in ret.stdout
Example #6
0
def test_extra_config_have_precedenced(c):
    host = 'leon'
    with tempdir() as tmpdir:
        with open('{}/config.conf'.format(tmpdir), 'w') as fh:
            fh.write(c.conf)
        cmd = '{} -C="{}" -E="system_path: /tmp/systest" {}'.format(
            c.loadconfig_cmd, tmpdir, host)
        ret = run(cmd)
    assert'export SYSTEM_PATH="/tmp/systest"' in ret.stdout
Example #7
0
def test_functional_verprog(f):
    '''Test version and program show properly.'''
    # argparse python 2.7 still send version option to stderr
    prog = 'demoscript.py'
    version = '0.1.5'
    cmd = 'PYTHONPATH={0} {0}/tests/fixtures/{1} -v'.format(
        f.project_path, prog)
    ret = run(cmd)
    regex = '{} {}+[ \n]*$'.format(prog, version)
    assert re.search(regex, ret.stderr)
Example #8
0
def test_from_directory(c):
    '''Functional test Config from directory (default on config.conf)'''
    host = 'leon'
    # Place conf in a temporary directory and run test
    with tempfile() as fh:
        fh.write(c.conf)
        fh.flush()
        cmd = '{} -C="{}" {}'.format(c.loadconfig_cmd, fh.name, host)
        ret = run(cmd)
    assert 'export SYSTEM_PATH="/data/salt/system"' in ret.stdout
    assert 'export HOST="{}"'.format(host) in ret.stdout
Example #9
0
def test_from_directory(c):
    '''Functional test Config from directory (default on config.conf)'''
    host = 'leon'
    # Place conf in a temporary directory and run test
    with tempfile() as fh:
        fh.write(c.conf)
        fh.flush()
        cmd = '{} -C="{}" {}'.format(c.loadconfig_cmd, fh.name, host)
        ret = run(cmd)
    assert 'export SYSTEM_PATH="/data/salt/system"' in ret.stdout
    assert 'export HOST="{}"'.format(host) in ret.stdout
Example #10
0
def test_multiple_options_are_cleaned(c):
    '''test_multiple_options_are_cleaned.

    shell equivalent:
    $ load_config.py -E="greet: hi" -E="name: Jenny"
    export GREET=hi
    export NAME=cmd
    '''
    cmd = '{} -E="greet: hi" -E="name: Jenny"'.format(c.loadconfig_cmd)
    ret = run(cmd)
    assert 'export GREET="hi"' in ret.stdout
    assert 'export NAME="Jenny"' in ret.stdout
    assert 'export STR="name: Jenny"' not in ret.stdout
    assert 'export ARGS=""' not in ret.stdout
Example #11
0
def test_multiple_options_are_cleaned(c):
    '''test_multiple_options_are_cleaned.

    shell equivalent:
    $ load_config.py -E="greet: hi" -E="name: Jenny"
    export GREET=hi
    export NAME=cmd
    '''
    cmd = '{} -E="greet: hi" -E="name: Jenny"'.format(c.loadconfig_cmd)
    ret = run(cmd)
    assert 'export GREET="hi"' in ret.stdout
    assert 'export NAME="Jenny"' in ret.stdout
    assert 'export STR="name: Jenny"' not in ret.stdout
    assert 'export ARGS=""' not in ret.stdout
Example #12
0
    def build(self):
        '''Render reStructuredText files with sphinx'''
        started = time.time()
        logger.info('Building...')

        result = run(
            'sphinx-build {rst_path} {output_path}'.format(
                rst_path=shlex_quote(self.c.sphinx_path),
                output_path=shlex_quote(
                    os.path.join(self.c.sphinx_path, self.c.output)
                )
            )
        )

        if result.stderr.strip():
            logger.warning(result.stderr.strip())

        total_seconds = time.time() - started
        logger.info('Build completed in %fs', total_seconds)

        return result
Example #13
0
def test_extra_positional_arguments(c):
    '''Test extra positional arguments are properly handled.'''
    host = 'leon'
    cmd = '{} -E="{}" {} test'.format(c.loadconfig_cmd, c.conf, host)
    ret = run(cmd)
    assert 'export ARGS="test"' in ret.stdout
Example #14
0
def test_empty_extra_argument(c):
    cmd = '{} -E=""'.format(c.loadconfig_cmd)
    ret = run(cmd)
    assert 0 == ret.code
    assert '' == ret.stderr
Example #15
0
def test_verprog(c):
    '''Test version and program show properly.'''
    # argparse python 2.7 still send version option to stderr
    cmd = '{} -E="{}" -v'.format(c.loadconfig_cmd, c.conf)
    ret = run(cmd)
    assert '{} {}\n'.format(c.prog, c.test_version) == ret.stderr
Example #16
0
def test_extra_positional_arguments(c):
    '''Test extra positional arguments are properly handled.'''
    host = 'leon'
    cmd = '{} -E="{}" {} test'.format(c.loadconfig_cmd, c.conf, host)
    ret = run(cmd)
    assert 'export ARGS="test"' in ret.stdout
Example #17
0
def test_verprog(c):
    '''Test version and program show properly.'''
    # argparse python 2.7 still send version option to stderr
    cmd = '{} -E="{}" -v'.format(c.loadconfig_cmd, c.conf)
    ret = run(cmd)
    assert '{} {}\n'.format(c.prog, c.test_version) == ret.stderr
Example #18
0
def test_options_are_cleaned(c):
    cmd = '{} -E="greet: hi"'.format(c.loadconfig_cmd)
    ret = run(cmd)
    assert 'export GREET="hi"' in ret.stdout
    assert 'export CONF=""' not in ret.stdout
Example #19
0
def test_options_are_cleaned(c):
    cmd = '{} -E="greet: hi"'.format(c.loadconfig_cmd)
    ret = run(cmd)
    assert 'export GREET="hi"' in ret.stdout
    assert 'export CONF=""' not in ret.stdout
Example #20
0
def test_empty_extra_argument(c):
    cmd = '{} -E=""'.format(c.loadconfig_cmd)
    ret = run(cmd)
    assert 0 == ret.code
    assert '' == ret.stderr