@@ -94,39 +94,72 @@ def file_not_found():
9494 op .get_stream ('a' ,'b' )
9595
9696
97- @pytest .mark .parametrize (
98- "_last_output_index, _output_index_by_display_id, cell_id, display_id, expected" , [
99- # Empty dictionaries, no display_id
100- ({}, {}, "cell1" , None , 0 ),
97+ def test__compute_output_index_basic ():
98+ """
99+ Test basic output index allocation for a cell without display ID
100+ """
101+ op = OutputsManager ()
101102
102- # Empty dictionaries, with display_id
103- ({}, {}, "cell1" , "display1" , 0 ),
103+ # First output for a cell should be 0
104+ assert op ._compute_output_index ('cell1' ) == 0
105+ assert op ._compute_output_index ('cell1' ) == 1
106+ assert op ._compute_output_index ('cell1' ) == 2
107+
108+ def test__compute_output_index_with_display_id ():
109+ """
110+ Test output index allocation with display IDs
111+ """
112+ op = OutputsManager ()
104113
105- # Existing last_output_index, no display_id
106- ({"cell1" : 5 }, {}, "cell1" , None , 6 ),
107- ({"cell2" : 3 }, {}, "cell1" , None , 0 ),
114+ # First output for a cell with display ID
115+ assert op ._compute_output_index ('cell1' , 'display1' ) == 0
108116
109- # Existing output_index_by_display_id
110- ({}, { "display1" : 2 }, " cell1" , " display1" , 2 ),
117+ # Subsequent calls with same display ID should return the same index
118+ assert op . _compute_output_index ( ' cell1' , ' display1' ) == 0
111119
112- # Existing last_output_index and display_id
113- ({"cell1" : 5 }, {"display1" : 3 }, "cell1" , "display1" , 3 ),
114- ({"cell1" : 5 }, {"display1" : 3 }, "cell1" , "display2" , 6 ),
120+ # Different display ID should get a new index
121+ assert op ._compute_output_index ('cell1' , 'display2' ) == 1
122+
123+
124+ def test__compute_output_index_multiple_cells ():
125+ """
126+ Test output index allocation across multiple cells
127+ """
128+ op = OutputsManager ()
115129
116- # Multiple cells with different indices
117- ({"cell1" : 2 , "cell2" : 7 }, {}, "cell1" , None , 3 ),
118- ({"cell1" : 2 , "cell2" : 7 }, {}, "cell3" , None , 0 ),
119- ])
120- def test__determine_output_index (
121- _last_output_index ,
122- _output_index_by_display_id ,
123- cell_id ,
124- display_id ,
125- expected
126- ):
130+ assert op ._compute_output_index ('cell1' ) == 0
131+ assert op ._compute_output_index ('cell1' ) == 1
132+ assert op ._compute_output_index ('cell2' ) == 0
133+ assert op ._compute_output_index ('cell2' ) == 1
134+
135+ def test_display_id_index_retrieval ():
136+ """
137+ Test retrieving output index for a display ID
138+ """
127139 op = OutputsManager ()
128- op ._last_output_index = _last_output_index ;
129- op ._output_index_by_display_id = _output_index_by_display_id
130140
131- assert expected == op ._determine_output_index (cell_id , display_id )
141+ op ._compute_output_index ('cell1' , 'display1' )
142+
143+ assert op .get_output_index ('display1' ) == 0
144+ assert op .get_output_index ('non_existent_display' ) is None
132145
146+ def test_display_ids ():
147+ """
148+ Test tracking of display IDs for a cell
149+ """
150+ op = OutputsManager ()
151+
152+ # Allocate multiple display IDs for a cell
153+ op ._compute_output_index ('cell1' , 'display1' )
154+ op ._compute_output_index ('cell1' , 'display2' )
155+
156+ # Verify display IDs are tracked
157+ assert 'cell1' in op ._display_ids
158+ assert set (op ._display_ids ['cell1' ]) == {'display1' , 'display2' }
159+
160+ # Clear cell indices
161+ op .clear ('file1' , 'cell1' )
162+
163+ # Verify display IDs are cleared
164+ assert 'display1' not in op ._display_ids
165+ assert 'display2' not in op ._display_ids
0 commit comments