OmniGibson/tests/test_object_removal.py

80 lines
1.8 KiB
Python
Raw Normal View History

2024-04-18 06:54:11 +08:00
import pytest
2024-01-10 15:15:02 +08:00
from utils import og_test
2024-04-18 06:54:11 +08:00
import omnigibson as og
from omnigibson.objects import DatasetObject
from omnigibson.utils.python_utils import NAMES
2024-01-10 15:15:02 +08:00
@og_test
def test_removal_and_readdition(env):
2024-01-10 15:15:02 +08:00
# Add an apple
apple = DatasetObject(
2024-02-09 07:00:26 +08:00
name="apple_unique",
2024-01-10 15:15:02 +08:00
category="apple",
model="agveuv",
)
# Import it into the scene
env.scene.add_object(apple)
2024-01-10 15:15:02 +08:00
2024-05-11 01:49:45 +08:00
# Check that apple exists
assert env.scene.object_registry("name", "apple_unique") is not None
2024-01-10 15:15:02 +08:00
# Step a few times
for _ in range(5):
og.sim.step()
# Remove the apple
env.scene.remove_object(obj=apple)
2024-01-10 15:15:02 +08:00
# Check that NAMES is the same as before
2024-05-11 01:49:45 +08:00
assert env.scene.object_registry("name", "apple_unique") is None
2024-01-10 15:15:02 +08:00
# Importing should work now
apple2 = DatasetObject(
2024-02-09 07:00:26 +08:00
name="apple_unique",
2024-01-10 15:15:02 +08:00
category="apple",
model="agveuv",
)
env.scene.add_object(apple2)
2024-02-09 07:00:26 +08:00
og.sim.step()
2024-01-10 15:15:02 +08:00
2024-01-10 15:24:32 +08:00
# Clear the stuff we added
env.scene.remove_object(apple2)
2024-01-10 15:24:32 +08:00
2024-03-21 04:07:31 +08:00
2024-01-10 15:15:02 +08:00
@og_test
def test_readdition(env):
2024-01-10 15:15:02 +08:00
# Add an apple
apple = DatasetObject(
2024-02-09 07:00:26 +08:00
name="apple_unique",
2024-01-10 15:15:02 +08:00
category="apple",
model="agveuv",
)
# Import it into the scene
env.scene.add_object(apple)
2024-01-10 15:15:02 +08:00
2024-05-11 01:49:45 +08:00
# Check that apple exists
assert env.scene.object_registry("name", "apple_unique") is not None
2024-01-10 15:15:02 +08:00
# Step a few times
for _ in range(5):
og.sim.step()
# Creating and importing a new apple should fail
with pytest.raises(AssertionError):
apple2 = DatasetObject(
2024-02-09 07:00:26 +08:00
name="apple_unique",
2024-01-10 15:15:02 +08:00
category="apple",
model="agveuv",
)
env.scene.add_object(apple2)
2024-01-10 15:15:02 +08:00
2024-05-11 01:49:45 +08:00
# Check that apple exists
assert env.scene.object_registry("name", "apple_unique") is not None
2024-01-10 15:15:02 +08:00
2024-01-10 15:24:32 +08:00
# Clear the stuff we added
env.scene.remove_object(apple)