File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -76,18 +76,19 @@ def test_to_dataframe(self):
7676 mock_dataframe .__len__ = MagicMock (return_value = 3 )
7777 mock_dataframe .__getitem__ = MagicMock (return_value = MagicMock (__getitem__ = lambda self , key : 123 ))
7878
79- with patch ('pandas.DataFrame' ) as mock_df_class , \
80- patch ('pandas.json_normalize' ) as mock_json_normalize :
81- mock_df_class .from_dict .return_value = mock_dataframe
82- mock_json_normalize .return_value = mock_dataframe
83-
79+ # Create mock pandas module
80+ mock_pandas = MagicMock ()
81+ mock_pandas .DataFrame .from_dict .return_value = mock_dataframe
82+ mock_pandas .json_normalize .return_value = mock_dataframe
83+
84+ with patch .dict ('sys.modules' , {'pandas' : mock_pandas }):
8485 dataframe = entitylist .to_dataframe ()
8586 assert len (dataframe ) == 3
86- mock_df_class .from_dict .assert_called_once ()
87+ mock_pandas . DataFrame .from_dict .assert_called_once ()
8788
8889 dataframe = entitylist .to_dataframe (True )
8990 assert len (dataframe ) == 3
90- mock_json_normalize .assert_called_once ()
91+ mock_pandas . json_normalize .assert_called_once ()
9192 assert int (dataframe ["location.x" ][- 1 :]) == 123
9293
9394
You can’t perform that action at this time.
0 commit comments