Skip to content

Commit

Permalink
[tests] split bullet world tetsts into testCase and unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigul committed Jan 3, 2024
1 parent c36780d commit b54e198
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/pycram/bullet_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def __enter__(self):
def __exit__(self, *args):
if not self.prev_world == None:
BulletWorld.current_bullet_world = self.prev_world
BulletWorld.current_bullet_world.world_sync.pause_sync = False
BulletWorld.current_bullet_world.world_sync.pause_sync = False


class WorldSync(threading.Thread):
Expand Down
54 changes: 54 additions & 0 deletions test/bullet_world_testcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import unittest

import numpy as np
import rospkg

from pycram.bullet_world import BulletWorld, Object, fix_missing_inertial
from pycram.pose import Pose
from pycram.robot_descriptions import robot_description
from pycram.process_module import ProcessModule
from pycram.enums import ObjectType
import os
import xml.etree.ElementTree as ET
import tf


class BulletWorldTestCase(unittest.TestCase):

world: BulletWorld

@classmethod
def setUpClass(cls):
cls.world = BulletWorld("DIRECT")
cls.robot = Object(robot_description.name, ObjectType.ROBOT, robot_description.name + ".urdf")
cls.kitchen = Object("kitchen", ObjectType.ENVIRONMENT, "kitchen.urdf")
cls.milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([1.3, 1, 0.9]))
cls.cereal = Object("cereal", ObjectType.BREAKFAST_CEREAL, "breakfast_cereal.stl", pose=Pose([1.3, 0.7, 0.95]))
ProcessModule.execution_delay = False

def setUp(self):
self.world.reset_bullet_world()



def tearDown(self):
self.world.reset_bullet_world()

@classmethod
def tearDownClass(cls):
cls.world.exit()


class XMLTester(unittest.TestCase):

def setUp(self) -> None:
rospack = rospkg.RosPack()
filename = rospack.get_path('pycram') + '/resources/' + 'pr2.urdf'
with open(filename, "r") as f:
self.urdf_string = f.read()

def test_inertial(self):
result = fix_missing_inertial(self.urdf_string)
resulting_tree = ET.ElementTree(ET.fromstring(result))
for element in resulting_tree.iter("link"):
self.assertTrue(len([*element.iter("inertial")]) > 0)
4 changes: 2 additions & 2 deletions test/local_transformer_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from src.pycram.local_transformer import LocalTransformer
from pycram.robot_descriptions import robot_description
from pycram.pose import Pose, Transform
import test_bullet_world
import bullet_world_testcase


class TestLocalTransformer(test_bullet_world.BulletWorldTest):
class TestLocalTransformer(test_bullet_world.BulletWorldTestCase):

def test_singelton(self):
l1 = LocalTransformer()
Expand Down
4 changes: 2 additions & 2 deletions test/test_action_designator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from pycram.pose import Pose
from pycram.enums import ObjectType
import pycram.enums
import test_bullet_world
from bullet_world_testcase import BulletWorldTestCase
import numpy as np


class TestActionDesignatorGrounding(test_bullet_world.BulletWorldTest):
class TestActionDesignatorGrounding(BulletWorldTestCase):
"""Testcase for the grounding methods of action designators."""

def test_move_torso(self):
Expand Down
49 changes: 4 additions & 45 deletions test/test_bullet_world.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
import unittest

import numpy as np
from pycram.bullet_world import BulletWorld, Object, fix_missing_inertial
from bullet_world_testcase import BulletWorldTestCase
from pycram.pose import Pose
from pycram.robot_descriptions import robot_description
from pycram.process_module import ProcessModule
from pycram.enums import ObjectType
import os
import xml.etree.ElementTree as ET
import tf


class BulletWorldTest(unittest.TestCase):

world: BulletWorld
import numpy as np

@classmethod
def setUpClass(cls):
cls.world = BulletWorld("DIRECT")
cls.robot = Object(robot_description.name, ObjectType.ROBOT, robot_description.name + ".urdf")
cls.kitchen = Object("kitchen", ObjectType.ENVIRONMENT, "kitchen.urdf")
cls.milk = Object("milk", ObjectType.MILK, "milk.stl", pose=Pose([1.3, 1, 0.9]))
cls.cereal = Object("cereal", ObjectType.BREAKFAST_CEREAL, "breakfast_cereal.stl", pose=Pose([1.3, 0.7, 0.95]))
ProcessModule.execution_delay = False

def setUp(self):
self.world.reset_bullet_world()
class BulletWorldTest(BulletWorldTestCase):

