def test_configure(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) generator = CompoundGenerator([ys, xs], [], []) generator.prepare() completed_steps = 2 steps_to_do = 4 self.o.done_when_reaches = 30 self.o.on_configure(self.context, completed_steps, steps_to_do, generator) expected_xml = """<?xml version="1.0" ?> <pos_layout> <dimensions> <dimension name="d0" /> <dimension name="d1" /> </dimensions> <positions> <position d0="0" d1="2" /> <position d0="1" d1="2" /> <position d0="1" d1="1" /> <position d0="1" d1="0" /> </positions> </pos_layout>""".replace("\n", "") # Wait for the start_future so the post gets through to our child # even on non-cothread systems self.o.start_future.result(timeout=1) assert self.child.handled_requests.mock_calls == [ call.post("delete"), call.put("enableCallbacks", True), call.put("idStart", 31), call.put("xml", expected_xml), call.post("start"), ] assert self.o.done_when_reaches == 34
def test_configure_with_hardware_start_trigger_succeeds(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) generator = CompoundGenerator([ys, xs], [], [], 0.1) generator.prepare() completed_steps = 0 steps_to_do = 6 # We are not gated self.o.gated_trigger = False # We want to be armed and in a hardware trigger mode self.set_attributes(self.child, acquiring=True, triggerMode="Rising Edge") self.o.on_configure(self.context, completed_steps, steps_to_do, {}, generator, fileDir="/tmp") assert self.child.handled_requests.mock_calls == [ call.put("arrayCallbacks", True), call.put("arrayCounter", 0), call.put("imageMode", "Multiple"), call.put("numImages", 6), call.put("postCount", 999), call.post("start"), call.when_value_matches("acquiring", True, None), ]
def test_long_steps_lookup(self): self.do_configure(axes_to_scan=["x"], completed_steps=3, x_pos=0.62506, duration=14.0) assert self.child.handled_requests.mock_calls[-6:] == [ call.put('pointsToBuild', 14), call.put( 'positionsA', pytest.approx([ 0.625, 0.5625, 0.5, 0.4375, 0.375, 0.3125, 0.25, 0.1875, 0.125, 0.0625, 0.0, -0.0625, -0.125, -0.12506377551020409 ])), call.put('timeArray', [ 7143, 3500000, 3500000, 3500000, 3500000, 3500000, 3500000, 3500000, 3500000, 3500000, 3500000, 3500000, 3500000, 7143 ]), call.put('userPrograms', [3, 0, 4, 0, 3, 0, 4, 0, 3, 0, 4, 0, 2, 8]), call.put('velocityMode', [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3]), call.post('buildProfile') ] assert self.o.completed_steps_lookup == ([ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6 ])
def test_configure_windows(self): self.o = StatsPluginPart(name="m", mri="BLOCK:STAT", runs_on_windows=True) self.context.set_notify_dispatch_request( self.o.notify_dispatch_request) self.process.start() fileDir = "/tmp" part_info = {"sth": [FilePathTranslatorInfo("X", "/tmp", "")]} infos = self.o.on_configure(self.context, part_info, fileDir) assert infos is None expected_filename_unix = "/tmp/BLOCK_STAT-attributes.xml" expected_filename_windows = "X:\\BLOCK_STAT-attributes.xml" assert self.child.handled_requests.mock_calls == [ call.put("computeStatistics", True), call.put("enableCallbacks", True), call.put("attributesFile", expected_filename_windows), ] expected_xml = ( '<?xml version="1.0" ?>\n' "<Attributes>\n" '<Attribute addr="0" datatype="DOUBLE" description="Sum of the array" ' 'name="STATS_TOTAL" source="TOTAL" type="PARAM" />\n' "</Attributes>") with open(expected_filename_unix) as f: actual_xml = f.read().replace(">", ">\n") actual_tree = ElementTree.XML(actual_xml) expected_tree = ElementTree.XML(expected_xml) assert ElementTree.dump(actual_tree) == ElementTree.dump(expected_tree)
def test_configure(self): params = MagicMock() xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) params.generator = CompoundGenerator([ys, xs], [], []) params.generator.prepare() completed_steps = 2 steps_to_do = 4 part_info = {"anything": [UniqueIdInfo(30)]} self.o.configure(self.context, completed_steps, steps_to_do, part_info, params) expected_xml = """<?xml version="1.0" ?> <pos_layout> <dimensions> <dimension name="d0" /> <dimension name="d1" /> <dimension name="FilePluginClose" /> </dimensions> <positions> <position FilePluginClose="0" d0="0" d1="2" /> <position FilePluginClose="0" d0="1" d1="2" /> <position FilePluginClose="0" d0="1" d1="1" /> <position FilePluginClose="1" d0="1" d1="0" /> </positions> </pos_layout>""".replace("\n", "") # Need to wait for the spawned mock start call to run self.o.start_future.result() assert self.child.handled_requests.mock_calls == [ call.post('delete'), call.put('enableCallbacks', True), call.put('idStart', 31), call.put('xml', expected_xml), call.post('start') ]
def test_configure(self): tmp_dir = mkdtemp() + os.path.sep vds_file = "odin2" start_time = datetime.now() self.o.on_configure( self.context, self.completed_steps, self.steps_to_do, generator=self.generator, fileDir=tmp_dir, formatName=vds_file, ) assert self.child.handled_requests.mock_calls == [ call.put("fileName", "odin2_raw_data"), call.put("filePath", tmp_dir), call.put("numCapture", self.steps_to_do), call.post("start"), call.when_value_matches("numCaptured", greater_than_zero, None), ] print(self.child.handled_requests.mock_calls) print("OdinWriter configure {} points took {} secs".format( self.steps_to_do, datetime.now() - start_time)) rmtree(tmp_dir)
def test_post_run_armed_with_hardware_trigger_and_breakpoints(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 100, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 5) generator = CompoundGenerator([ys, xs], [], [], 0.1) generator.prepare() info = ExposureDeadtimeInfo(0.01, 1000, 0.0) part_info = dict(anyname=[info]) breakpoints = [100, 400] # This would have been done by initial configure self.o.is_hardware_triggered = True self.o.done_when_reaches = 100 self.o.on_post_run_armed(self.context, 100, 400, part_info, generator, breakpoints) assert self.child.handled_requests.mock_calls == [ call.put("arrayCallbacks", True), call.put("arrayCounter", 100), call.put("imageMode", "Multiple"), call.put("numImages", 400), call.put("acquirePeriod", 0.1 - 0.0001), call.post("start"), call.when_value_matches("acquiring", True, None), ] assert self.o.done_when_reaches == 500
def test_configure_software_trigger_succeeds(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) duration = 0.1 generator = CompoundGenerator([ys, xs], [], [], duration) generator.prepare() completed_steps = 0 steps_to_do = 6 # We wait to be armed, so set this here self.set_attributes(self.child, acquiring=True, triggerOffCondition="Always On") self.o.on_configure(self.context, completed_steps, steps_to_do, {}, generator, fileDir="/tmp") # We expect only these calls (no arming in software trigger mode) assert self.child.handled_requests.mock_calls == [ call.put("arrayCallbacks", True), call.put("arrayCounter", 0), call.put("imageMode", "Multiple"), call.put("numImages", 6), call.put("postCount", 1000), ]
def test_configure(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 3000, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2000) generator = CompoundGenerator([ys, xs], [], [], 0.1) generator.prepare() completed_steps = 0 steps_to_do = 2000 * 3000 # We wait to be armed, so set this here self.set_attributes(self.child, acquiring=True, fanStateReady=1) self.o.on_configure( self.context, completed_steps, steps_to_do, {}, generator=generator, fileDir="/tmp", ) assert self.child.handled_requests.mock_calls == [ call.put("arrayCallbacks", True), call.put("arrayCounter", 0), call.put("imageMode", "Multiple"), call.put("numImages", 6000000), call.put("numImagesPerSeries", 1), call.post("start"), ]
def test_run(self): self.prepare_half_run() task = MagicMock() update_completed_steps = MagicMock() self.o.run(task, update_completed_steps) self.assertEqual(task.mock_calls, [ call.put(self.child['counter'], 0), call.sleep(AlmostFloat(1.0, delta=0.05)), call.put(self.child['counter'], 2), call.sleep(AlmostFloat(2.0, delta=0.1))])
def test_run(self): self.prepare_half_run() task = MagicMock() update_completed_steps = MagicMock() self.o.run(task, update_completed_steps) self.assertEqual(task.mock_calls, [ call.put(self.child['counter'], 0), call.sleep(AlmostFloat(1.0, delta=0.05)), call.put(self.child['counter'], 2), call.sleep(AlmostFloat(2.0, delta=0.1)) ])
def test_long_move(self): self.do_configure(axes_to_scan=["x"], x_pos=-10.1375) assert self.child.handled_requests.mock_calls[13:18] == [ call.put('pointsToBuild', 5), call.put( 'positionsA', pytest.approx([-8.2575, -6.1775, -4.0975, -2.0175, -0.1375])), call.put('timeArray', [2080000, 2080000, 2080000, 2080000, 2080000]), call.put('userPrograms', [8, 8, 8, 8, 8]), call.put('velocityMode', [0, 0, 0, 0, 2]) ]
def test_configure(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 3000, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2000) generator = CompoundGenerator([ys, xs], [], [], 0.1) generator.prepare() completed_steps = 0 steps_to_do = 2000 * 3000 # We wait to be armed, so set this here self.set_attributes(self.child, acquiring=True) # This is what the detector does when exposure and acquirePeriod are # both set to 0.1 self.set_attributes(self.child, exposure=0.1, acquirePeriod=0.105) self.o.configure(self.context, completed_steps, steps_to_do, {}, generator=generator) assert self.child.handled_requests.mock_calls == [ call.put('exposure', 0.1), call.put('acquirePeriod', 0.1), call.put('arrayCallbacks', True), call.put('arrayCounter', 0), # duration - readout - fudge_factor - crystal offset call.put('exposure', pytest.approx(0.1 - 0.005 - 0.0014 - 5e-6)), call.put('imageMode', 'Multiple'), call.put('numImages', 6000000), call.put('acquirePeriod', 0.1 - 5e-6), call.post('start') ]
def test_configure(self): self.o.configure(self.context, self.completed_steps, self.steps_to_do, {}, generator=self.generator, fileDir='/tmp', fileName='odin.hdf') assert self.child.handled_requests.mock_calls == [ call.put('fileName', 'odin.hdf'), call.put('filePath', '/tmp/'), call.put('numCapture', self.steps_to_do), call.post('start') ] print(self.child.handled_requests.mock_calls)
def test_move(self): self.mock_when_value_matches(self.child) # Move time is converted into milliseconds move_time = 2.3 expected_move_time = move_time * 1000.0 self.b.moveCS1(a=32, c=19.1, moveTime=move_time) assert self.child.handled_requests.mock_calls == [ call.put("deferMoves", True), call.put("csMoveTime", expected_move_time), call.put("demandA", 32), call.put("demandC", 19.1), call.when_value_matches("demandA", 32, None), call.when_value_matches("demandC", 19.1, None), call.put("deferMoves", False), ]
def resolutions_and_use_call(self, useB=True): return [ call.put('useA', True), call.put('useB', useB), call.put('useC', False), call.put('useU', False), call.put('useV', False), call.put('useW', False), call.put('useX', False), call.put('useY', False), call.put('useZ', False) ]
def test_setup_detector_overwrites_exposure_in_kwargs_no_frame_transfer_mode( self, super_setup_detector_mock): # Mock our arguments completed_steps = Mock(name="completed_steps_mock") steps_to_do = Mock(name="steps_to_do_mock") duration = 0.1 actual_exposure = 0.09 actual_period = 0.098 part_info = Mock(name="part_info") # Mock the adjusted_exposure_time_and_acquire_period_method adjusted_acquisition_mock = Mock(name="adjusted_acquisition_mock") adjusted_acquisition_mock.return_value = (actual_exposure, actual_period) self.andor_driver_part.get_adjusted_exposure_time_and_acquire_period = ( adjusted_acquisition_mock) self.andor_driver_part.setup_detector( self.context, completed_steps, steps_to_do, steps_to_do, duration, part_info, exposure=0.05, ) # Check method calls assert self.child.handled_requests.mock_calls == [ call.put("exposure", duration), call.put("acquirePeriod", duration), call.put("acquirePeriod", actual_period), ] super_setup_detector_mock.assert_called_once_with( self.context, completed_steps, steps_to_do, steps_to_do, duration, part_info, initial_configure=True, exposure=actual_exposure, ) # Check exposure time self.assertEqual(actual_exposure, self.andor_driver_part.exposure.value)
def test_setup_detector_overwrites_exposure_in_kwargs_frame_transfer_mode( self, super_setup_detector_mock): # Mock our arguments completed_steps = Mock(name="completed_steps_mock") steps_to_do = Mock(name="steps_to_do_mock") duration = 1.0 actual_exposure = 0.0 accumulate_period = 0.01 part_info = Mock(name="part_info") # Turn on frame transfer mode and set accumulate period self.set_attributes( self.child, andorFrameTransferMode=True, andorAccumulatePeriod=accumulate_period, ) self.andor_driver_part.setup_detector( self.context, completed_steps, steps_to_do, steps_to_do, duration, part_info, exposure=0.25, ) # Check method calls assert self.child.handled_requests.mock_calls == [ call.put("exposure", actual_exposure), call.put("acquirePeriod", actual_exposure), call.put("acquirePeriod", accumulate_period), ] super_setup_detector_mock.assert_called_once_with( self.context, completed_steps, steps_to_do, steps_to_do, duration, part_info, initial_configure=True, exposure=actual_exposure, ) # Check exposure time self.assertEqual(actual_exposure, self.andor_driver_part.exposure.value)
def resolutions_and_use_call(self, useB=True): return [ call.put("useA", True), call.put("useB", useB), call.put("useC", False), call.put("useU", False), call.put("useV", False), call.put("useW", False), call.put("useX", False), call.put("useY", False), call.put("useZ", False), ]
def test_upload_files_dir(self, mock_connected_ssh): """We can upload directories of files""" ssh = mock.MagicMock(name='ssh') ftp = mock.MagicMock(name='ftp') channel = mock.MagicMock(name='channel') ssh.exec_command.return_value = channel, channel, channel mock_connected_ssh.return_value = (ssh, ftp) remote = common.remote_ssh_host.RemoteSSHHost(hostname=None, username=None, pem_file=None) remote._perform_exec = mock.MagicMock(name='_perform_exec') remote._perform_exec.return_value = 0 local_path = os.path.abspath(os.path.dirname(__file__)) remote_path = '/foo/bar' remote.upload_file(local_path, remote_path) ssh.exec_command.assert_has_calls([ call('mkdir -p /foo/bar', get_pty=False), call('tar xf /foo/bar.tar -C /foo/bar', get_pty=False), call('rm /foo/bar.tar', get_pty=False) ], any_order=False) ftp.assert_has_calls([call.put(ANY, '/foo/bar.tar'), call.chmod('/foo/bar.tar', ANY)], any_order=False)
def test_configure(self): fileDir = "/tmp" infos = self.o.configure(self.context, fileDir) assert infos is None expected_filename = "/tmp/BLOCK-STAT-attributes.xml" assert self.child.handled_requests.mock_calls == [ call.put('computeStatistics', True), call.put('enableCallbacks', True), call.put('attributesFile', expected_filename)] expected_xml = """<?xml version="1.0" ?> <Attributes> <Attribute addr="0" datatype="DOUBLE" description="Sum of the array" name="STATS_TOTAL" source="TOTAL" type="PARAM" /> </Attributes>""" with open(expected_filename) as f: actual_xml = f.read().replace(">", ">\n") assert actual_xml.splitlines() == expected_xml.splitlines()
def test_upload_files_dir(self, mock_connected_ssh): """We can upload directories of files""" ssh = mock.MagicMock(name="ssh") ftp = mock.MagicMock(name="ftp") channel = mock.MagicMock(name="channel") ssh.exec_command.return_value = channel, channel, channel mock_connected_ssh.return_value = (ssh, ftp) remote = remote_ssh_host.RemoteSSHHost(hostname=None, username=None, pem_file=None) remote._perform_exec = mock.MagicMock(name="_perform_exec") remote._perform_exec.return_value = 0 local_path = whereami.dsi_repo_path("testscripts") remote_path = "/foo/bar" remote.upload_file(local_path, remote_path) ssh.exec_command.assert_has_calls( [ call("mkdir -p /foo/bar", get_pty=False), call("tar xf /foo/bar.tar -C /foo/bar", get_pty=False), call("rm /foo/bar.tar", get_pty=False), ], any_order=False, ) ftp.assert_has_calls( [call.put(ANY, "/foo/bar.tar"), call.chmod("/foo/bar.tar", ANY)], any_order=False)
def test_bs(self): b = self.context.block_view("SCAN") generator = CompoundGenerator([LineGenerator("x", "mm", 0, 1, 10)], [], [], 0.1) b.configure(generator) self.o.on_configure(self.context) assert self.child.handled_requests.mock_calls == [call.put("demand", 50)]
def test_configure_from_disarmed_state(self): self._do_configure() assert self.child.handled_requests.mock_calls == [ call.put("imageMode", "Continuous"), call.post("start"), call.when_value_matches("acquiring", True, None), ]
def test_configure(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) generator = CompoundGenerator([ys, xs], [], [], 0.1) generator.prepare() completed_steps = 0 steps_to_do = 6 # We wait to be armed, so set this here self.set_attributes(self.child, acquiring=True) self.o.configure( self.context, completed_steps, steps_to_do, {}, generator) assert self.child.handled_requests.mock_calls == [ call.put('arrayCallbacks', True), call.put('arrayCounter', 0), call.put('imageMode', 'Multiple'), call.put('numImages', 6), call.put('postCount', 999), call.post('start')]
def test_seek(self): completed_steps = 4 steps_to_do = 3 part_infos = {"anything": [UniqueIdInfo(10)]} self.o.seek(self.context, completed_steps, steps_to_do, part_infos) assert self.child.handled_requests.mock_calls == [ call.put('arrayCounter', 0) ] assert self.o.done_when_reaches == 13
def test_seek(self): self.o.done_when_reaches = 10 completed_steps = 4 steps_to_do = 3 self.o.seek(self.context, completed_steps, steps_to_do) assert self.child.handled_requests.mock_calls == [ call.put('arrayCounter', 0) ] assert self.o.done_when_reaches == 13
def test_configure(self): params = MagicMock() xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) params.generator = CompoundGenerator([ys, xs], [], [], 0.1) params.generator.prepare() completed_steps = 0 steps_to_do = 6 part_info = ANY self.o.configure(self.context, completed_steps, steps_to_do, part_info, params) assert self.child.handled_requests.mock_calls == [ call.put('arrayCallbacks', True), call.put('arrayCounter', 0), call.put('imageMode', 'Multiple'), call.put('numImages', 6), call.put('exposure', 0.1 - 7e-5) ]
def test_configure_with_extra_attributes(self): xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) generator = CompoundGenerator([ys, xs], [], [], 0.1) generator.prepare() completed_steps = 0 steps_to_do = 6 expected_xml_filename = "/tmp/mri-attributes.xml" self.set_attributes(self.child, triggerMode="Internal") extra_attributes = ExtraAttributesTable( name=["test1", "test2", "test3"], sourceId=["PV1", "PV2", "PARAM1"], sourceType=[SourceType.PV, SourceType.PV, SourceType.PARAM], description=[ "a test pv", "another test PV", "a param, for testing" ], dataType=[DataType.DBRNATIVE, DataType.DOUBLE, DataType.DOUBLE], datasetType=[ AttributeDatasetType.MONITOR, AttributeDatasetType.DETECTOR, AttributeDatasetType.POSITION, ], ) self.o.extra_attributes.set_value(extra_attributes) self.o.on_configure(self.context, completed_steps, steps_to_do, {}, generator, fileDir="/tmp") assert self.child.handled_requests.mock_calls == [ call.put("arrayCallbacks", True), call.put("arrayCounter", 0), call.put("imageMode", "Multiple"), call.put("numImages", 6), call.put("attributesFile", expected_xml_filename), ] assert not self.o.is_hardware_triggered with open(expected_xml_filename) as f: actual_xml = f.read().replace(">", ">\n") actual_tree = ElementTree.XML(actual_xml) expected_tree = ElementTree.XML(expected_xml) assert ElementTree.dump(actual_tree) == ElementTree.dump(expected_tree)
def test_add_one(self): from StringIO import StringIO from datetime import datetime now = datetime.utcnow() file_reader = StringIO('123') objid = self.db.add_one(file_reader, now, test=1) assert [call.put(file_reader)] == self.db.grid.mock_calls assert [call.insert({'test': 1, 'raw_data': self.db.grid.put(), 'created': now})] == self.db.db.docs.mock_calls assert self.db.db.docs.insert() == objid
def test_configure_on_windows(self): """Test the network mount drive on Windows""" xs = LineGenerator("x", "mm", 0.0, 0.5, 3, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) generator = CompoundGenerator([ys, xs], [], [], 0.1) generator.prepare() completed_steps = 0 steps_to_do = 6 expected_xml_filename = "\\\\dc\\tmp\\WINDOWS_DETECTOR-attributes.xml" self.set_attributes(self.child, triggerMode="Internal") extra_attributes = ExtraAttributesTable( name=["test1", "test2", "test3"], sourceId=["PV1", "PV2", "PARAM1"], sourceType=[SourceType.PV, SourceType.PV, SourceType.PARAM], description=[ "a test pv", "another test PV", "a param, for testing" ], dataType=[DataType.DBRNATIVE, DataType.DOUBLE, DataType.DOUBLE], datasetType=[ AttributeDatasetType.MONITOR, AttributeDatasetType.DETECTOR, AttributeDatasetType.POSITION, ], ) self.o.extra_attributes.set_value(extra_attributes) win_info = FilePathTranslatorInfo("", "/tmp", "//dc") part_info = dict(anyname=[win_info]) self.o.on_configure( self.context, completed_steps, steps_to_do, part_info, generator, fileDir="/tmp", ) assert self.child.handled_requests.mock_calls == [ call.put("arrayCallbacks", True), call.put("arrayCounter", 0), call.put("imageMode", "Multiple"), call.put("numImages", 6), call.put("attributesFile", expected_xml_filename), ] assert not self.o.is_hardware_triggered
def test_on_seek(self): # Set up the generator which would have been done in original configure xs = LineGenerator("x", "mm", 0.0, 0.5, 5, alternate=True) ys = LineGenerator("y", "mm", 0.0, 0.1, 3) generator = CompoundGenerator([ys, xs], [], [], duration=1.0) generator.prepare() self.o.generator = generator # Now we can call on_seek completed_steps = 10 steps_to_do = 5 self.o.done_when_reaches = 10 self.o.on_seek(self.context, completed_steps, steps_to_do) expected_xml = """<?xml version="1.0" ?> <pos_layout> <dimensions> <dimension name="d0" /> <dimension name="d1" /> </dimensions> <positions> <position d0="2" d1="0" /> <position d0="2" d1="1" /> <position d0="2" d1="2" /> <position d0="2" d1="3" /> <position d0="2" d1="4" /> </positions> </pos_layout>""".replace( "\n", "" ) self.o.start_future.result(timeout=1) assert self.child.handled_requests.mock_calls == [ call.post("delete"), call.put("arrayCounter", 10), call.put("enableCallbacks", True), call.put("idStart", 11), call.put("xml", expected_xml), call.post("start"), ] assert self.o.done_when_reaches == 15
def test_read_and_send_on_message_parses_message_and_send_passing_to_queue(mock_receive): message = '{"type":"builds","error":"","failing":[],"acknowledged":[],"healthy":[{"name":"Build","building":false,"user":"","url":"http://localhost:8000/job/Failing%20Build/","number_of_failures":0,"failing_since":0}]}' mock_receive.return_value = (message, 'b') mock_conn = Mock(spec=socket.socket) mock_queue = Mock(spec=Queue) client_thread = ClientThread(None, None, mock_queue) remainder = client_thread.read_and_send_on_message(mock_conn, '') assert remainder == 'b' mock_queue.assert_has_calls([ call.put(BuildStatusUpdate(BuildStatus.Passing)) ]) mock_receive.assert_has_calls([ call(mock_conn, '') ])