diff --git a/depend_test_framework/case_generator.py b/depend_test_framework/case_generator.py index 8f97ec6..94e120b 100644 --- a/depend_test_framework/case_generator.py +++ b/depend_test_framework/case_generator.py @@ -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: @@ -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): diff --git a/depend_test_framework/env.py b/depend_test_framework/env.py index 19f8eea..d39515c 100644 --- a/depend_test_framework/env.py +++ b/depend_test_framework/env.py @@ -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 @@ -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: @@ -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)