"""Tests OG Data Model"""

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


# ======================================================================
class TestDataModel(ogts.OmniGraphTestCase):
    """
    Run tests that exercises the data model features of omni graph, such as copy on write and data stealing.
    """

    async def test_copy_on_write(self):
        """
        Test all basic CoW behaviors:
            - Bundle passthrough is passing a reference to original bundle
            - Bundle mutation trigger CoW, but array attribute in the new bundle are references
            - Array attribute mutation in bundle trigger CoW on the attribute
            - Array attribute on node can be passed by ref, and mutation triggers CoW behavior

        Load the test scene which has 3 OgnTestDataModel nodes that performs some checks

            Node #1:
            - receives a passthrough bundle and the original one, and makes sure those are the same
              (not equal, the actual same in RAM)
            - mutate the "points" attribute in its output bundle

            - receives an array attribute and pass it through unchanged

            Node #2:
            - compare the original bundle to the output of node #1, makes sure it is a copy
            - Checks that all array attribute are actually pointing to the same buffer than the original one,
              BUT "points", that has been mutated by #1

            - validate that the received array attribute is actually pointing to the original one
            - mutate it on its output

            Node #3:
            - validate that the array attribute out of node #2 is a new copy
        """

        (result, error) = await ogts.load_test_file("TestCoW.usda", use_caller_subdirectory=True)
        self.assertTrue(result, error)

        # run the graph 2 more times to exercise DB caching
        await omni.kit.app.get_app().next_update_async()
        await omni.kit.app.get_app().next_update_async()
