Skip to content

Commit 993407f

Browse files
committed
keep original scenario list unshuffled
1 parent f067277 commit 993407f

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

robotmbt/suiteprocessors.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def process_test_suite(self, in_suite, *, seed='new'):
8989
"\n\t".join([f"{s.src_id}: {s.name}" for s in self.scenarios]))
9090

9191
self._init_randomiser(seed)
92-
random.shuffle(self.scenarios)
92+
self.shuffled = [s.src_id for s in self.scenarios]
93+
random.shuffle(self.shuffled) # Keep a single shuffle for all TraceStates (non-essential)
9394

9495
# a short trace without the need for repeating scenarios is preferred
9596
self._try_to_reach_full_coverage(allow_duplicate_scenarios=False)
@@ -105,7 +106,7 @@ def process_test_suite(self, in_suite, *, seed='new'):
105106
return self.out_suite
106107

107108
def _try_to_reach_full_coverage(self, allow_duplicate_scenarios):
108-
self.tracestate = TraceState(range(len(self.scenarios)))
109+
self.tracestate = TraceState(self.shuffled)
109110
self.active_model = ModelSpace()
110111
while not self.tracestate.coverage_reached():
111112
i_candidate = self.tracestate.next_candidate(retry=allow_duplicate_scenarios)
@@ -142,7 +143,7 @@ def __last_candidate_changed_nothing(self):
142143
def _scenario_with_repeat_counter(self, index):
143144
"""Fetches the scenario by index and, if this scenario is already used in the trace,
144145
adds a repetition counter to its name."""
145-
candidate = self.scenarios[index]
146+
candidate = next(s for s in self.scenarios if s.src_id == index)
146147
rep_count = self.tracestate.count(index)
147148
if rep_count:
148149
candidate = candidate.copy()
@@ -214,7 +215,8 @@ def _try_to_fit_in_scenario(self, index, candidate, retry_flag):
214215
else:
215216
logger.debug(f"Scenario did not meet refinement conditions {exit_conditions}")
216217
logger.debug(f"last state:\n{self.active_model.get_status_text()}")
217-
logger.debug(f"Reconsidering {self.scenarios[i_refine].name}, scenario excluded")
218+
scenario_name = next(s.name for s in self.scenarios if s.src_id == i_refine)
219+
logger.debug(f"Reconsidering {scenario_name}, scenario excluded")
218220
self._rewind()
219221
self._report_tracestate_to_user()
220222
i_refine = self.tracestate.next_candidate(retry=retry_flag)
@@ -413,13 +415,8 @@ def _parse_modifier_expression(expression, args):
413415
raise ValueError(f"Invalid argument substitution: {expression}")
414416

415417
def _report_tracestate_to_user(self):
416-
user_trace = "["
417-
for snapshot in self.tracestate:
418-
part = f".{snapshot.id.split('.')[1]}" if '.' in snapshot.id else ""
419-
user_trace += f"{snapshot.scenario.src_id}{part}, "
420-
user_trace = user_trace[:-2] + "]" if ',' in user_trace else "[]"
421-
reject_trace = [self.scenarios[i].src_id for i in self.tracestate.tried]
422-
logger.debug(f"Trace: {user_trace} Reject: {reject_trace}")
418+
user_trace = f"[{', '.join(self.tracestate.id_trace)}]"
419+
logger.debug(f"Trace: {user_trace} Reject: {list(self.tracestate.tried)}")
423420

424421
def _report_tracestate_wrapup(self):
425422
logger.info("Trace composed:")

robotmbt/tracestate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232

3333
class TraceState:
34-
def __init__(self, scenario_indexes):
35-
if len(scenario_indexes) != len(set(scenario_indexes)):
36-
raise ValueError("Scenarios must be uniquely identifiable")
34+
def __init__(self, scenario_indexes: list[int]):
3735
self.c_pool = {index: 0 for index in scenario_indexes}
36+
if len(self.c_pool) != len(scenario_indexes):
37+
raise ValueError("Scenarios must be uniquely identifiable")
3838
self._tried = [[]] # Keeps track of the scenarios already tried at each step in the trace
3939
self._snapshots = [] # Keeps details for elements in trace
4040
self._open_refinements = []

0 commit comments

Comments
 (0)