@@ -632,8 +632,9 @@ def test_daily_observation_validation_ghi(mocker, make_observation,
632632 DESCRIPTION_MASK_MAPPING ['UNEVEN FREQUENCY' ] |
633633 LATEST_VERSION_FLAG
634634 ]
635- assert post_mock .called_once
636- assert_frame_equal (post_mock .call_args [0 ][1 ], out )
635+ assert post_mock .called
636+ posted_df = pd .concat ([cal [0 ][1 ] for cal in post_mock .call_args_list ])
637+ assert_frame_equal (posted_df , out )
637638
638639
639640def test_daily_observation_validation_ghi_zeros (mocker , make_observation ,
@@ -677,8 +678,9 @@ def test_daily_observation_validation_ghi_zeros(mocker, make_observation,
677678 base | DESCRIPTION_MASK_MAPPING ['NIGHTTIME' ] |
678679 DESCRIPTION_MASK_MAPPING ['UNEVEN FREQUENCY' ]
679680 ]
680- assert post_mock .called_once
681- assert_frame_equal (post_mock .call_args [0 ][1 ], out )
681+ assert post_mock .called
682+ posted_df = pd .concat ([cal [0 ][1 ] for cal in post_mock .call_args_list ])
683+ assert_frame_equal (posted_df , out )
682684
683685
684686def test_validate_daily_dc_power (mocker , make_observation , daily_index ):
@@ -767,8 +769,9 @@ def test_daily_observation_validation_dc_power(mocker, make_observation,
767769 DESCRIPTION_MASK_MAPPING ['NIGHTTIME' ] |
768770 LATEST_VERSION_FLAG
769771 ]
770- assert post_mock .called_once
771- assert_frame_equal (post_mock .call_args [0 ][1 ], out )
772+ assert post_mock .called
773+ posted_df = pd .concat ([cal [0 ][1 ] for cal in post_mock .call_args_list ])
774+ assert_frame_equal (posted_df , out )
772775
773776
774777def test_validate_daily_ac_power (mocker , make_observation , daily_index ):
@@ -863,8 +866,9 @@ def test_daily_observation_validation_ac_power(mocker, make_observation,
863866 DESCRIPTION_MASK_MAPPING ['NIGHTTIME' ] |
864867 LATEST_VERSION_FLAG
865868 ]
866- assert post_mock .called_once
867- assert_frame_equal (post_mock .call_args [0 ][1 ], out )
869+ assert post_mock .called
870+ posted_df = pd .concat ([cal [0 ][1 ] for cal in post_mock .call_args_list ])
871+ assert_frame_equal (posted_df , out )
868872
869873
870874@pytest .mark .parametrize ('var' , ['air_temperature' , 'wind_speed' , 'dni' , 'dhi' ,
@@ -885,13 +889,14 @@ def test_daily_observation_validation_other(var, mocker, make_observation,
885889 return_value = data )
886890 post_mock = mocker .patch (
887891 'solarforecastarbiter.io.api.APISession.post_observation_values' )
888- validate_mock = mocker .MagicMock ()
892+ validated = pd .Series (2 , index = daily_index )
893+ validate_mock = mocker .MagicMock (return_value = validated )
889894 mocker .patch .dict (
890895 'solarforecastarbiter.validation.tasks.IMMEDIATE_VALIDATION_FUNCS' ,
891896 {var : validate_mock })
892897 tasks .daily_single_observation_validation (
893898 '' , obs .observation_id , data .index [0 ], data .index [- 1 ])
894- assert post_mock .called_once
899+ assert post_mock .called
895900 assert validate_mock .called
896901
897902
@@ -914,13 +919,14 @@ def test_daily_observation_validation_many(mocker, make_observation,
914919 return_value = data )
915920 post_mock = mocker .patch (
916921 'solarforecastarbiter.io.api.APISession.post_observation_values' )
917- validate_mock = mocker .MagicMock ()
922+ validated = pd .Series (2 , index = daily_index )
923+ validate_mock = mocker .MagicMock (return_value = validated )
918924 mocker .patch .dict (
919925 'solarforecastarbiter.validation.tasks.IMMEDIATE_VALIDATION_FUNCS' ,
920926 {'dhi' : validate_mock , 'dni' : validate_mock })
921927 tasks .daily_observation_validation (
922928 '' , data .index [0 ], data .index [- 1 ])
923- assert post_mock .called_once
929+ assert post_mock .called
924930 assert validate_mock .call_count == 2
925931
926932
@@ -967,3 +973,51 @@ def test_daily_observation_validation_not_enough(mocker, make_observation):
967973 '' , data .index [0 ], data .index [- 1 ])
968974 assert out is None
969975 assert log .called
976+
977+
978+ def test__group_continuous_week_post (mocker , make_observation ):
979+ split_dfs = [
980+ pd .DataFrame ([(0 , LATEST_VERSION_FLAG )],
981+ columns = ['value' , 'quality_flag' ],
982+ index = pd .date_range (
983+ start = '2020-05-03T00:00' ,
984+ end = '2020-05-03T23:59' ,
985+ tz = 'UTC' ,
986+ freq = '1h' )),
987+ # new week split
988+ pd .DataFrame ([(0 , LATEST_VERSION_FLAG )],
989+ columns = ['value' , 'quality_flag' ],
990+ index = pd .date_range (
991+ start = '2020-05-04T00:00' ,
992+ end = '2020-05-04T11:59' ,
993+ tz = 'UTC' ,
994+ freq = '1h' )),
995+ # missing 12
996+ pd .DataFrame (
997+ [(0 , LATEST_VERSION_FLAG | DESCRIPTION_MASK_MAPPING ['UNEVEN FREQUENCY' ])] + # NOQA
998+ [(1 , LATEST_VERSION_FLAG )] * 7 ,
999+ columns = ['value' , 'quality_flag' ],
1000+ index = pd .date_range (
1001+ start = '2020-05-04T13:00' ,
1002+ end = '2020-05-04T20:00' ,
1003+ tz = 'UTC' ,
1004+ freq = '1h' )),
1005+ # missing a week+
1006+ pd .DataFrame (
1007+ [(9 , LATEST_VERSION_FLAG | DESCRIPTION_MASK_MAPPING ['UNEVEN FREQUENCY' ])] + # NOQA
1008+ [(3 , LATEST_VERSION_FLAG )] * 7 ,
1009+ columns = ['value' , 'quality_flag' ],
1010+ index = pd .date_range (
1011+ start = '2020-05-13T09:00' ,
1012+ end = '2020-05-13T16:59' ,
1013+ tz = 'UTC' ,
1014+ freq = '1h' )),
1015+ ]
1016+ ov = pd .concat (split_dfs , axis = 0 )
1017+ obs = make_observation ('ghi' )
1018+ session = mocker .MagicMock ()
1019+ tasks ._group_continuous_week_post (session , obs , ov )
1020+ call_list = session .post_observation_values .call_args_list
1021+ assert len (call_list ) == 4
1022+ for i , cal in enumerate (call_list ):
1023+ assert_frame_equal (split_dfs [i ], cal [0 ][1 ])
0 commit comments