-
Notifications
You must be signed in to change notification settings - Fork 49
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
Observatory Dependency Injection #195
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
from astropy import units as u | ||
|
||
from . import PanBase | ||
from .observatory import Observatory | ||
from .state.machine import PanStateMachine | ||
from .utils import current_time | ||
from .utils import get_free_space | ||
|
@@ -25,6 +24,7 @@ class POCS(PanStateMachine, PanBase): | |
the `get_ready()` method the transition that is responsible for moving to the initial state. | ||
|
||
Args: | ||
observatory(Observatory): An instance of a `pocs.observatory.Observatory` class | ||
state_machine_file(str): Filename of the state machine to use, defaults to | ||
'simple_state_table' | ||
messaging(bool): If messaging should be included, defaults to False | ||
|
@@ -38,7 +38,12 @@ class POCS(PanStateMachine, PanBase): | |
|
||
""" | ||
|
||
def __init__(self, state_machine_file='simple_state_table', messaging=False, **kwargs): | ||
def __init__( | ||
self, | ||
observatory, | ||
state_machine_file='simple_state_table', | ||
messaging=False, | ||
**kwargs): | ||
|
||
# Explicitly call the base classes in the order we want | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, this comment and the associated code seem to imply that we should use aggregation for PanStateMachine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be the comment that you missed, about the awkwardness of multiple inheritance. |
||
PanBase.__init__(self, **kwargs) | ||
|
@@ -61,7 +66,7 @@ def __init__(self, state_machine_file='simple_state_table', messaging=False, **k | |
PanStateMachine.__init__(self, state_machine_file, **kwargs) | ||
|
||
# Create our observatory, which does the bulk of the work | ||
self.observatory = Observatory(**kwargs) | ||
self.observatory = observatory | ||
|
||
self._connected = True | ||
self._initialized = False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,24 @@ | |
from pocs import POCS | ||
from pocs import _check_config | ||
from pocs import _check_environment | ||
from pocs.observatory import Observatory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto on the import style. |
||
from pocs.utils import error | ||
from pocs.utils.messaging import PanMessaging | ||
|
||
|
||
@pytest.fixture | ||
def pocs(config): | ||
def observatory(): | ||
observatory = Observatory(simulator=['all']) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop blank line. |
||
yield observatory | ||
|
||
|
||
@pytest.fixture | ||
def pocs(config, observatory): | ||
os.environ['POCSTIME'] = '2016-08-13 13:00:00' | ||
pocs = POCS(simulator=['all'], run_once=True, | ||
|
||
pocs = POCS(observatory, | ||
run_once=True, | ||
config=config, | ||
ignore_local_config=True, db='panoptes_testing') | ||
|
||
|
@@ -177,11 +187,13 @@ def test_is_weather_safe_no_simulator(pocs, db): | |
assert pocs.is_weather_safe() is False | ||
|
||
|
||
def test_run_wait_until_safe(db): | ||
def test_run_wait_until_safe(db, observatory): | ||
os.environ['POCSTIME'] = '2016-08-13 23:00:00' | ||
|
||
def start_pocs(): | ||
pocs = POCS(simulator=['camera', 'mount', 'night'], | ||
observatory.config['simulator'] = ['camera', 'mount', 'night'] | ||
|
||
pocs = POCS(observatory, | ||
messaging=True, safe_delay=15) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, looks like safe_delay is one of several undocumented parameters to POCS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created issue #198 |
||
pocs.db.current.remove({}) | ||
pocs.initialize() | ||
|
@@ -286,9 +298,9 @@ def test_run(pocs): | |
assert pocs.state == 'sleeping' | ||
|
||
|
||
def test_run_interrupt_with_reschedule_of_target(): | ||
def test_run_interrupt_with_reschedule_of_target(observatory): | ||
def start_pocs(): | ||
pocs = POCS(simulator=['all'], messaging=True) | ||
pocs = POCS(observatory, messaging=True) | ||
pocs.logger.info('Before initialize') | ||
pocs.initialize() | ||
pocs.logger.info('POCS initialized, back in test') | ||
|
@@ -321,9 +333,9 @@ def start_pocs(): | |
assert pocs_process.is_alive() is False | ||
|
||
|
||
def test_run_power_down_interrupt(): | ||
def test_run_power_down_interrupt(observatory): | ||
def start_pocs(): | ||
pocs = POCS(simulator=['all'], messaging=True) | ||
pocs = POCS(observatory, messaging=True) | ||
pocs.initialize() | ||
pocs.observatory.scheduler.fields_list = [{'name': 'KIC 8462852', | ||
'position': '20h06m15.4536s +44d27m24.75s', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please import package or module, not class. In this case, you'd say:
import pocs.observatory
And later:
observatory = pocs.observatory.Observatory(simulator=simulator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I remarked in another PR, this was not something that we explicitly decided on, we only talked about using root relative syntax. Either style is correct and the thing that is usually stressed is to be consistent. Since 95% of the current code uses the
from
syntax, which is what we have been encouraging previously, I'm not sure what the arguments are for in favor of changing them all. It is slightly more obvious what package is being referred to so I could understand wanting to switch to it, but that is a conversation we have not had yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you made a comment but disappeared. I looked at the google style code a bit more and see what they are getting at. It's not explicitly saying not to use the
from
style but to use just the module without prefix, which is not what I am doing. Will fix accordingly. From here