def test_object_movement(self):
self.milk.set_position(Pose([0, 1, 1]))
Expand All @@ -36,23 +14,4 @@ def test_robot_orientation(self):
head_position = self.robot.get_link_position('head_pan_link').z
#self.robot.set_orientation(list(2*tf.transformations.quaternion_from_euler(0, 0, np.pi, axes="sxyz")))
self.robot.set_orientation(Pose(orientation=[0, 0, 1, 1]))
self.assertEqual(self.robot.get_link_position('head_pan_link').z, head_position)

def tearDown(self):
self.world.reset_bullet_world()

@classmethod
def tearDownClass(cls):
cls.world.exit()


class XMLTester(unittest.TestCase):

def setUp(self) -> None:
self.urdf_string = open(os.path.join("..", "resources", "pr2.urdf"), "r").read()

def test_inertial(self):
result = fix_missing_inertial(self.urdf_string)
resulting_tree = ET.ElementTree(ET.fromstring(result))
for element in resulting_tree.iter("link"):
self.assertTrue(len([*element.iter("inertial")]) > 0)
self.assertEqual(self.robot.get_link_position('head_pan_link').z, head_position)
4 changes: 2 additions & 2 deletions test/test_bullet_world_reasoning.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import time

from test_bullet_world import BulletWorldTest
from bullet_world_testcase import BulletWorldTestCase
import pycram.bullet_world_reasoning as btr
from pycram.pose import Pose
from pycram.robot_descriptions import robot_description


class TestBulletWorldReasoning(BulletWorldTest):
class TestCaseBulletWorldReasoning(BulletWorldTestCase):

def test_contact(self):
self.milk.set_pose(Pose([1, 1, 1]))
Expand Down
4 changes: 2 additions & 2 deletions test/test_costmaps.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from test_bullet_world import BulletWorldTest
from bullet_world_testcase import BulletWorldTestCase
from pycram.costmaps import OccupancyCostmap
from pycram.pose import Pose
import numpy as np


class TestCostmaps(BulletWorldTest):
class TestCostmapsCase(BulletWorldTestCase):

def test_raytest_bug(self):
for i in range(30):
Expand Down
4 changes: 2 additions & 2 deletions test/test_location_designator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from pycram.process_module import simulated_robot
from pycram.pose import Pose
import pycram.enums
import test_bullet_world
from bullet_world_testcase import BulletWorldTestCase


class TestActionDesignatorGrounding(test_bullet_world.BulletWorldTest):
class TestActionDesignatorGrounding(BulletWorldTestCase):

def test_reachability(self):
self.robot.set_joint_state(robot_description.torso_joint, 0.3)
Expand Down
4 changes: 2 additions & 2 deletions test/test_object_designator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import unittest
import test_bullet_world
from bullet_world_testcase import BulletWorldTestCase
from pycram.designators.object_designator import *
from pycram.enums import ObjectType


class TestObjectDesignator(test_bullet_world.BulletWorldTest):
class TestObjectDesignator(BulletWorldTestCase):

def test_object_grounding(self):
description = ObjectDesignatorDescription(["milk"], [ObjectType.MILK])
Expand Down
6 changes: 3 additions & 3 deletions test/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pycram.orm.task
import pycram.task
import pycram.task
import test_bullet_world
from bullet_world_testcase import BulletWorldTestCase
import test_task_tree
from pycram.designators import action_designator, object_designator
from pycram.pose import Pose
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_meta_data_alternation(self):
self.assertEqual(metadata_result.description, "Test")


class ORMObjectDesignatorTestCase(test_bullet_world.BulletWorldTest):
class ORMObjectDesignatorTestCase(BulletWorldTestCase):
"""Test ORM functionality with a plan including object designators. """

engine: sqlalchemy.engine.Engine
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_task_tree_node_parents(self):
self.assertTrue([r[i].parent == r[r[i].parent_id - 1] for i in range(len(r)) if r[i].parent_id is not None])


class MotionDesigTest(test_bullet_world.BulletWorldTest):
class MotionDesigTest(BulletWorldTestCase):
engine: sqlalchemy.engine.Engine
session: sqlalchemy.orm.Session

Expand Down
4 changes: 2 additions & 2 deletions test/test_task_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from pycram.task import with_tree
import unittest
import anytree
import test_bullet_world
from bullet_world_testcase import BulletWorldTestCase
import pycram.plan_failures
from pycram.designators import object_designator, action_designator


class TaskTreeTestCase(test_bullet_world.BulletWorldTest):
class TaskTreeTestCase(BulletWorldTestCase):

@with_tree
def plan(self):
Expand Down

0 comments on commit b54e198

Please sign in to comment.