Beispiel #1
0
 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()
Beispiel #2
0
 def test_dynamic_scope(self):
     env = Environment()
     local_env1 = env.create_local_environment()
     local_env1.define("var_1", 123)
     local_env2 = env.create_local_environment(local_env1)
     self.assertIsNone(local_env2.look_up("var_1"))
     self.assertEqual(local_env2.dynamic_look_up("var_1"), 123)
Beispiel #3
0
    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)
Beispiel #4
0
    def test_evaluation_of_lifo(self):
        environment = Environment()
        queue = LIFO()

        Evaluation(environment, queue, Factory()).result

        queue = environment.look_up(Symbols.QUEUE).delegate
        self.assertIsInstance(queue, LIFOTaskPool)
Beispiel #5
0
    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)
Beispiel #6
0
    def test_evaluation_of_sequence_stops_at_the_first_failure(self):
        environment = Environment()

        succeed = MagicMock(Expression)
        succeed.accept = MagicMock(return_value=Success())

        def check_result(status):
            self.assertTrue(status.is_erroneous)

        Evaluation(environment,
                   Sequence(Fail(), succeed),
                   Factory(),
                   continuation=check_result).result
        succeed.accept.assert_not_called()
Beispiel #7
0
    def test_evaluation_of_fail(self):
        environment = Environment()

        result = Evaluation(environment, Fail(), Factory()).result

        self.assertTrue(result.is_erroneous)
Beispiel #8
0
 def test_look_up_a_missing_binding(self):
     env1 = Environment()
     env1.define("var1", 5)
     self.assertIsNone(env1.look_up("missing_symbol"))
Beispiel #9
0
 def test_define_all_reject_missing_values(self):
     env = Environment()
     with self.assertRaises(ValueError):
         env.define_each(["a", "b", "c"], [1, 2])
Beispiel #10
0
    def test_define_all_symbols(self):
        env = Environment()
        env.define_each(["a", "b", "c"], [1, 2, 3])

        self.verify_all_bindings(env, {"a": 1, "b": 2, "c": 3})