|
1 | | -from visual_behavior.translator import schemas |
| 1 | + |
| 2 | +from visual_behavior.schemas.core import MetadataSchema, StimulusSchema, \ |
| 3 | + RunningSchema, LickSchema, RewardSchema, TrialSchema |
| 4 | +from visual_behavior.schemas.extended_trials import ExtendedTrialSchema |
| 5 | +from visual_behavior.translator import foraging2, foraging |
| 6 | +from visual_behavior.translator.core import create_extended_dataframe |
2 | 7 |
|
3 | 8 |
|
4 | 9 | """test the schemas vs the outputs here |
5 | 10 | """ |
| 11 | + |
| 12 | +def _test_core_data_schemas(core_data): |
| 13 | + |
| 14 | + # metadata |
| 15 | + |
| 16 | + # core dataframes |
| 17 | + dataframe_schemas = ( |
| 18 | + (StimulusSchema, core_data['visual_stimuli']), |
| 19 | + (RunningSchema, core_data['running']), |
| 20 | + (LickSchema, core_data['licks']), |
| 21 | + (RewardSchema, core_data['rewards']), |
| 22 | + (TrialSchema, core_data['trials']), |
| 23 | + ) |
| 24 | + |
| 25 | + for Schema, data in dataframe_schemas: |
| 26 | + errors = Schema(many=True).validate(data.to_dict(orient='records')) |
| 27 | + |
| 28 | + for row, row_errors in errors.items(): |
| 29 | + assert len(row_errors)==0, (Schema, data, row_errors) |
| 30 | + |
| 31 | + extended_trials = create_extended_dataframe( |
| 32 | + trials=core_data['trials'], |
| 33 | + metadata=core_data['metadata'], |
| 34 | + licks=core_data['licks'], |
| 35 | + time=core_data['time'], |
| 36 | + ) |
| 37 | + |
| 38 | + errors = ExtendedTrialSchema(many=True).validate( |
| 39 | + extended_trials.to_dict(orient='records') |
| 40 | + ) |
| 41 | + |
| 42 | + for row, row_errors in errors.items(): |
| 43 | + assert len(row_errors)==0, row_errors |
| 44 | + |
| 45 | + errors = MetadataSchema().validate(core_data['metadata']) |
| 46 | + assert len(errors)==0, errors.keys() |
| 47 | + |
| 48 | + |
| 49 | +def test_foraging2_translator_schema(foraging2_data_stage4_2018_05_10): |
| 50 | + core_data = foraging2.data_to_change_detection_core( |
| 51 | + foraging2_data_stage4_2018_05_10 |
| 52 | + ) |
| 53 | + _test_core_data_schemas(core_data) |
| 54 | + |
| 55 | +def test_foraging_translator_schema(behavioral_session_output_fixture): |
| 56 | + core_data = foraging.data_to_change_detection_core( |
| 57 | + behavioral_session_output_fixture |
| 58 | + ) |
| 59 | + _test_core_data_schemas(core_data) |
0 commit comments