Facing issue while writing test cases using monkey_cognite_patch.
Hi Team,
We are working on a POC , where we need to create unit test cases where we are facing different issues .For reference we are using code from Cognite Hub
Below attaching our code and output expectations . Please help with the approach to resolve this issue
Expectation from print is ts_internal_id = 3973245479016710 Actual Output -
Page 1 / 1
You chain a lot of methods here and so mocking will be a bit entangled as well. First off, you should not call the methods on the mock when setting a return value:
Secondly, you need to think about what is returned by these intermediate chained calls, i.e. you first get an asset object, then you ask for the time series connected to it. This gives you a TimeSeriesList object. On this object, you get the specific time series by using the .get method supplying an identifier etc, etc, etc.
You should probably mock these objects separately, i.e.
"value":3973245479016710,"Brazil:3W:Well-Bore-19B_target_throughput","Brazil:3W:Well-Bore-19B_target_throughput",False,{}, "Barrel",3332326574821917,False,"target volume for a oil well bore",l],8739280581150161,"2023-05-02 09:37:04.944000", "2023-05-02 09:37:04.944000"]}
Use case is in between these calls I have used is df_filtered_timefilter = df_filteredm(event_start_date <= df_filteredd"start_time"]) & (df_filtered""end_time"] <= event_end_date)]
But i am getting this error <MagicMock name='mock.assets.retrieve().subtree().events().to_pandas().__getitem__()' id='2821478081008'>
and code is breaking is between these patches
I can chain these intermediate calls as you suggested but my question is will this result a proper result which is expected with above like of code ? Will it be able to pass that step ? df_filtered_timefilter = df_filtered[(event_start_date <= df_filtered["start_time"]) & (df_filtered["end_time"] <= event_end_date)] Or will these patches will be considered as real df so that the errored line could pass through to next step.
In @erlend.vollset code above, ts_data is an actual pandas DataFrame, which allows later pandas “data wrangling” code to succeed (in the test). I suspect one of your variables named “df_*” are still a mock.
(Note that Erlend sets the return value to a TimeSeriesList. The later .get call then uses the actual get-method on the object (i.e. not some mocked method). Same goes with the .to_pandas call after that.)