def test_bad_mount(config): conf = config.copy() simulator = hardware.get_all_names(without=['mount']) conf['mount']['port'] = '/dev/' conf['mount']['driver'] = 'foobar' with pytest.raises(error.NotFound): Observatory(simulator=simulator, config=conf, ignore_local_config=True)
def test_camera_import_error(config): conf = config.copy() conf['cameras']['devices'][0]['model'] = 'foobar' conf['cameras']['devices'][0]['port'] = 'usb:001,002' simulator = hardware.get_all_names(without=['camera']) with pytest.raises(error.NotFound): Observatory(simulator=simulator, config=conf, auto_detect=False, ignore_local_config=True)
def simulator(): """ We assume everything runs on a simulator Tests that require real hardware should be marked with the appropriate fixtue (see `conftest.py`) """ return hardware.get_all_names(without=['night'])
def pytest_collection_modifyitems(config, items): """ Modify tests to skip or not based on cli options Certain tests should only be run when the appropriate hardware is attached. The names of the types of hardware are in hardware.py, but include 'mount' and 'camera'. For a test that requires a mount, for example, the test should be marked as follows: `@pytest.mark.with_mount`: Run tests with mount attached. And the same applies for the names of other types of hardware. Note: We are marking which tests to skip rather than which tests to include so the logic is opposite of the options. """ hardware_list = config.getoption('--with-hardware') for name in hardware.get_all_names(): # Do we have hardware called name? if name in hardware_list: # Yes, so don't need to skip tests with keyword "with_name". continue # No, so find all the tests that need this type of hardware and mark them to be skipped. skip = pytest.mark.skip( reason="need --with-hardware={} option to run".format(name)) keyword = 'with_' + name for item in items: if keyword in item.keywords: item.add_marker(skip)
def pytest_collection_modifyitems(config, items): """ Modify tests to skip or not based on cli options Certain tests should only be run when the appropriate hardware is attached. The names of the types of hardware are in hardware.py, but include 'mount' and 'camera'. For a test that requires a mount, for example, the test should be marked as follows: `@pytest.mark.with_mount`: Run tests with mount attached. And the same applies for the names of other types of hardware. Note: We are marking which tests to skip rather than which tests to include so the logic is opposite of the options. """ hardware_list = config.getoption('--with-hardware') for name in hardware.get_all_names(): # Do we have hardware called name? if name in hardware_list: # Yes, so don't need to skip tests with keyword "with_name". continue # No, so find all the tests that need this type of hardware and mark them to be skipped. skip = pytest.mark.skip(reason="need --with-hardware={} option to run".format(name)) keyword = 'with_' + name for item in items: if keyword in item.keywords: item.add_marker(skip)
def pocs_with_dome(config_with_simulated_dome): os.environ['POCSTIME'] = '2016-08-13 13:00:00' simulator = hardware.get_all_names(without=['dome']) observatory = Observatory(config=config_with_simulated_dome, simulator=simulator, ignore_local_config=True) pocs = POCS(observatory, run_once=True, config=config_with_simulated_dome, ignore_local_config=True, db='panoptes_testing') pocs.observatory.scheduler.fields_list = [ {'name': 'Wasp 33', 'position': '02h26m51.0582s +37d33m01.733s', 'priority': '100', 'exp_time': 2, 'min_nexp': 2, 'exp_set_size': 2, }, ] yield pocs pocs.power_down()
def test_operate_dome(config_with_simulated_dome): simulator = hardware.get_all_names(without=['dome', 'night']) observatory = Observatory(config=config_with_simulated_dome, simulator=simulator, ignore_local_config=True) assert observatory.has_dome assert observatory.open_dome() assert observatory.dome.is_open assert observatory.close_dome() assert observatory.dome.is_closed
#!/usr/bin/env python3 from pocs import hardware from pocs import POCS pocs = POCS(simulator=hardware.get_all_names(without=['mount', 'night'])) pocs.observatory.mount.initialize() pocs.observatory.mount.home_and_park() pocs.power_down()
def test_camera_not_found(config): conf = config.copy() simulator = hardware.get_all_names(without=['camera']) with pytest.raises(error.PanError): Observatory(simulator=simulator, config=conf, ignore_local_config=True)
def test_bad_camera(config): conf = config.copy() simulator = hardware.get_all_names(without=['camera']) with pytest.raises(error.PanError): Observatory(simulator=simulator, config=conf, auto_detect=True, ignore_local_config=True)