def test_deserialize_trail_mismatched_trail(self): # Make another DAG: # +--> step_d -->+ # step_a -->| |--> step_b # +--> step_c -->+ def action_a(): pass def action_b(): pass def action_c(): pass def action_d(): pass step_a = Step(action_a) step_b = Step(action_b) step_c = Step(action_c) step_d = Step(action_d) trail_definition = [ (step_a, step_d), (step_a, step_c), (step_d, step_b), (step_c, step_b), ] mismatching_trail_data = serialize_trail(make_dag(trail_definition)) with self.assertRaises(MatchTrailsException): deserialize_trail(self.root_step, mismatching_trail_data, {})
def __init__(self, trail_definition, socket_file=None, dag_file=None, context=None, delay=1, timeout=0.0001, backlog_count=1): self.context = context self.root_step = make_dag(trail_definition) self.socket_file = socket_file self.started = False self.timeout = timeout self.backlog_count = backlog_count self.trail_process = None # Will point to the trail process only in threaded mode. self.delay = delay if not dag_file: self.dag_file = mktemp(prefix='autotrail.') else: self.dag_file = dag_file if not socket_file: self.socket_file = mktemp(prefix='autotrail.socket.') else: self.socket_file = socket_file self.api_socket = socket_server_setup(self.socket_file, backlog_count=backlog_count, timeout=timeout)
def test_assign_sequence_numbers_to_steps(self): # Make this DAG: # +--> step_b -->+ # step_a -->| |--> step_d # +--> step_c -->+ step_a = Step(lambda x: x) step_b = Step(lambda x: x) step_c = Step(lambda x: x) step_d = Step(lambda x: x) trail_definition = [ (step_a, step_b), (step_a, step_c), (step_b, step_d), (step_c, step_d), ] root_step = make_dag(trail_definition) assign_sequence_numbers_to_steps(root_step) get_number = lambda x: x.tags['n'] self.assertEqual(get_number(step_a), 0) self.assertEqual(get_number(step_d), 3) self.assertGreater(get_number(step_d), get_number(step_b)) self.assertGreater(get_number(step_d), get_number(step_c)) self.assertLess(get_number(step_a), get_number(step_b)) self.assertLess(get_number(step_a), get_number(step_c)) self.assertNotEqual(get_number(step_b), get_number(step_c))
def test_make_dag_cyclic(self): # Make this cyclic DAG: # step_a --> step_b -->+ # ^ | # | v # +<----- step_c <--+ step_a = Step(lambda x: x) step_b = Step(lambda x: x) step_c = Step(lambda x: x) trail_definition = [ (step_a, step_b), (step_b, step_c), (step_c, step_a), ] with self.assertRaises(CyclicException): root_step = make_dag(trail_definition)
def test_serialize_trail(self): # Make this DAG: # +--> step_b -->+ # step_a -->| |--> step_d # +--> step_c -->+ def action_a(): pass def action_b(): pass def action_c(): pass def action_d(): pass step_a = Step(action_a) step_b = Step(action_b) step_c = Step(action_c) step_d = Step(action_d) trail_definition = [ (step_a, step_b), (step_a, step_c), (step_b, step_d), (step_c, step_d), ] root_step = make_dag(trail_definition) trail_data = serialize_trail(root_step) for step in [step_a, step_b, step_c, step_d]: self.assertIn(str(step), trail_data) self.assertEqual(trail_data[str(step)][StatusField.STATE], str(step.state)) self.assertEqual(trail_data[str(step)][StatusField.RETURN_VALUE], str(step.return_value)) for parent in step.parents: self.assertIn(str(parent), trail_data[str(step)]['parents'])
def test_make_dag(self): # Make this DAG: # +--> step_b -->+ # step_a -->| |--> step_d # +--> step_c -->+ step_a = Step(lambda x: x) step_b = Step(lambda x: x) step_c = Step(lambda x: x) step_d = Step(lambda x: x) trail_definition = [ (step_a, step_b), (step_a, step_c), (step_b, step_d), (step_c, step_d), ] root_step = make_dag(trail_definition) self.assertEqual(root_step, step_a) self.assertEqual(step_a.tags['n'], 0) self.assertEqual(step_d.tags['n'], 3)
def setUp(self): # Make this DAG: # +--> step_b -->+ # step_a -->| |--> step_d # +--> step_c -->+ def action_a(): pass def action_b(): pass def action_c(): pass def action_d(): pass self.step_a = Step(action_a) self.step_b = Step(action_b) self.step_c = Step(action_c) self.step_d = Step(action_d) trail_definition = [ (self.step_a, self.step_b), (self.step_a, self.step_c), (self.step_b, self.step_d), (self.step_c, self.step_d), ] self.root_step = make_dag(trail_definition) self.step_a.return_value = 'mock return value' self.step_a.prompt_messages = ['mock prompt_messages'] self.step_a.output_messages = ['mock output_messages'] self.step_a.input_messages = ['mock input_messages'] self.trail_data = serialize_trail(self.root_step)