示例#1
0
 def test_add_variant_at_instantiation(self):
     mock_backend = asp_module.ASPBackend(Mock(), None, Mock())
     a = asp_module.SpecializedFunction("foo", mock_backend, Mock(),
                                        ["foo_1"],
                                        ["void foo_1(){return;}"])
     self.assertEqual(len(a.variant_funcs), 1)
     self.assertTrue(mock_backend.module.add_to_module.called)
示例#2
0
    def test_add_variant(self):
        mock_backend = asp_module.ASPBackend(Mock(), None, Mock())
        a = asp_module.SpecializedFunction("foo", mock_backend, Mock())
        a.add_variant("foo_1", "void foo_1(){return;}")
        self.assertEqual(a.variant_names[0], "foo_1")
        self.assertEqual(len(a.variant_funcs), 1)

        # also check to make sure the backend added the function
        self.assertTrue(mock_backend.module.add_to_module.called)

        self.assertRaises(Exception, a.add_variant, "foo_1", None)
示例#3
0
    def test_call(self):
        # this is a complicated situation.  we want the backend to have a fake
        # module, and that fake module should return a fake compiled module.
        # we'll cheat by just returning itself.
        mock_backend_module = Mock()
        mock_backend_module.compile.return_value = mock_backend_module
        mock_backend = asp_module.ASPBackend(mock_backend_module, None, Mock())
        a = asp_module.HelperFunction("foo", "void foo(){}", mock_backend)
        # test a call
        a()

        # it should call foo() on the backend module
        self.assertTrue(mock_backend_module.foo.called)
示例#4
0
    def test_call(self):
        # this is a complicated situation.  we want the backend to have a fake
        # module, and that fake module should return a fake compiled module.
        # we'll cheat by just returning itself.
        mock_backend_module = Mock()
        mock_backend_module.compile.return_value = mock_backend_module
        mock_backend = asp_module.ASPBackend(mock_backend_module, None, Mock())
        mock_db = Mock()
        mock_db.get.return_value = []
        a = asp_module.SpecializedFunction("foo", mock_backend, mock_db)
        a.add_variant("foo_1", "void foo_1(){return;}")
        # test a call
        a()

        # it should call foo() on the backend module
        self.assertTrue(mock_backend_module.foo_1.called)
示例#5
0
    def test_calling_with_multiple_variants(self):
        # this is a complicated situation.  we want the backend to have a fake
        # module, and that fake module should return a fake compiled module.
        # we'll cheat by just returning itself.
        mock_backend_module = Mock()
        mock_backend_module.compile.return_value = mock_backend_module
        mock_backend = asp_module.ASPBackend(mock_backend_module, None, Mock())
        mock_db = Mock()
        mock_db.get.return_value = []

        a = asp_module.SpecializedFunction("foo", mock_backend, mock_db)
        a.add_variant("foo_1", "void foo_1(){return;}")
        a.add_variant("foo_2", "void foo_2(){}")

        # test 2 calls
        a()
        # ensure the second one sees that foo_1 was called the first time
        mock_db.get.return_value = [["foo", "foo_1", None, None]]
        a()

        # it should call both variants on the backend module
        self.assertTrue(mock_backend_module.foo_1.called)
        self.assertTrue(mock_backend_module.foo_2.called)