def test_bad_scheduler_fields_file(config_host, config_port): set_config('scheduler.fields_file', 'foobar') site_details = create_location_from_config() with pytest.raises(error.NotFound): create_scheduler_from_config(observer=site_details['observer']) reset_conf(config_host, config_port)
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 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 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_set_scheduler(observatory, caplog): site_details = create_location_from_config() scheduler = create_scheduler_from_config(observer=site_details['observer']) assert observatory.current_observation is None observatory.set_scheduler(scheduler=None) assert observatory.scheduler is None observatory.set_scheduler(scheduler=scheduler) assert observatory.scheduler is not None err_msg = 'Scheduler is not an instance of .*BaseScheduler' with pytest.raises(TypeError, match=err_msg): observatory.set_scheduler('scheduler') err_msg = ".*missing 1 required positional argument.*" with pytest.raises(TypeError, match=err_msg): observatory.set_scheduler()
def scheduler(site_details): return create_scheduler_from_config(observer=site_details['observer'])
def test_no_scheduler_in_config(config_host, config_port): set_config('scheduler', None) site_details = create_location_from_config() assert create_scheduler_from_config( observer=site_details['observer']) is None reset_conf(config_host, config_port)
def test_no_observer(): assert isinstance(create_scheduler_from_config(observer=None), BaseScheduler) is True