@@ -111,15 +111,19 @@ def test_set_filter_init_not_finished(self):
111111 self .filter_wheel .init_finished = True
112112
113113 def test_set_filter_init_finished (self ):
114- self .mock_device_connection .reset_mock ()
115- self .filter_wheel .init_finished = True
116- for i in range (6 ):
117- self .filter_wheel .set_filter (
118- list (self .filter_wheel .filter_dictionary .keys ())[i ],
119- wait_until_done = True ,
120- )
121- self .mock_device_connection .write .assert_called ()
122- self .mock_device_connection .read .assert_not_called ()
114+ for wait_flag , read_num in [(True , 2 ), (False , 1 )]:
115+ self .mock_device_connection .reset_mock ()
116+ self .filter_wheel .init_finished = True
117+ read_count = 0
118+ for i in range (6 ):
119+ self .filter_wheel .set_filter (
120+ list (self .filter_wheel .filter_dictionary .keys ())[i ],
121+ wait_until_done = wait_flag ,
122+ )
123+ self .mock_device_connection .write .assert_called ()
124+ self .mock_device_connection .read .assert_called ()
125+ read_count += read_num
126+ assert self .mock_device_connection .read .call_count == read_count
123127
124128 def test_set_filter_without_waiting (self ):
125129 self .mock_device_connection .reset_mock ()
@@ -138,9 +142,14 @@ def test_set_filter_without_waiting(self):
138142
139143 def test_read_wrong_number_bytes_returned (self ):
140144 self .mock_device_connection .reset_mock ()
145+ # fewer response bytes than expected
141146 with self .assertRaises (UserWarning ):
142- self .mock_device_connection .inWaiting .return_value = b"0x"
147+ # in_waiting() returns an integer.
148+ self .mock_device_connection .inWaiting .return_value = 1
143149 self .filter_wheel .read (num_bytes = 10 )
150+ # more response bytes than expected
151+ self .mock_device_connection .inWaiting .return_value = 12
152+ self .filter_wheel .read (num_bytes = 10 )
144153
145154 def test_read_correct_number_bytes_returned (self ):
146155 # Mocked device connection expected to return 2 bytes
0 commit comments