import omni.kit.test
import omni.graph.core as og
import omni.graph.core.tests as ogts


class TestOgn(ogts.OmniGraphTestCase):

    async def test_data_access(self):
        from omni.graph.examples.cpp.ogn.OgnSimpleGatherDatabase import OgnSimpleGatherDatabase
        (_, (test_node,), _, _) = og.Controller.edit("/TestGraph", {
            og.Controller.Keys.CREATE_NODES: ("Template_omni_graph_examples_cpp_SimpleGather", "omni.graph.examples.cpp.SimpleGather")
        })
        database = OgnSimpleGatherDatabase(test_node)
        self.assertTrue(test_node.is_valid())
        node_type_name = test_node.get_type_name()
        self.assertEqual(og.GraphRegistry().get_node_type_version(node_type_name), 1)

        def _attr_error(attribute: og.Attribute, usd_test: bool) -> str:
            test_type = "USD Load" if usd_test else "Database Access"
            return f"{node_type_name} {test_type} Test - {attribute.get_name()} value error"


        self.assertTrue(test_node.get_attribute_exists("inputs:input0"))
        attribute = test_node.get_attribute("inputs:input0")
        db_value = database.inputs.input0
        expected_value = []
        ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))

        self.assertTrue(test_node.get_attribute_exists("inputs:multiplier"))
        attribute = test_node.get_attribute("inputs:multiplier")
        db_value = database.inputs.multiplier
        expected_value = 0.0
        ogts.verify_values(expected_value, db_value, _attr_error(attribute, False))

        self.assertTrue(test_node.get_attribute_exists("outputs:output0"))
        attribute = test_node.get_attribute("outputs:output0")
        db_value = database.outputs.output0
