@@ -203,5 +203,59 @@ def test_name_based_update_1d_x_1d_y(self):
203203 self .assertEqual (data ["y" ], [4.0 , 5.0 , 6.0 ])
204204
205205
206+ class TestHeatmap (unittest .TestCase ):
207+ def setUp (self ):
208+ self .viz = visdom .Visdom (send = False , use_incoming_socket = False )
209+
210+ def _heatmap (self , X , ** kwargs ):
211+ sent = {}
212+
213+ def capture (msg , endpoint = "events" ):
214+ sent ["payload" ] = msg
215+ sent ["endpoint" ] = endpoint
216+ return "win1"
217+
218+ with patch .object (self .viz , "_send" , side_effect = capture ):
219+ self .viz .heatmap (X , ** kwargs )
220+ return sent
221+
222+ def test_nx_m_input (self ):
223+ X = np .array ([[1.0 , 2.0 ], [3.0 , 4.0 ], [5.0 , 6.0 ]])
224+ sent = self ._heatmap (X )
225+ self .assertEqual (sent ["payload" ]["data" ][0 ]["type" ], "heatmap" )
226+
227+ def test_x_not_2d_raises (self ):
228+ with self .assertRaises (AssertionError ):
229+ self .viz .heatmap (np .array ([1.0 , 2.0 , 3.0 ]))
230+
231+ def test_invalid_update_raises (self ):
232+ X = np .ones ((3 , 3 ))
233+ with self .assertRaises (AssertionError ):
234+ self .viz .heatmap (X , update = "badvalue" )
235+
236+ def test_colormap_defaults_to_viridis (self ):
237+ X = np .ones ((2 , 2 ))
238+ sent = self ._heatmap (X )
239+ self .assertEqual (sent ["payload" ]["opts" ]["colormap" ], "Viridis" )
240+
241+ def test_append_row_sets_update_dir (self ):
242+ X = np .ones ((2 , 2 ))
243+ sent = self ._heatmap (X , update = "appendRow" , win = "w" )
244+ self .assertEqual (sent ["payload" ]["updateDir" ], "appendRow" )
245+ self .assertTrue (sent ["payload" ]["append" ])
246+ self .assertEqual (sent ["endpoint" ], "update" )
247+
248+ def test_append_column_sets_update_dir (self ):
249+ X = np .ones ((2 , 2 ))
250+ sent = self ._heatmap (X , update = "appendColumn" , win = "w" )
251+ self .assertEqual (sent ["payload" ]["updateDir" ], "appendColumn" )
252+ self .assertTrue (sent ["payload" ]["append" ])
253+
254+ def test_replace_sets_append_false (self ):
255+ X = np .ones ((2 , 2 ))
256+ sent = self ._heatmap (X , update = "replace" , win = "w" )
257+ self .assertFalse (sent ["payload" ]["append" ])
258+
259+
206260if __name__ == "__main__" :
207261 unittest .main ()
0 commit comments