From 95092b511dbacac412dbe5b8ff3a28abb3d3f664 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Fri, 10 Aug 2018 12:55:10 +0200 Subject: Leverage on abc and stevedore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7b3c4c0c5dd0c9e6fb3e52c3fff5221d4b831b02 Signed-off-by: Cédric Ollivier --- xtesting/core/feature.py | 9 ++++----- xtesting/core/testcase.py | 13 ++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'xtesting/core') diff --git a/xtesting/core/feature.py b/xtesting/core/feature.py index 932e0230..86215515 100644 --- a/xtesting/core/feature.py +++ b/xtesting/core/feature.py @@ -13,21 +13,25 @@ Feature is considered as TestCase offered by Third-party. It offers helpers to run any python method or any bash command. """ +import abc import logging import subprocess import time +import six from xtesting.core import testcase __author__ = ("Serena Feng , " "Cedric Ollivier ") +@six.add_metaclass(abc.ABCMeta) class Feature(testcase.TestCase): """Base model for single feature.""" __logger = logging.getLogger(__name__) + @abc.abstractmethod def execute(self, **kwargs): """Execute the Python method. @@ -39,12 +43,7 @@ class Feature(testcase.TestCase): Args: kwargs: Arbitrary keyword arguments. - - Returns: - -1. """ - # pylint: disable=unused-argument,no-self-use - return -1 def run(self, **kwargs): """Run the feature. diff --git a/xtesting/core/testcase.py b/xtesting/core/testcase.py index 61a2e8c8..c3a1c38c 100644 --- a/xtesting/core/testcase.py +++ b/xtesting/core/testcase.py @@ -9,6 +9,7 @@ """Define the parent class of all Xtesting TestCases.""" +import abc from datetime import datetime import json import logging @@ -17,6 +18,7 @@ import re import requests import prettytable +import six from xtesting.utils import decorators from xtesting.utils import env @@ -24,7 +26,9 @@ from xtesting.utils import env __author__ = "Cedric Ollivier " -class TestCase(object): # pylint: disable=too-many-instance-attributes +@six.add_metaclass(abc.ABCMeta) +class TestCase(object): + # pylint: disable=too-many-instance-attributes """Base model for single test case.""" EX_OK = os.EX_OK @@ -138,6 +142,7 @@ class TestCase(object): # pylint: disable=too-many-instance-attributes """ self.is_skipped = False + @abc.abstractmethod def run(self, **kwargs): """Run the test case. @@ -156,13 +161,7 @@ class TestCase(object): # pylint: disable=too-many-instance-attributes Args: kwargs: Arbitrary keyword arguments. - - Returns: - TestCase.EX_RUN_ERROR. """ - # pylint: disable=unused-argument - self.__logger.error("Run must be implemented") - return TestCase.EX_RUN_ERROR @decorators.can_dump_request_to_file def push_to_db(self): -- cgit 1.2.3-korg