Commit 2b25ea13 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[core] Added decorators for skipping tests when asset does not support certain features

Implemented for:
- no versions support
- no fork support
parent 7f2e6208
Pipeline #34645 failed with stage
in 3 minutes and 5 seconds
......@@ -42,7 +42,9 @@ import os
import nose.tools
import click
import shutil
from collections import namedtuple
from functools import wraps
from click.testing import CliRunner
......@@ -69,13 +71,51 @@ else:
pass
# ----------------------------------------------------------
# decorators
# Make skip on disconnected a decorator, this will make tests easier to read and write
skip_disconnected = skipif(disconnected, "missing test platform (%s)" % platform)
def skip_no_version(method):
"""Skip test is asset does not support versioning"""
@wraps(method)
def _impl(self, *args, **kwargs):
with common.Selector(tmp_prefix) as selector:
if not selector.has_versions(self.asset_type):
raise nose.SkipTest(
"{} does not support versions".format(self.asset_type)
)
return method(self, *args, **kwargs)
return _impl
def skip_no_fork(method):
"""Skip test if asset does not support forking"""
@wraps(method)
def _impl(self, *args, **kwargs):
with common.Selector(tmp_prefix) as selector:
if not selector.can_fork(self.asset_type):
raise nose.SkipTest("{} does not support forks".format(self.asset_type))
return method(self, *args, **kwargs)
return _impl
# ----------------------------------------------------------
# helper
# Used for making direct calls
MockConfig = namedtuple("MockConfig", ["platform", "user", "token"])
# ----------------------------------------------------------
class BaseTest:
asset_type = None
......@@ -135,6 +175,9 @@ class BaseTest:
return result.exit_code, result.output
# ----------------------------------------------------------
class AssetBaseTest(BaseTest):
"""Base class that ensures that the asset_type is set before calling click"""
......@@ -186,6 +229,7 @@ class AssetLocalTest(AssetBaseTest):
def test_create(self, obj=None):
self.create(self.object_map["create"])
@skip_no_version
def test_new_version(self):
obj = self.object_map["create"]
obj2 = self.object_map["new"]
......@@ -230,6 +274,9 @@ class AssetLocalTest(AssetBaseTest):
nose.tools.assert_false(storage.exists())
# ----------------------------------------------------------
class AssetRemoteTest(AssetBaseTest):
"""Base class for remote tests"""
......@@ -295,13 +342,8 @@ class AssetRemoteTest(AssetBaseTest):
@slow
@skip_disconnected
@skip_no_version
def test_push_different_versions(self):
with common.Selector(tmp_prefix) as selector:
if not selector.has_versions(self.asset_type):
raise nose.SkipTest(
"{} does not support versions".format(self.asset_type)
)
asset_name = self.object_map["create"]
self.create(asset_name)
......@@ -331,11 +373,8 @@ class AssetRemoteTest(AssetBaseTest):
@slow
@skip_disconnected
@skip_no_fork
def test_push_different_forks(self):
with common.Selector(tmp_prefix) as selector:
if not selector.can_fork(self.asset_type):
raise nose.SkipTest("{} does not support fork".format(self.asset_type))
asset_name = self.object_map["fork"]
if "fork_from" in self.object_map:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment