提交测试

This commit is contained in:
2024-01-16 17:22:21 +08:00
parent 92862c0372
commit 73635fda01
654 changed files with 178015 additions and 2 deletions

View File

@@ -0,0 +1,54 @@
# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import shutil
import zipfile
import urllib.request
import pytest
@pytest.fixture(scope='module')
def kitchen_set_dir():
# Create temporary output directory
data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '_data')
os.makedirs(data_dir, exist_ok=True)
kitchen_set_path = os.path.join(data_dir, 'kitchenset.zip')
kitchen_set_url = 'http://graphics.pixar.com/usd/files/Kitchen_set.zip'
urllib.request.urlretrieve(kitchen_set_url, kitchen_set_path)
with zipfile.ZipFile(kitchen_set_path, 'r') as zip_ref:
zip_ref.extractall(data_dir)
yield os.path.join(data_dir, 'Kitchen_set')
shutil.rmtree(data_dir)
@pytest.fixture(scope='module')
def out_dir():
# Create temporary output directory
out_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '_out')
os.makedirs(out_dir, exist_ok=True)
yield out_dir
shutil.rmtree(out_dir)
class TestUsdKitchenSet:
def test_runs(self, kitchen_set_dir, out_dir):
args = f'--kitchen_set_dir={kitchen_set_dir} --output_dir={out_dir}'
os.system(f'python examples/tutorial/usd_kitchenset.py {args}')
# Confirm that there are 426 meshes exported
assert len(os.listdir(out_dir)) == 426

View File

@@ -0,0 +1,61 @@
# Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import pytest
import shutil
import torch
import kaolin
from kaolin.utils.testing import tensor_info
@pytest.fixture(scope='module')
def out_dir():
# Create temporary output directory
out_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '_viz_out')
os.makedirs(out_dir, exist_ok=True)
yield out_dir
shutil.rmtree(out_dir) # Note: comment to keep output directory
@pytest.fixture(scope='module')
def obj_paths():
cur_dir = os.path.dirname(os.path.realpath(__file__))
samples_dir = os.path.join(cur_dir, os.pardir, os.pardir, os.pardir, 'samples')
return [os.path.join(samples_dir, 'rocket.obj'),
os.path.join(samples_dir, 'model.obj')]
class TestVisualizeMain:
def test_runs(self, obj_paths, out_dir):
objs = ','.join(obj_paths)
# Check that the main function runs
# Note: to run and capture output do:
# pytest --capture=tee-sys tests/python/examples/
args = '--skip_normalization --test_objs={} --output_dir={}'.format(objs, out_dir)
os.system('python examples/tutorial/visualize_main.py {}'.format(args))
# Spot check one of the outputs
for i in range(len(obj_paths)):
expected = kaolin.io.obj.import_mesh(obj_paths[i])
expected_usd = os.path.join(out_dir, 'output', 'mesh_%d.usd' % i)
assert os.path.exists(expected_usd)
actual_start = kaolin.io.usd.import_mesh(expected_usd, time=0)
actual_end = kaolin.io.usd.import_mesh(expected_usd, time=1000)
assert torch.allclose(expected.vertices, actual_end.vertices, rtol=1e-03)
assert not torch.allclose(expected.vertices, actual_start.vertices)