Skip to content

Commit

Permalink
add first pytest unit tests (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsilver authored Aug 19, 2024
1 parent d60a388 commit 8b5759c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 15 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI Checks

on: [pull_request]

jobs:
unit-tests:
name: Unit Tests
runs-on: "ubuntu-20.04"
defaults:
run:
shell: bash -el {0}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: rcareworld
python-version: "3.10"
- run: |
cd pyrcareworld
pip install -r requirements.txt
pip install -e .
pip uninstall -y numpy
conda install numpy
cd ../
pytest tests/
15 changes: 15 additions & 0 deletions pyrcareworld/pyrcareworld/envs/bathing_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Bathing environment for the PhyRC competition."""

from pyrcareworld.envs.base_env import RCareWorld
from pathlib import Path


_TEMPLATE_PATH = Path(__file__).parents[3] / "template"
_DEFAULT_EXECUTABLE_PATH = _TEMPLATE_PATH / "Bathing" / "BathingPlayer.x86_64"


class BathingEnv(RCareWorld):
"""Bathing environment for the PhyRC competition."""

def __init__(self, executable_file=str(_DEFAULT_EXECUTABLE_PATH), *args, **kwargs):
super().__init__(executable_file=executable_file, *args, **kwargs)
15 changes: 15 additions & 0 deletions pyrcareworld/pyrcareworld/envs/dressing_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Dressing environment for the PhyRC competition."""

from pyrcareworld.envs.base_env import RCareWorld
from pathlib import Path


_TEMPLATE_PATH = Path(__file__).parents[3] / "template"
_DEFAULT_EXECUTABLE_PATH = _TEMPLATE_PATH / "Dressing" / "DressingPlayer.x86_64"


class DressingEnv(RCareWorld):
"""Dressing environment for the PhyRC competition."""

def __init__(self, executable_file=str(_DEFAULT_EXECUTABLE_PATH), *args, **kwargs):
super().__init__(executable_file=executable_file, *args, **kwargs)
1 change: 1 addition & 0 deletions pyrcareworld/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ opencv-contrib-python
requests
open3d
pandas
pytest>=7.2.2

# gym==0.21.0
# cloudpickle
Expand Down
11 changes: 3 additions & 8 deletions template/test_bathing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
from pyrcareworld.envs.base_env import RCareWorld
from pyrcareworld.envs.bathing_env import BathingEnv
import numpy as np
import cv2
import os
import argparse

def _main(use_graphics=False):
Expand All @@ -23,12 +22,8 @@ def _main(use_graphics=False):
"""

print(text)
# Initialize the environment with the specified executable file and graphics option

script_dir = os.path.dirname(os.path.abspath(__file__))
executable_file = os.path.join(script_dir, "Bathing", "BathingPlayer.x86_64")

env = RCareWorld(executable_file=executable_file, graphics=use_graphics)
# Initialize the environment
env = BathingEnv(graphics=use_graphics)
print(env.attrs)

stretch_id = 221582
Expand Down
10 changes: 3 additions & 7 deletions template/test_dressing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyrcareworld.envs.base_env import RCareWorld
from pyrcareworld.envs.dressing_env import DressingEnv
import pyrcareworld.attributes as attr
import cv2
import os
Expand All @@ -21,12 +21,8 @@ def _main(use_graphics=False):
"""

print(text)
# Initialize the environment with the specified assets and set the time step

script_dir = os.path.dirname(os.path.abspath(__file__))
executable_file = os.path.join(script_dir, "Dressing", "DressingPlayer.x86_64")

env = RCareWorld(executable_file=executable_file, graphics=use_graphics)
# Initialize the environment
env = DressingEnv(graphics=use_graphics)
print(env.attrs)

kinova_id = 315893
Expand Down
16 changes: 16 additions & 0 deletions tests/test_env_initialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Tests that the main environments initialize without crashing."""

from pyrcareworld.envs.bathing_env import BathingEnv
from pyrcareworld.envs.dressing_env import DressingEnv


def test_bathing_env_initialization():
"""Tests that the bathing environment initializes without crashing."""
env = BathingEnv(graphics=False)
assert isinstance(env, BathingEnv)


def test_dressing_env_initialization():
"""Tests that the dressing environment initializes without crashing."""
env = DressingEnv(graphics=False)
assert isinstance(env, DressingEnv)

0 comments on commit 8b5759c

Please sign in to comment.