OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace / tests / cython / atomspace / test_callback_arity.py

50 lines · python ref:
import unittest

from opencog.atomspace import *

import __main__


def return_concept(atom):
    return atom.atomspace.add_node(types.ConceptNode, "test")


__main__.return_concept = return_concept


class TestExecutionOutputLink(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_correct_argcount(self):
        atom1 = ConceptNode("atom1")
        exec_link = ExecutionOutputLink(GroundedSchemaNode("py:return_concept"),
                                        ListLink(atom1))
        result = exec_link.execute()
        self.assertTrue(result.name == "test")

    def test_too_many_args(self):
        atom1 = ConceptNode("atom1")
        exec_link = ExecutionOutputLink(GroundedSchemaNode("py:return_concept"),
                                        ListLink(atom1, atom1))
        try:
           result = exec_link.execute()
           self.assertFalse("call should fail")
        except TypeError as e:
           self.assertTrue("but 2 were given" in str(e))

    def test_too_few_args(self):
        atom1 = ConceptNode("atom1")
        exec_link = ExecutionOutputLink(GroundedSchemaNode("py:return_concept"),
                                        ListLink())
        try:
           result = exec_link.execute()
           self.assertFalse("call should fail")
        except TypeError as e:
           self.assertTrue("missing 1 required positional argument" in str(e))