<commit_before>import unittest

from opencog.atomspace import AtomSpace
from opencog.utilities import initialize_opencog, finalize_opencog
from opencog.type_constructors import (GroundedObjectNode,
                                       ApplyLink, MethodOfLink,
                                       ListLink, ConceptNode)
from opencog.bindlink import execute_atom

class GroundedObjectNodeTest(unittest.TestCase):

    def setUp(self):
        self.space = AtomSpace()
        initialize_opencog(self.space)

    def tearDown(self):
        finalize_opencog()
        del self.space

    def test_call_grounded_object_predicate(self):
        grounded_object_node = GroundedObjectNode("test_grounded_object_node",
                                                  TestObject("some object"))
        exec_link = ApplyLink(
                        MethodOfLink(grounded_object_node, ConceptNode("foo")),
                        ListLink(ConceptNode("arg"))
                        )

        result = execute_atom(self.space,  exec_link)

        self.assertEqual(result, ConceptNode("arg"))

    def test_call_grounded_object_no_arguments(self):
        grounded_object_node = GroundedObjectNode("test_grounded_object_node",
                                                  TestObject("some object"))
        exec_link = ApplyLink(
                        MethodOfLink(grounded_object_node,
                                     ConceptNode("noarguments")),
                        ListLink()
                    )

        result = execute_atom(self.space,  exec_link)

        self.assertEqual(result, ConceptNode("empty"))

    def test_call_grounded_object_predicate_two_args(self):
        grounded_object_node = GroundedObjectNode("test_grounded_object_node",
                                                  TestObject("some object"))
        exec_link = ApplyLink(
                        MethodOfLink(grounded_object_node, ConceptNode("second")),
                        ListLink(
                            ConceptNode("firstArg"),
                            ConceptNode("secondArg")
                        )
                    )

        result = execute_atom(self.space,  exec_link)

        self.assertEqual(result, ConceptNode("secondArg"))

    def test_set_object(self):
        grounded_object_node = GroundedObjectNode("test_grounded_object_node",
                                                  TestObject("some object"))
        grounded_object_node.set_object(TestObject("other object"))

        self.assertEqual(grounded_object_node.get_object().name, "other object")

    def test_create_grounded_object_node_without_object(self):
        grounded_object_node = GroundedObjectNode("test_grounded_object_node")

        self.assertTrue(grounded_object_node.get_object() is None)

class TestObject:

    def __init__(self, name):
        self.name = name

    def foo(self, arg):
        return arg

    def noarguments(self):
        return ConceptNode("empty")

    def second(self, first, second):
        return second

if __name__ == '__main__':
    unittest.main()
<commit_msg>Unit test refactoring<commit_after>import unittest

from opencog.atomspace import AtomSpace
from opencog.utilities import initialize_opencog, finalize_opencog
from opencog.type_constructors import (GroundedObjectNode,
                                       ApplyLink, MethodOfLink,
                                       ListLink, ConceptNode)
from opencog.bindlink import execute_atom

class GroundedObjectNodeTest(unittest.TestCase):

    def setUp(self):
        self.space = AtomSpace()
        initialize_opencog(self.space)

    def tearDown(self):
        finalize_opencog()
        del self.space

    def test_call_grounded_object_call(self):
        exec_link = ApplyLink(
                        MethodOfLink(
                            GroundedObjectNode("obj", TestObject("obj")),
                            ConceptNode("get_argument")
                        ),
                        ListLink(
                            ConceptNode("arg")
                        )
                    )

        result = execute_atom(self.space,  exec_link)

        self.assertEqual(result, ConceptNode("arg"))

    def test_call_grounded_object_no_arguments(self):
        exec_link = ApplyLink(
                        MethodOfLink(
                            GroundedObjectNode("obj", TestObject("obj")),
                            ConceptNode("no_arguments")
                        ),
                        ListLink()
                    )

        result = execute_atom(self.space,  exec_link)

        self.assertEqual(result, ConceptNode("empty"))

    def test_call_grounded_object_predicate_two_args(self):
        exec_link = ApplyLink(
                        MethodOfLink(
                            GroundedObjectNode("obj", TestObject("obj")),
                            ConceptNode("get_second")
                        ),
                        ListLink(
                            ConceptNode("first"),
                            ConceptNode("second")
                        )
                    )

        result = execute_atom(self.space,  exec_link)

        self.assertEqual(result, ConceptNode("second"))

    def test_set_object(self):
        grounded_object_node = GroundedObjectNode("a", TestObject("some object"))
        grounded_object_node.set_object(TestObject("other object"))

        self.assertEqual(grounded_object_node.get_object().name, "other object")

    def test_create_grounded_object_node_without_object(self):
        grounded_object_node = GroundedObjectNode("obj")

        self.assertTrue(grounded_object_node.get_object() is None)

class TestObject:

    def __init__(self, name):
        self.name = name

    def get_argument(self, arg):
        return arg

    def no_arguments(self):
        return ConceptNode("empty")

    def get_second(self, first, second):
        return second

if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.07896924355777224, 'fraction_numerical': 0.0, 'mean_word_length': 1.8404154863078377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7583275', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1498, 'n_words': 255}