Skip to content

Commit

Permalink
Add support for 'or' operation in consumer
Browse files Browse the repository at this point in the history
Use '|' to mark paths with or relation

Signed-off-by: Luyao Huang <[email protected]>
  • Loading branch information
LuyaoHuang committed Aug 16, 2019
1 parent 7ad22a8 commit 028f62a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
22 changes: 13 additions & 9 deletions depend_test_framework/case_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ def __init__(self, suit_env_limit=20, allow_dep=8, use_map=True):
self._v_graph = None

def find_suit_envs(self, env):
env_list = env if type(env) is list else [env]
if not self.dep_graph:
raise Exception('Need gen depend graph first')
tmp_list = []
for key_env in self.dep_graph.keys():
if env <= key_env:
tmp_list.append(key_env)

for i, tgt_env in enumerate(sorted(tmp_list, key=len)):
if i <= self._suit_env_limit:
yield tgt_env
env_record = []
for tmp_env in env_list:
tmp_list = []
for key_env in self.dep_graph.keys():
if tmp_env <= key_env:
tmp_list.append(key_env)

for i, tgt_env in enumerate(sorted(tmp_list, key=len)):
if i <= self._suit_env_limit and tgt_env not in env_record:
env_record.append(tgt_env)
yield tgt_env

def compute_route_permutations(self, src_env, target_env, cleanup=False):
if not self.dep_graph:
Expand All @@ -69,7 +73,7 @@ def compute_route_permutations(self, src_env, target_env, cleanup=False):
def gen_cases(self, test_func, random_cleanup=False, need_cleanup=False, src_env=None):
if not src_env:
src_env = Env()
target_env = Env.gen_require_env(test_func)
target_env = list(Env.gen_require_env(test_func))
for tgt_env in self.find_suit_envs(target_env):
cases = self.compute_route_permutations(src_env, tgt_env)
if not tgt_env.gen_transfer_env(test_func):
Expand Down
23 changes: 19 additions & 4 deletions depend_test_framework/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import contextlib
import copy
import itertools

from .log import get_logger
from .dependency import Consumer, Provider, Cut, Graft, get_all_depend
Expand Down Expand Up @@ -105,7 +106,16 @@ def hit_require(self, depend):
else:
raise NotImplementedError

ret = self._get_data_from_path(depend.env_depend)
# TODO: support more kind of operation
paths = depend.env_depend.split('|')
for path in paths:
if self._valid_single_require(path, require):
return True

return False

def _valid_single_require(self, path, require):
ret = self._get_data_from_path(path)
if ret is not None and (ret.struct_table() != '{}' or ret.data):
return require
else:
Expand Down Expand Up @@ -140,11 +150,16 @@ def gen_require_env(cls, func):
return required env
"""
cons = get_all_depend(func, depend_cls=Consumer)
env = cls()
env_paths = []
for con in cons:
if con.type == Consumer.REQUIRE:
env._set_data_from_path(con.env_depend, True)
return env
env_paths.append(con.env_depend.split('|'))
all_paths = itertools.product(*env_paths)
for paths in all_paths:
env = cls()
for path in paths:
env._set_data_from_path(path, True)
yield env

def __reduce__(self):
return self.__reduce_ex__(None)
Expand Down

0 comments on commit 028f62a

Please sign in to comment.