def test_unroll( sample_file, recwarn): """ Tests parser.py::unroll() """ gavo = sample_file sources = gavo.find_instances(Source) assert len(sources) == 2 # Uses same instances as test_is_template() test # Acting on GLOBAL instance assert unroll(sources[0].position) == [] assert unroll(sources[0].position_error) == [] # Acting on TEMPLATE instance (table has 3 rows) # * method unpacks it into array of separate instances assert isinstance(sources[1].position, SkyCoordinate) positions = unroll(sources[1].position) assert len(positions) == 3 assert isinstance(positions[0], SkyCoordinate) assert isinstance(positions[1], SkyCoordinate) assert isinstance(positions[2], SkyCoordinate) # Acting on non-VO Object try: assert unroll(gavo) == 0 except ValueError as ex: assert "Instance is not an adapter or a data model type" in str(ex) pass assert len(recwarn) == 0
def test_references_orm_unroll(references_file, recwarn): sources = references_file.find_instances(Source) filters = references_file.find_instances(PhotometryFilter) f814w = None f606w = None for hsc_filter in filters: if hsc_filter.name == "F814W": f814w = hsc_filter else: f606w = hsc_filter source = unroll(sources[0]) assert source[0].luminosity[0].filter is f606w assert source[1].luminosity[0].filter is f814w
def test_references_orm_unroll_hsc(hsc_data_file, recwarn): sources = hsc_data_file.find_instances(Detection) filters = hsc_data_file.find_instances(PhotometryFilter) f814w = None f606w = None for hsc_filter in filters: if hsc_filter.name == "F814W": f814w = hsc_filter else: f606w = hsc_filter assert sources[0].cardinality == 7 source = unroll(sources[0]) assert source[0].luminosity[0].filter is f814w assert source[1].luminosity[0].filter is f606w assert source[2].luminosity[0].filter is f606w assert source[3].luminosity[0].filter is f606w assert source[4].luminosity[0].filter is f606w assert source[5].luminosity[0].filter is f606w assert source[6].luminosity[0].filter is f606w
def test_source_unroll(context_test5, recwarn): template_source = context_test5.find_instances(Source)[0] assert is_template(template_source) assert count(template_source) == 3 frame = context_test5.find_instances(SkyCoordinateFrame)[0] filters = context_test5.find_instances(PhotometryFilter) h_filter = filters[0] j_filter = filters[1] k_filter = filters[2] sources = unroll(template_source) assert len(sources) == 3 source = sources[0] assert source.name == '08120809-0206132' assert source.position.longitude == template_source.position.longitude[0] assert source.position.latitude == template_source.position.latitude[0] assert source.position.frame is frame h_mag = source.luminosity[0] assert h_mag.type == 'magnitude' assert h_mag.filter is h_filter assert h_mag.value == template_source.luminosity[0].value[0] assert h_mag.error == template_source.luminosity[0].error[0] j_mag = source.luminosity[1] assert j_mag.type == 'magnitude' assert j_mag.filter is j_filter assert j_mag.value == template_source.luminosity[1].value[0] assert j_mag.error == template_source.luminosity[1].error[0] k_mag = source.luminosity[2] assert k_mag.type == 'magnitude' assert k_mag.filter is k_filter assert k_mag.value == template_source.luminosity[2].value[0] assert k_mag.error == template_source.luminosity[2].error[0] source = sources[1] assert source.name == '08115683-0205428' assert source.position.longitude == template_source.position.longitude[1] assert source.position.latitude == template_source.position.latitude[1] assert source.position.frame is frame h_mag = source.luminosity[0] assert h_mag.type == 'magnitude' assert h_mag.filter is h_filter assert h_mag.value == template_source.luminosity[0].value[1] assert h_mag.error == template_source.luminosity[0].error[1] j_mag = source.luminosity[1] assert j_mag.type == 'magnitude' assert j_mag.filter is j_filter assert j_mag.value == template_source.luminosity[1].value[1] assert j_mag.error == template_source.luminosity[1].error[1] k_mag = source.luminosity[2] assert k_mag.type == 'magnitude' assert k_mag.filter is k_filter assert k_mag.value == template_source.luminosity[2].value[1] assert k_mag.error == template_source.luminosity[2].error[1] source = sources[2] assert source.name == '08115826-0205336' assert source.position.longitude == template_source.position.longitude[2] assert source.position.latitude == template_source.position.latitude[2] assert source.position.frame is frame h_mag = source.luminosity[0] assert h_mag.type == 'magnitude' assert h_mag.filter is h_filter assert h_mag.value == template_source.luminosity[0].value[2] assert h_mag.error == template_source.luminosity[0].error[2] j_mag = source.luminosity[1] assert j_mag.type == 'magnitude' assert j_mag.filter is j_filter assert j_mag.value == template_source.luminosity[1].value[2] assert j_mag.error == template_source.luminosity[1].error[2] k_mag = source.luminosity[2] assert k_mag.type == 'magnitude' assert k_mag.filter is k_filter assert k_mag.value == template_source.luminosity[2].value[2] assert k_mag.error == template_source.luminosity[2].error[2]