import omni.kit.test
from .test_base import KitLaunchTest
from pathlib import Path

import omni


class TestDefaultStage(KitLaunchTest):

    async def test_default_stage(self):
        """Test to ensure a default stage is created when it's requested."""

        kit_file = "[dependencies]\n"
        kit_file += '"omni.usd" = {}\n'
        kit_file += '"omni.kit.loop-default" = {}\n'
        kit_file += '"omni.kit.stage_templates" = {}\n'

        kit_file += """
        # Register extension folder from this repo in kit
        [settings.app.exts]
        folders.'++' = ["${app}/../exts" ]

        [settings.app.extensions]
        enabledDeprecated = [
            ]
        """
        script = f"""
import omni.usd
import omni.kit.app
import asyncio
from pxr import Sdf, Usd


async def main():
    for i in range(10):
        await omni.kit.app.get_app().next_update_async()

    usd_context = omni.usd.get_context()
    # Gets stage to see if a default stage is created.
    stage = usd_context.get_stage()
    stage.DefinePrim("/test")

asyncio.ensure_future(main())
        """

        await self._run_kit_with_script(
            script,
            args=["--no-window", "--/app/quitAfter=20", "--/app/content/emptyStageOnStart=True"],
            kit_file=kit_file
        )
