Ejemplo n.º 1
0
def test_rm(helpers, pcs_full, stored_profile_pool, capsys):
    """Test calling 'perun rm', expecting normal behaviour

    Expecting removing the profile from the index, keeping the number of files
    intact.
    """
    before_count = helpers.count_contents_on_path(pcs_full.path)

    git_repo = git.Repo(pcs_full.vcs_path)
    head = str(git_repo.head.commit)

    # We need relative path
    deleted_profile = os.path.split(stored_profile_pool[1])[-1]

    def entry_contains_profile(entry):
        """Helper function for looking up entry to be deleted"""
        return deleted_profile == entry.path

    with helpers.open_index(pcs_full.path, head) as index_handle:
        assert helpers.exists_profile_in_index_such_that(
            index_handle, entry_contains_profile)

    commands.remove([deleted_profile], None)

    with helpers.open_index(pcs_full.path, head) as index_handle:
        assert not helpers.exists_profile_in_index_such_that(
            index_handle, entry_contains_profile)

    _, err = capsys.readouterr()
    assert len(err) == 0

    # Assert that nothing was removed
    after_count = helpers.count_contents_on_path(pcs_full.path)
    assert before_count == after_count
Ejemplo n.º 2
0
def test_rm_on_empty_repo(pcs_with_empty_git, stored_profile_pool, capsys):
    """Test calling 'perun rm', when the wrapped VCS is empty"""
    with pytest.raises(SystemExit):
        commands.remove([stored_profile_pool[0]], None)

    # Test that nothing is printed on out and something is printed on err
    out, err = capsys.readouterr()
    assert out == ''
    assert err != '' and 'fatal' in err
Ejemplo n.º 3
0
def test_rm_outside_pcs(stored_profile_pool):
    """Test calling 'perun rm', when outside of the scope of the perun repository

    Expecting an exception NotPerunRepositoryExpcetion, as we are outside of the perun scope,
    and thus should not do anything, should be caught on the CLI/UI level
    """
    with pytest.raises(NotPerunRepositoryException):
        # Remove first profile from the head
        commands.remove([stored_profile_pool[0]], None)
Ejemplo n.º 4
0
def unregister_profile_of_minor_version(minor_version, profile_name):
    """Function for registering performance profile of a minor version
    :param PCS pcs: object with performance control system wrapper
    :param str profile_name: name of the performance profile
    :return: new profile path
    """
    try:
        commands.remove([profile_name], minor_version)
        return create_response('Unregistering successfull', 200)
    
    except Exception as e:
        eprint(e)
        return create_response(e, 404)
Ejemplo n.º 5
0
def test_rm_nonexistent(helpers, pcs_full, capsys):
    """Test calling 'perun rm', trying to remove nonexistent profile

    Expecting error message and nothing removed at all
    """
    before_count = helpers.count_contents_on_path(pcs_full.path)
    with pytest.raises(EntryNotFoundException):
        commands.remove(['nonexistent.perf'], None)

    out, _ = capsys.readouterr()
    assert out == ''

    # Assert that nothing was removed
    after_count = helpers.count_contents_on_path(pcs_full.path)
    assert before_count == after_count
Ejemplo n.º 6
0
def rm(profile, minor, **kwargs):
    """Unlinks the profile from the given minor version, keeping the contents
    stored in ``.perun`` directory.

    <profile> is unlinked in the following steps:

        1. <profile> is looked up in the <hash> minor version's internal index.

        2. In case <profile> is not found. An error is raised.

        3. Otherwise, the record corresponding to <hash> is erased. However,
           the original blob is kept in ``.perun/objects``.

    If no `<hash>` is specified, then current ``HEAD`` of the wrapped version
    control system is used instead. Massaging of <hash> is taken care of by
    underlying version control system (e.g. git uses ``git rev-parse``).

    <profile> can either be a ``index tag`` or a path specifying the profile.
    ``Index tags`` are in form of ``i@i``, where ``i`` stands for an index in
    the minor version's index and ``@i`` is literal suffix. Run ``perun
    status`` to see the `tags` of current ``HEAD``'s index.

    Examples of removing profiles:

    .. code-block:: bash

        $ perun rm 2@i

    This commands removes the third (we index from zero) profile in the index
    of registered profiles of current ``HEAD``.

    An error is raised if the command is executed outside of range of any
    Perun or if <profile> is not found inside the <hash> index.

    See :doc:`internals` for information how perun handles profiles internally.
    """
    try:
        commands.remove(profile, minor, **kwargs)
    except (NotPerunRepositoryException, EntryNotFoundException) as exception:
        perun_log.error(str(exception))
    finally:
        perun_log.info("removed '{}'".format(profile))
Ejemplo n.º 7
0
def test_rm_no_profiles(helpers, pcs_full, capsys):
    """Test calling 'perun rm', when there are no profiles to be removed

    Expecting error message and nothing removed at all
    """
    before_count = helpers.count_contents_on_path(pcs_full.path)

    git_repo = git.Repo(pcs_full.vcs_path)
    file = os.path.join(os.getcwd(), 'file3')
    store.touch_file(file)
    git_repo.index.add([file])
    git_repo.index.commit("new commit")

    with pytest.raises(EntryNotFoundException):
        commands.remove(['nonexistent.perf'], None)

    out, _ = capsys.readouterr()
    assert out == ''

    # Assert that nothing was removed
    after_count = helpers.count_contents_on_path(pcs_full.path)
    assert before_count == after_count