Skip to content

Commit

Permalink
Issue #91: Add tests for example scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed Dec 24, 2023
1 parent 6e973ea commit 05d7492
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
22 changes: 11 additions & 11 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
## Description
Closes #XXX

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

How should this pull request be reviewed?
- [ ] By commit
- [ ] All changes at once

## Type of change
Please include a summary, motivation, and context of the changes and the related issue.

### Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

### How should this pull request be reviewed?
- [ ] By commit
- [ ] All changes at once

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

### Passes Tests
- [ ] __Unit tests__ (General Environment only) `pytest --cov bsk_rl/envs/general_satellite_tasking --cov-report term-missing tests/unittest`
- [ ] __Integrated tests__ (General Environment only) `pytest --cov bsk_rl/envs/general_satellite_tasking --cov-report term-missing tests/integration`
- [ ] __Examples__ (General Environment only) `pytest tests/examples`

### Test Configuration
- Python: [e.g. 3.10.1]
- Basilisk: [e.g. 2.2.0]
- Platform: [e.g. Ubuntu 22.08]
- Python:
- Basilisk:
- Platform:

# Checklist:

Expand All @@ -34,4 +35,3 @@ Please describe the tests that you ran to verify your changes.
- [ ] Commit messages are atomic, are in the form `Issue #XXX: Message` and have a useful message
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
6 changes: 3 additions & 3 deletions examples/general_satellite_tasking/multisat_aeos.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Data environment contains 5000 targets located near random cities, which are
# randomized on reset()
env_features = CityTargets(n_targets=5000, location_offset=10e3)
env_features = CityTargets(n_targets=500, location_offset=10e3)
# Data manager records and rewards uniquely imaged targets
data_manager = data.UniqueImagingManager(env_features)

Expand Down Expand Up @@ -54,7 +54,7 @@

# Instantiate the satellite object. Arguments to the satellite class are set here.
satellite = sat_type(
"EO" + str(i + 1), sat_args, n_ahead_observe=30, n_ahead_act=15
"EO" + str(i + 1), sat_args, n_ahead_observe=15, n_ahead_act=15
)
satellites.append(satellite)

Expand Down Expand Up @@ -82,7 +82,7 @@
# current task is finished
max_step_duration=600.0,
# Set 3-orbit long episodes
time_limit=95 * 60 * 3,
time_limit=95 * 60,
log_level="INFO",
)

Expand Down
4 changes: 2 additions & 2 deletions examples/general_satellite_tasking/satellite_customization.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class CustomDynModel(dynamics.ImagingDynModel, dynamics.LOSCommDynModel):


# Configure the environent
env_features = CityTargets(n_targets=5000)
env_features = CityTargets(n_targets=1000)
data_manager = data.UniqueImagingManager(env_features)
# Use the CustomSat type
sat_type = CustomSatComposed
Expand Down Expand Up @@ -189,7 +189,7 @@ class CustomDynModel(dynamics.ImagingDynModel, dynamics.LOSCommDynModel):
data_manager=data_manager,
sim_rate=0.5,
max_step_duration=600.0,
time_limit=95 * 60 * 3,
time_limit=95 * 60,
log_level="INFO",
)

Expand Down
4 changes: 2 additions & 2 deletions examples/general_satellite_tasking/single_sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# satellite.

# Data environment contains 5000 targets randomly distributed
env_features = StaticTargets(n_targets=5000)
env_features = StaticTargets(n_targets=1000)
# Data manager records and rewards uniquely imaged targets
data_manager = data.UniqueImagingManager(env_features)

Expand Down Expand Up @@ -59,7 +59,7 @@
# current task is finished
max_step_duration=600.0,
# Set 3-orbit long episodes
time_limit=95 * 60 * 3,
time_limit=95 * 60,
# Send the terminated signal in addition to the truncated signal at the end of the
# episode. Needed for some RL algorithms to work correctly.
terminate_on_time_limit=True,
Expand Down
19 changes: 19 additions & 0 deletions tests/examples/test_general_satellite_tasking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pathlib
import runpy

import pytest

examples_path = (
pathlib.Path(__file__).parent
/ ".."
/ ".."
/ "examples"
/ "general_satellite_tasking"
)
scripts = examples_path.resolve().glob("*.py")
script_names = {script.name: script for script in scripts}


@pytest.mark.parametrize("script", script_names)
def test_example_script(script):
runpy.run_path(script_names[script])
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_parallel_api():
try:
parallel_api_test(parallel_env)
except AssertionError as e:
if str(e) == "agent cannot be revived once dead":
warn("'{e}' is a known issue (#59)")
if "agent cannot be revived once dead" in str(e):
warn(f"'{e}' is a known issue (#59)")
else:
raise (e)

0 comments on commit 05d7492

Please sign in to comment.