|
1 | 1 | # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | +import pathlib |
| 4 | +import shutil |
| 5 | +from unittest.mock import patch |
3 | 6 |
|
| 7 | +import usdex.core |
| 8 | +import usdex.test |
| 9 | +from pxr import Sdf, Tf, Usd |
| 10 | + |
| 11 | +from urdf_usd_converter._impl.cli import run |
4 | 12 | from tests.util.ConverterTestCase import ConverterTestCase |
5 | 13 |
|
6 | 14 |
|
7 | 15 | class TestCli(ConverterTestCase): |
8 | 16 |
|
9 | 17 | def test_run(self): |
10 | | - pass # dummy test for now |
| 18 | + for robot in pathlib.Path("tests/data").glob("*.urdf"): |
| 19 | + robot_name = robot.stem |
| 20 | + with patch("sys.argv", ["urdf_usd_converter", str(robot), self.tmpDir()]): |
| 21 | + self.assertEqual(run(), 0, f"Failed to convert {robot}") |
| 22 | + self.assertTrue((pathlib.Path(self.tmpDir()) / f"{robot_name}.usda").exists()) |
| 23 | + |
| 24 | + def test_invalid_input(self): |
| 25 | + with ( |
| 26 | + patch("sys.argv", ["urdf_usd_converter", "tests/data/invalid.xml", self.tmpDir()]), |
| 27 | + usdex.test.ScopedDiagnosticChecker(self, [(Tf.TF_DIAGNOSTIC_WARNING_TYPE, "Input file does not exist.*")]), |
| 28 | + ): |
| 29 | + self.assertEqual(run(), 1, "Expected non-zero exit code for invalid input") |
| 30 | + |
| 31 | + def test_input_path_is_directory(self): |
| 32 | + # Create a directory as input_file (should fail) |
| 33 | + input_dir = pathlib.Path("tests/data/input_dir") |
| 34 | + input_dir.mkdir(parents=True, exist_ok=True) |
| 35 | + try: |
| 36 | + with ( |
| 37 | + patch("sys.argv", ["urdf_usd_converter", str(input_dir), self.tmpDir()]), |
| 38 | + usdex.test.ScopedDiagnosticChecker(self, [(Tf.TF_DIAGNOSTIC_WARNING_TYPE, "Input path is not a file.*")]), |
| 39 | + ): |
| 40 | + self.assertEqual(run(), 1, "Expected non-zero exit code for input path as directory") |
| 41 | + finally: |
| 42 | + shutil.rmtree(input_dir) |
| 43 | + |
| 44 | + def test_input_file_not_xml(self): |
| 45 | + # Create a non-xml file as input_file (should fail) |
| 46 | + not_xml = pathlib.Path("tests/data/not_xml.txt") |
| 47 | + not_xml.write_text("dummy content") |
| 48 | + try: |
| 49 | + with ( |
| 50 | + patch("sys.argv", ["urdf_usd_converter", str(not_xml), self.tmpDir()]), |
| 51 | + usdex.test.ScopedDiagnosticChecker(self, [(Tf.TF_DIAGNOSTIC_WARNING_TYPE, "Only URDF.*are supported as input.*")]), |
| 52 | + ): |
| 53 | + self.assertEqual(run(), 1, "Expected non-zero exit code for non-xml input file") |
| 54 | + finally: |
| 55 | + not_xml.unlink() |
0 commit comments