Skip to content

Commit

Permalink
fix: added test utility functions and cleanup (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsam authored and Panaetius committed Feb 18, 2020
1 parent 8326e37 commit 7a81ca6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 44 deletions.
28 changes: 1 addition & 27 deletions tests/core/commands/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Dataset tests."""

import os
import shutil
import stat
from contextlib import contextmanager

import pytest
from git import Repo
from tests.utils import raises

from renku.core import errors
from renku.core.commands.dataset import create_dataset
from renku.core.models.datasets import Dataset, DatasetFile
from renku.core.models.provenance.agents import Person


def _key(client, dataset, filename):
"""Return key in dataset for a given filename."""
dataset_path = client.renku_datasets_path / dataset.name
return os.path.relpath(
str(client.path / client.datadir / dataset.name / filename),
start=str(dataset_path),
)


def raises(error):
"""Wrapper around pytest.raises to support None."""
if error:
return pytest.raises(error)
else:

@contextmanager
def not_raises():
try:
yield
except Exception as e:
raise e

return not_raises()


@pytest.mark.parametrize(
'scheme, path, force, error',
[('', 'temp', False, None), ('file://', 'temp', True, None),
Expand Down
18 changes: 1 addition & 17 deletions tests/core/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"""Project initialization tests."""

import shutil
from contextlib import contextmanager
from pathlib import Path
from tempfile import TemporaryDirectory

import pkg_resources
import pytest
from tests.utils import raises

from renku.core import errors
from renku.core.commands.init import TEMPLATE_MANIFEST, create_from_template, \
Expand All @@ -41,22 +41,6 @@
template_local = Path(pkg_resources.resource_filename('renku', 'templates'))


def raises(error):
"""Wrapper around pytest.raises to support None."""
if error:
return pytest.raises(error)
else:

@contextmanager
def not_raises():
try:
yield
except Exception as e:
raise e

return not_raises()


@pytest.mark.parametrize(
'url, ref, result, error', [(TEMPLATE_URL, TEMPLATE_REF, True, None),
(FAKE, TEMPLATE_REF, None, errors.GitError),
Expand Down
37 changes: 37 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020 - Swiss Data Science Center (SDSC)
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
# Eidgenössische Technische Hochschule Zürich (ETHZ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test utility functions."""
from contextlib import contextmanager

import pytest


def raises(error):
"""Wrapper around pytest.raises to support None."""
if error:
return pytest.raises(error)
else:

@contextmanager
def not_raises():
try:
yield
except Exception as e:
raise e

return not_raises()

0 comments on commit 7a81ca6

Please sign in to comment.