def test_look_up_bindings_in_parent(self): env1 = Environment() env1.define("my_var", 4) env2 = env1.create_local_environment() env3 = env2.create_local_environment() self.assertEqual(env3.look_up("my_var"), 4)
def test_look_up_masked_bindings(self): env1 = Environment() env1.define("my_var", 8) env2 = env1.create_local_environment() env2.define("my_var", 7) env3 = env2.create_local_environment() env3.define("my_var", 6) self.assertEqual(env1.look_up("my_var"), 8) self.assertEqual(env2.look_up("my_var"), 7) self.assertEqual(env3.look_up("my_var"), 6)
class Simulation: """ Represent the general simulation, including the current schedule and the associated trace """ # TODO: This should inherits from SimulatedEntity as well def __init__(self, storage): self._storage = storage self._scheduler = Scheduler() self.environment = Environment() self.environment.define(Symbols.SIMULATION, self) self._next_request_id = 1 self.factory = Factory() def run_until(self, end, display=None): self._scheduler.simulate_until(end, display) @property def log(self): return self._storage.log @property def schedule(self): return self._scheduler def evaluate(self, expression, continuation=lambda x: x): return Evaluation(self.environment, expression, self.factory, continuation).result def next_request_id(self): id = self._next_request_id self._next_request_id += 1 return id @property def services(self): return self._find_by_type(Service) @property def clients(self): return self._find_by_type(ClientStub) def _find_by_type(self, type): return [ each_value for each_value in list(self.environment.bindings.values()) if isinstance(each_value, type) ]
class Simulation: """ Represent the general simulation, including the current schedule and the associated trace """ # TODO: This should inherits from SimulatedEntity as well def __init__(self, storage): self._storage = storage self._scheduler = Scheduler() self.environment = Environment() self.environment.define(Symbols.SIMULATION, self) self._next_request_id = 1 self.factory = Factory() def run_until(self, end, display=None): self._scheduler.simulate_until(end, display) @property def log(self): return self._storage.log @property def schedule(self): return self._scheduler def evaluate(self, expression, continuation=lambda x: x): return Evaluation(self.environment, expression, self.factory, continuation).result def next_request_id(self): id = self._next_request_id self._next_request_id += 1 return id @property def services(self): return self._find_by_type(Service) @property def clients(self): return self._find_by_type(ClientStub) def _find_by_type(self, type): return [each_value for each_value in self.environment.bindings.values() if isinstance(each_value, type)]
def test_look_up_a_missing_binding(self): env1 = Environment() env1.define("var1", 5) self.assertIsNone(env1.look_up("missing_symbol"))