import os
import unittest
import carb
import omni.kit.test


class TestUsdPaths(omni.kit.test.AsyncTestCase):
    async def setUp(self):
        # Disable logging for the time of tests to avoid spewing errors
        await omni.usd.get_context().new_stage_async()
        omni.kit.window.usd_paths.tests.create_test_stage()

    async def tearDown(self):
        pass

    async def test_paths(self):
        found_paths = []

        def get_all_paths(path):
            if path not in found_paths:
                found_paths.append(os.path.basename(path).lower())
            return path

        def on_preload_complete():
            paths = sorted(
                [
                    path
                    for path in found_paths
                    if path.endswith(".hdr") or path.endswith(".mdl") or path.find("lenna.") != -1
                ]
            )
            self.assertListEqual(
                paths,
                ["canary_wharf_4k.hdr", "lenna.dds", "lenna.gif", "lenna.jpg", "lenna.png", "lenna.tga", "omnipbr.mdl"],
            )

        await omni.kit.window.usd_paths.get_instance().get_asset_paths(on_preload_complete, get_all_paths)
