def test_cannot_observe(caplog): obs = Observatory() site_details = create_location_from_config() cameras = create_cameras_from_config() assert obs.can_observe is False time.sleep(0.5) # log sink time log_record = caplog.records[-1] assert log_record.message.endswith( "not present") and log_record.levelname == "WARNING" obs.scheduler = create_scheduler_from_config( observer=site_details['observer']) assert obs.can_observe is False time.sleep(0.5) # log sink time log_record = caplog.records[-1] assert log_record.message.endswith( "not present") and log_record.levelname == "WARNING" for cam_name, cam in cameras.items(): obs.add_camera(cam_name, cam) assert obs.can_observe is False log_record = caplog.records[-1] time.sleep(0.5) # log sink time assert log_record.message.endswith( "not present") and log_record.levelname == "WARNING"
def test_camera_wrong_type(): # Remove mount simulator set_config('simulator', hardware.get_all_names(without='camera')) with pytest.raises(AttributeError): Observatory(cameras=[Time.now()]) with pytest.raises(AssertionError): Observatory(cameras={'Cam00': Time.now()})
def do_setup_pocs(self, *arg): """Setup and initialize a POCS instance.""" args, kwargs = string_to_params(*arg) simulator = kwargs.get('simulator', list()) if isinstance(simulator, str): simulator = [simulator] # Set whatever simulators were passed during setup client.set_config('simulator', simulator) # Retrieve what was set simulators = client.get_config('simulator', default=list()) if len(simulators): print_warning(f'Using simulators: {simulators}') if 'POCSTIME' in os.environ: print_warning("Clearing POCSTIME variable") del os.environ['POCSTIME'] try: mount = create_mount_from_config() cameras = create_cameras_from_config() scheduler = create_scheduler_from_config() observatory = Observatory(mount=mount, cameras=cameras, scheduler=scheduler) self.pocs = POCS(observatory) self.pocs.initialize() except error.PanError as e: print_warning('Problem setting up POCS: {}'.format(e))
def test_operate_dome(): # Remove dome and night simulator set_config('simulator', hardware.get_all_names(without=['dome', 'night'])) set_config('dome', { 'brand': 'Simulacrum', 'driver': 'simulator', }) set_config('dome', { 'brand': 'Simulacrum', 'driver': 'simulator', }) dome = create_dome_simulator() observatory = Observatory(dome=dome) assert observatory.has_dome assert observatory.open_dome() assert observatory.dome.is_open assert not observatory.dome.is_closed assert observatory.open_dome() assert observatory.dome.is_open assert not observatory.dome.is_closed assert observatory.close_dome() assert observatory.dome.is_closed assert not observatory.dome.is_open assert observatory.close_dome() assert observatory.dome.is_closed assert not observatory.dome.is_open assert observatory.open_dome() assert observatory.dome.is_open assert not observatory.dome.is_closed
def test_set_dome(): set_config('dome', { 'brand': 'Simulacrum', 'driver': 'simulator', }) dome = create_dome_simulator() obs = Observatory(dome=dome) assert obs.has_dome is True obs.set_dome(dome=None) assert obs.has_dome is False obs.set_dome(dome=dome) assert obs.has_dome is True err_msg = 'Dome is not an instance of .*AbstractDome' with pytest.raises(TypeError, match=err_msg): obs.set_dome('dome') err_msg = ".*missing 1 required positional argument.*" with pytest.raises(TypeError, match=err_msg): obs.set_dome()
def test_set_mount(): obs = Observatory() assert obs.mount is None obs.set_mount(mount=None) assert obs.mount is None set_config( 'mount', { 'brand': 'Simulacrum', 'driver': 'simulator', 'model': 'panoptes.pocs.camera.simulator.dslr', }) mount = create_mount_from_config() obs.set_mount(mount=mount) assert isinstance(obs.mount, AbstractMount) is True err_msg = 'Mount is not an instance of .*AbstractMount' with pytest.raises(TypeError, match=err_msg): obs.set_mount(mount='mount') err_msg = ".*missing 1 required positional argument.*" with pytest.raises(TypeError, match=err_msg): obs.set_mount()
def observatory(cameras, mount, site_details, scheduler): """Return a valid Observatory instance with a specific config.""" obs = Observatory(scheduler=scheduler, simulator=['power', 'weather']) for cam_name, cam in cameras.items(): obs.add_camera(cam_name, cam) obs.set_mount(mount) return obs
def observatory(mount, cameras, images_dir): """Return a valid Observatory instance with a specific config.""" site_details = create_location_from_config() scheduler = create_scheduler_from_config(observer=site_details['observer']) obs = Observatory(scheduler=scheduler) obs.set_mount(mount) for cam_name, cam in cameras.items(): obs.add_camera(cam_name, cam) return obs
def test_bad_site(config_host, config_port): set_config('location', {}) with pytest.raises(error.PanError): Observatory() reset_conf(config_host, config_port)
def test_camera(): cameras = create_cameras_from_config() obs = Observatory(cameras=cameras) assert obs.has_cameras
def observatory(): observatory = Observatory(simulator=['all']) yield observatory