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

State Machine Updates #219

Merged
merged 3 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 8 additions & 4 deletions pocs/state/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,18 @@ def load_state_table(cls, state_table_name='simple_state_table'):

Args:
state_table_name(str): Name of state table. Corresponds to file name in
`$POCS/resources/state_table/` directory. Default 'simple_state_table'.
`$POCS/resources/state_table/` directory or to absolute path if
starts with "/". Default 'simple_state_table'.

Returns:
dict: Dictonary with `states` and `transitions` keys.
dict: Dictonary with `states` and `transitions` keys.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/Dictonary/Dictionary

"""

state_table_file = "{}/resources/state_table/{}.yaml".format(
os.getenv('POCS', default='/var/panoptes/POCS'), state_table_name)
if not state_table_name.startswith('/'):
state_table_file = "{}/resources/state_table/{}.yaml".format(
os.getenv('POCS', default='/var/panoptes/POCS'), state_table_name)
else:
state_table_file = state_table_name

state_table = {'states': [], 'transitions': []}

Expand Down
11 changes: 0 additions & 11 deletions pocs/tests/test_pocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pocs import PanBase
from pocs import POCS
from pocs.observatory import Observatory
from pocs.utils import error
from pocs.utils.messaging import PanMessaging


Expand Down Expand Up @@ -113,16 +112,6 @@ def test_initialization(pocs):
assert pocs.is_initialized


def test_bad_state_machine_file():
with pytest.raises(error.InvalidConfig):
POCS.load_state_table(state_table_name='foo')


def test_load_bad_state(pocs):
with pytest.raises(error.InvalidConfig):
pocs._load_state('foo')


def test_default_lookup_trigger(pocs):
pocs.state = 'parking'
pocs.next_state = 'parking'
Expand Down
37 changes: 37 additions & 0 deletions pocs/tests/test_state_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import pytest
import yaml

from pocs import POCS
from pocs.observatory import Observatory
from pocs.utils import error


@pytest.fixture
def observatory():
observatory = Observatory(simulator=['all'])

yield observatory


def test_bad_state_machine_file():
with pytest.raises(error.InvalidConfig):
POCS.load_state_table(state_table_name='foo')


def test_load_bad_state(observatory):
pocs = POCS(observatory)

with pytest.raises(error.InvalidConfig):
pocs._load_state('foo')


def test_state_machine_absolute(temp_file):
state_table = POCS.load_state_table()
assert isinstance(state_table, dict)

with open(temp_file, 'w') as f:
f.write(yaml.dump(state_table))

file_path = os.path.abspath(temp_file)
assert POCS.load_state_table(state_table_name=file_path)