Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions taf/plugins/pytest_tempest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

import sys
import os
from itertools import chain
import argparse

from itertools import chain

_PLUGIN_NAME = "_tempest"

Expand All @@ -36,6 +37,18 @@ def prepend_path(path):
# need to add plugins.pytest_tempest to conftest.py in tempest test directory


class ReuseVenvAction(argparse.Action):
"""
"""
CHOICES = {
'true': True,
'false': False,
}

def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, self.CHOICES[values])


def pytest_addoption(parser):
"""Tempest specific options.

Expand All @@ -48,11 +61,12 @@ def pytest_addoption(parser):
},
'--reuse_venv': {
'action': 'store',
'default': 'True',
'choices': ['True', 'False'],
'default': 'true',
'action': ReuseVenvAction,
'help': "Reuse(=True) or Delete(=False) existing public networks/routers\
, '%default' by default.",
},
'choices': ReuseVenvAction.CHOICES,
}
}

for opt, opt_kwargs in options.items():
Expand Down
Empty file added taf/testlib/common/__init__.py
Empty file.
133 changes: 133 additions & 0 deletions taf/testlib/common/logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""
@copyright Copyright (c) 2017, Intel Corporation.

This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU Lesser General Public License,
version 2.1, as published by the Free Software Foundation.

This program is distributed in the hope it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.

@file logic.py

@summary combinational, resolution, functional, predicate and other logics helpers.
"""

import itertools
import functools


__0__ = object()


class Functional(object):
"""
"""
@classmethod
def fixed(cls, value):
def wrapper(arg):
return value
return wrapper

@classmethod
def mapped(cls, mapper):
def wrapper(arg):
return mapper(arg)
return wrapper

@classmethod
def f2i(sentinel=object()):
"""
function to iter decorator
"""
def decorator(f):
return iter(f, sentinel)
return decorator

@classmethod
def fwrap(cls, wraps=__0__, returns=__0__, args=__0__, kwargs=__0__):
"""
function wrapper
"""
def decorator(f):
"""
TODO Propagate the signature as originally declared for `f`?
inspect.signature(f) ... ???
"""
@functools.wraps(f if wraps is __0__ else wraps)
def wrapper(*f_args, **f_kwargs):
if args is not __0__:
f_args = args(*f_args)
if kwargs is not __0__:
f_kwargs = kwargs(**f_kwargs)

ret = f(*f_args, **f_kwargs)

if returns is __0__:
return ret
return returns(ret)

return wrapper
return decorator

@classmethod
def ifwrap(cls, sentinel=__0__):
"""
iterator [function] wrapper
Just like the builtin `iter`, only with a customizable sentinel predicate
"""
if sentinel is __0__:
def wrapper(obj):
return iter(obj)
return wrapper

predicate = Predicate.pwrap_bool_false(sentinel)

def wrapper(obj):
return itertools.takewhile(predicate, Functional.f2i()(obj))
return wrapper


class Predicate(object):
"""
"""
DEFAULT_PREDICATE = bool

@classmethod
def pwrap(cls, wraps=__0__, predicate=__0__, on_true=__0__, on_false=__0__):
"""
predicate wrapper
"""
if predicate is __0__:
predicate = cls.DEFAULT_PREDICATE

def mapper(mappee):
ret = on_false
if predicate(mappee):
ret = on_true
if ret is __0__:
return mappee
return ret

return Functional.fwrap(wraps=wraps, returns=Functional.mapped(mapper))

__PWRAP_IMPL_MAP__ = {}

@classmethod
def class_init(cls):
cls.pwrap_bool_true = cls.pwrap(on_true=True, on_false=False)
cls.pwrap_bool_false = cls.pwrap(on_true=False, on_false=True)
cls.pwrap_object_true = cls.pwrap(on_false=None)
cls.pwrap_object_false = cls.pwrap(on_true=None)

cls.__PWRAP_IMPL_MAP__.update(
{
bool: [cls.pwrap_bool_false, cls.pwrap_bool_true],
object: [cls.pwrap_object_false, cls.pwrap_object_true],
}
)


Predicate.class_init()
Loading