Skip to content

Commit

Permalink
Merge pull request #32 from tsbxmw/dev-2.1.0
Browse files Browse the repository at this point in the history
release 2.0.3
  • Loading branch information
tsbxmw authored Dec 5, 2018
2 parents 04ea89d + eca1516 commit c236b30
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 41 deletions.
5 changes: 5 additions & 0 deletions docs/releasenote.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
> version 2.0.3
- complete @ support
- support @test @skip @parametrize

> version 2.0.0
- all new
Expand Down
3 changes: 3 additions & 0 deletions haf/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, module_name, module_path):
self.suite = ""
self.func = ""
self._init_all()
self.run = self.func
self.param = None

def _init_all(self):
self.ids = Ids()
Expand Down Expand Up @@ -65,6 +67,7 @@ def constructor(self, *args, **kwargs):
self.run = CASE_RUN if args_init.get("run") is True else CASE_SKIP
self.func = args_init.get("func")
self.suite = args_init.get("suite")
self.param = args_init.get("param")

def bind_bench(self, bench_name):
self.bench_name = bench_name
Expand Down
6 changes: 3 additions & 3 deletions haf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@

MAIN_VERSION = 2
SUB_VERSION = 0
FIX_VERSION = 2
FIX_VERSION = 3
VERSION_TYPE = "dev"
PLATFORM_VERSION = f"{VERSION_TYPE}-{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION}"

BANNER_STRS ="""
BANNER_STRS =f"""
***************************************
* H H A FFFFFFFF *
* H H A A F *
* H H A A F *
* HHHHHHHH AAAAAAA FFFFFFFF *
* H H A A F *
* H H A A F *
* H HA AF v2.0.2 *
* H HA AF v{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION} *
***************************************
"""
34 changes: 20 additions & 14 deletions haf/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@


class TestDecorator:
def __init__(self, func):
self.func = func
self.run = True
self.reason = ""
self.param = ""
def __init__(self, name):
self.name = name
self.mark = "test"

def __call__(self, param):
self.param = param
if len(self.param) > 0:
return self.func(self, self.param)
else:
return self.func(self)
def __call__(self, *args, **kwargs):
if len(args) == 1 and len(kwargs) == 0:
if inspect.isfunction(args[0]):
setattr(args[0], "test_decorator", self.__class__(self.name))
setattr(args[0], "mark", self.mark)
setattr(args[0], "run", True)
return args[0]


test = TestDecorator
Expand All @@ -26,20 +25,27 @@ class SkipDecorator:
def __init__(self, test_item: test=None):
self.test_item = test_item
self.test_item.run = False
self.mark = "test"

def __call__(self):
setattr(self.test_item, "mark", self.mark)
return self.test_item


skip = SkipDecorator


class ParametersDecorator:
class ParameterizeDecorator:
def __init__(self, params: list=[]):
self.params = params
self.mark = "test"

def __call__(self, *args, **kwargs):
return self.params
func = args[0]
setattr(func, "mark", self.mark)
setattr(func, "params", self.params)
setattr(func, "run", True)
return func


parameters = ParametersDecorator
parameterize = ParameterizeDecorator
8 changes: 4 additions & 4 deletions haf/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ def run(self, case:PyCase):
module_path = case.module_path
sys.path.append(module_path)
module = importlib.import_module(module_name)
func = getattr(getattr(module, case.suite), case.func)
if hasattr(func, "param"):
func(param=func.param)
func = getattr(getattr(module, case.suite)(), case.func)
if case.param is not None:
func(case.param)
else:
func(key=True)
func()
result.result = RESULT_PASS
except AssertionError as ae:
traceback.print_exc()
Expand Down
22 changes: 16 additions & 6 deletions haf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import platform
import yaml

from haf.mark import test, skip, parameters, TestDecorator
from haf.mark import test, skip, parameterize, TestDecorator

logger = Log.getLogger(__name__)

Expand Down Expand Up @@ -238,6 +238,10 @@ def get_case_from_class(class_list):
elif isinstance(func, skip):
func_temp[func_key] = func
suite_dict[class_temp_key].append(func_temp)
elif inspect.isfunction(func):
if hasattr(func, "mark") and func.mark == "test":
func_temp[func_key] = func
suite_dict[class_temp_key].append(func_temp)

case_dict[cl].append(suite_dict)
return case_dict
Expand All @@ -257,13 +261,19 @@ def load_dict_to_case(case_dict):
for case in suite_temp:
for key in case.keys():
case_temp = {"id": id, "subid": subid, "name": key, "run": case.get(key).run if hasattr(case.get(key), 'run') else False, "reason": case.get(key).reason if hasattr(case.get(key), 'reason') else None}
subid += 1
case_temp["func"] = key
case_temp["suite"] = suite_key
if isinstance(case.get(key), test):
case_temp["param"] = case.get(key).param
cases.append(case_temp)
print(cases)
func = case.get(key)
if hasattr(func, "params"):
for param in func.params:
case_temp_1 = case_temp.copy()
case_temp_1["subid"] = subid
case_temp_1["param"] = param
cases.append(case_temp_1)
subid += 1
else:
subid += 1
cases.append(case_temp)
return cases


Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import setuptools, os
from setuptools import setup
from haf.config import *

PACKAGE_NAME = "haf"

Expand Down Expand Up @@ -43,7 +44,7 @@ def package_files(directory):

setup(
name = 'haf',
version = '2.0.2',
version = f"{MAIN_VERSION}.{SUB_VERSION}.{FIX_VERSION}",
author = 'wei.meng',
author_email = 'mengwei1101@hotmail.com',
long_description = long_description,
Expand Down
29 changes: 16 additions & 13 deletions testcases/test4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@
import sys

sys.path.append("..")
from haf.mark import test, skip, parameters
from haf.mark import test, skip, parameterize
from haf.case import BaseCase
import inspect


class TestHello(BaseCase):
@test
def Hello(self):

@test("test hello11")
def test_1(self):
assert 1+1 == 2
assert 1 == 5

@skip
@test
def Hello1(self):
@test("test hello12")
def test_2(self):
assert 1 + 1 == 2

@test
@parameters([{"test":123},{"test":245}])
def Hello2(self, params):
@parameterize([{"test":123},{"test":245}])
def test_3(self, params):
print(params)
assert 1 + 1 == 2

@parameterize([{"test":123},{"test":245}])
def test_4(self, params):
assert params.get("test")==123


class TestHello2(BaseCase):
@test
def Hello(self):
@test("test hello2")
def test1(self):
assert 1+1 == 2

@test
def Hello1123(self):
@test("test hello21")
def test2(self):
assert 1 + 1 == 2


Expand Down

0 comments on commit c236b30

Please sign in to comment.