"""
Tests for the omnigraph.tutorial.stateAttributesPy node
"""
import omni.graph.core as og
import omni.graph.core.tests as ogts


class TestTutorialStateAttributesPy(ogts.OmniGraphTestCase):
    """.ogn tests only run once while state tests require multiple evaluations, handled here"""

    # ----------------------------------------------------------------------
    async def test_tutorial_state_attributes_py_node(self):
        """Test basic operation of the Python tutorial node containing state attributes"""
        keys = og.Controller.Keys
        (_, [state_node], _, _) = og.Controller.edit(
            "/TestGraph",
            {
                keys.CREATE_NODES: ("StateNode", "omni.graph.tutorials.StateAttributesPy"),
                keys.SET_VALUES: ("StateNode.state:reset", True),
            },
        )
        await og.Controller.evaluate()
        reset_attr = og.Controller.attribute("state:reset", state_node)
        monotonic_attr = og.Controller.attribute("state:monotonic", state_node)

        self.assertEqual(og.Controller.get(reset_attr), False, "Reset attribute set back to False")
        self.assertEqual(og.Controller.get(monotonic_attr), 0, "Monotonic attribute reset to start")

        await og.Controller.evaluate()
        self.assertEqual(og.Controller.get(reset_attr), False, "Reset attribute still False")
        self.assertEqual(og.Controller.get(monotonic_attr), 1, "Monotonic attribute incremented once")

        await og.Controller.evaluate()
        self.assertEqual(og.Controller.get(monotonic_attr), 2, "Monotonic attribute incremented twice")

        og.Controller.set(reset_attr, True)
        await og.Controller.evaluate()
        self.assertEqual(og.Controller.get(reset_attr), False, "Reset again set back to False")
        self.assertEqual(og.Controller.get(monotonic_attr), 0, "Monotonic attribute again reset to start")
