Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS X crash on import paseos when pip installed #51

Merged
merged 7 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include paseos/resources/default_cfg.toml
include README.md
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- myst-parser
- pykep
- pytest
- pytest-asyncio
- python
- scikit-spatial
- sphinx
Expand Down
2 changes: 1 addition & 1 deletion paseos/activities/activity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ async def job():
return job()
else:
# Run activity and processor
asyncio.run(job())
asyncio.gather(job())

logger.info(f"Activity {activity} completed.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove the file paseos/resources/.DS_Store

File renamed without changes.
32 changes: 19 additions & 13 deletions paseos/tests/activity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
from test_utils import get_default_instance

from paseos import SpacecraftActor

import asyncio
import pytest


async def wait_for_activity(sim):
while sim._is_running_activity is True:
await asyncio.sleep(0.1)


def test_activity():
# tell pytest to create an event loop and execute the tests using the event loop
@pytest.mark.asyncio
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment somewhere what this actually does, so we remember? :)

async def test_activity():
"""Test if performing activity consumes power as expected"""
sim, sat1, earth = get_default_instance()

Expand All @@ -15,7 +22,7 @@ def test_activity():

# Out test case is a function that increments a value, genius.
# (needs a list to increase the actual value by reference and not create a copy)
test_value = [0]
test_val = [0]

async def func(args):
for _ in range(10):
Expand All @@ -28,10 +35,11 @@ async def func(args):
)

# Run the activity
sim.perform_activity("Testing", activity_func_args=[test_value])
sim.perform_activity("Testing", activity_func_args=[test_val])
await wait_for_activity(sim)

# Check activity result
assert test_value[0] == 10
assert test_val[0] == 10

# Check power was depleted as expected
# Activity should run roughly 2s
Expand All @@ -41,7 +49,8 @@ async def func(args):
assert sat1.battery_level_in_Ws > 480 and sat1.battery_level_in_Ws < 490


def test_running_two_activities():
@pytest.mark.asyncio
async def test_running_two_activities():
"""This test ensures that you cannot run two activities at the same time."""
sim, sat1, earth = get_default_instance()

Expand All @@ -63,12 +72,14 @@ async def act2(args):

# try running it
sim.perform_activity("act1", activity_func_args=[test_value])
await wait_for_activity(sim)

# Value should be 42 as first activity is started but then an error occurs trying the second
assert test_value[0] == 42


def test_activity_constraints():
@pytest.mark.asyncio
async def test_activity_constraints():
"""Tests if creating a constraint function to be satisfied during an activity works.
Here we start a function that counts up until we stop charging our solar panels and then prints the value.
"""
Expand Down Expand Up @@ -112,12 +123,7 @@ async def on_termination(args):
constraint_func_args=[sat1],
termination_func_args=[test_value, test_value2],
)
await wait_for_activity(sim)

assert test_value == test_value2
assert sat1.battery_level_in_Ws >= 505


if __name__ == "__main__":
test_running_two_activities()
test_activity()
test_activity_constraints()
5 changes: 3 additions & 2 deletions paseos/utils/load_default_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

def load_default_cfg():
"""Loads the default toml config file from the cfg folder."""
logger.debug("Loading default cfg...")

path = os.path.join(
os.path.dirname(__file__) + "/../../resources/", "default_cfg.toml"
os.path.dirname(__file__) + "/../resources/", "default_cfg.toml"
)
logger.debug(f"loading default cfg from path: {path}")

with open(path) as cfg:
# dynamic=False inhibits automatic generation of non-existing keys
return DotMap(toml.load(cfg), _dynamic=False)