예제 #1
0
파일: cli.py 프로젝트: petr-muller/perun
def config(**kwargs):
    """Manages local and shared configuration.

    In perun there exists two external configurations:

        1. ``local.yml``: the local configuration stored in ``.perun``
           directory, containing  the keys such as specification of wrapped
           repository or job matrix used for quick generation of profiles (run
           ``perun run matrix --help`` or refer to :doc:`jobs` for information
           how to construct the job matrix).

        2. ``shared.yml`` - the global configuration shared by all Perun
           instances, containing shared keys, such as text editor, formatting
           string, etc.

    The syntax of the ``<key>`` consists of section separated by dots, e.g.
    ``vcs.type`` specifies ``type`` key in ``vcs`` section. There exists three
    modes of lookup, ``--local``, ``--shared`` and ``nearest``, which locates
    or sets the <key> in local, shared or nearest configuration (e.g. when one
    is trying to get some key, there may be nested perun instances that do not
    contain the given key). By default, perun locates the nearest config.

    When neither of ``--get``, ``--set`` or ``--edit`` is set, an error is
    raised. Otherwise the latest action is used.

    Refer to :doc:`config` for full description of configurations and
    :ref:`config-types` for full list of configuration options.

    E.g. using the following can retrieve the type of the nearest perun
    wrapper:

    .. code-block:: bash

        $ perun config --get vsc.type
        vcs.type: git
    """
    try:
        commands.config(**kwargs)
    except (MissingConfigSectionException,
            InvalidConfigOperationException) as mcs_err:
        perun_log.error(str(mcs_err))
예제 #2
0
def test_edit(pcs_full, capsys):
    """Test 'editing' the configuration file

    Expecting no errors or exceptions
    """
    # First try to get the exception by calling bogus editor
    commands.config('local', 'set', 'global.editor', 'bogus')
    with pytest.raises(ExternalEditorErrorException):
        commands.config('local', 'edit')
    capsys.readouterr()

    # Use cat as a valid editor
    commands.config('local', 'set', 'global.editor', 'cat')
    commands.config('local', 'edit')
    capsys.readouterr()
    _, err = capsys.readouterr()
    assert err == ''
예제 #3
0
def test_get_exists(pcs_full, capsys):
    """Test calling 'perun --get KEY', such that the key exists"""
    # Get valid thing from local
    commands.config('local', 'get', 'vcs.type')
    out, err = capsys.readouterr()
    assert 'git' in out
    assert err == ''

    # Get valid thing from global
    commands.config('shared', 'get', 'global.editor')
    out_global, err = capsys.readouterr()
    assert 'global.editor: ' in out_global
    assert err == ''

    # First verify there is nothing in local
    with pytest.raises(MissingConfigSectionException):
        commands.config('local', 'get', 'global.editor')
        out, err = capsys.readouterr()
        assert out == err
        assert 'fatal' in err

    # Now try to recursively obtain the same thing
    commands.config('recursive', 'get', 'global.editor')
    out, err = capsys.readouterr()
    assert out == out_global
    assert err == ''

    # Try to recursively obtain nonexistant
    with pytest.raises(MissingConfigSectionException):
        commands.config('recursive', 'get', 'super.editor')

    # Try get without key
    with pytest.raises(InvalidConfigOperationException):
        commands.config('shared', 'set')
예제 #4
0
def test_set_exists(pcs_full, capsys):
    """Test calling 'perun --set KEY', such that the key was in config and is reset"""
    # Set valid thing in local
    commands.config('local', 'set', 'bogus.key', 'true')
    capsys.readouterr()
    commands.config('local', 'get', 'bogus.key')
    out, err = capsys.readouterr()
    assert 'bogus.key' in out and 'true' in out
    assert err == ''

    # Set valid thing in global
    random_value = str(random.randint(0, 10**6))
    commands.config('shared', 'set', 'testkey', random_value)
    capsys.readouterr()
    commands.config('shared', 'get', 'testkey')
    out, err = capsys.readouterr()
    assert 'testkey' in out and random_value in out
    assert err == ''

    # Set valid thing in nearest
    with pytest.raises(MissingConfigSectionException):
        commands.config('local', 'get', 'test2key')
    commands.config('recursive', 'set', 'test2key', 'testvalue')
    capsys.readouterr()
    commands.config('recursive', 'get', 'test2key')
    out, err = capsys.readouterr()
    assert 'test2key' in out and 'testvalue' in out
    assert err == ''

    # Try set without key
    with pytest.raises(InvalidConfigOperationException):
        commands.config('shared', 'set', 'key')
예제 #5
0
def test_get_outside_of_pcs():
    """Test calling 'perun --get KEY' outside of the scope of the PCS"""
    with pytest.raises(NotPerunRepositoryException):
        commands.config('local', 'edit')