"""Basic tests of the Python interface to C++ nodes generated from a .ogn file"""
import omni.graph.core as og
import omni.graph.core.tests as ogts
from omni.graph.tutorials.ogn.OgnTutorialSimpleDataDatabase import OgnTutorialSimpleDataDatabase


# ======================================================================
class TestOmniGraphPythonInterface(ogts.OmniGraphTestCase):
    """Run a simple unit test that exercises generated Python interface functionality"""

    # ----------------------------------------------------------------------
    async def test_setting_in_ogn_python_api(self):
        """Test ability to set inputs on a node and retrieve them"""
        (_, [simple_node], _, _) = og.Controller.edit(
            "/TestGraph",
            {
                og.Controller.Keys.CREATE_NODES: ("PyTest_SimpleNode", "omni.graph.tutorials.SimpleData"),
            },
        )
        await og.Controller.evaluate()

        interface = OgnTutorialSimpleDataDatabase(simple_node)

        # Set input values through the database interface
        interface.inputs.a_bool = False
        interface.inputs.a_half = 2.0
        interface.inputs.a_int = 3
        interface.inputs.a_int64 = 4
        interface.inputs.a_float = 5.0
        interface.inputs.a_double = 6.0
        # interface.inputs.a_token = "hello"
        interface.inputs.unsigned_a_uchar = 7
        interface.inputs.unsigned_a_uint = 8
        interface.inputs.unsigned_a_uint64 = 9

        # Run the node's compute method
        await og.Controller.evaluate()

        # Retrieve output values from the database interface and verify against expected values
        self.assertEqual(interface.outputs.a_bool, True)
        self.assertAlmostEqual(interface.outputs.a_half, 3.0)
        self.assertEqual(interface.outputs.a_int, 4)
        self.assertEqual(interface.outputs.a_int64, 5)
        self.assertAlmostEqual(interface.outputs.a_float, 6.0)
        self.assertAlmostEqual(interface.outputs.a_double, 7.0)
        # self.assertEqual(interface.outputs.a_token, "world")
        self.assertEqual(interface.outputs.unsigned_a_uchar, 8)
        self.assertEqual(interface.outputs.unsigned_a_uint, 9)
        self.assertEqual(interface.outputs.unsigned_a_uint64, 10)

    # ----------------------------------------------------------------------
    async def test_check_has_state(self):
        """Test ability to correctly determine if a node has marked itself as having internal state"""
        stateless_node_type = og.get_node_type("omni.graph.tutorials.SimpleData")
        stateful_node_type = og.get_node_type("omni.graph.tutorials.StatePy")
        self.assertFalse(stateless_node_type.has_state())
        self.assertTrue(stateful_node_type.has_state())
