def test_run_and_flush(self):
        self.o = HDFWriterPart(name="m", mri="BLOCK:HDF5")

        def set_num_captured():
            # Sleep for 2.5 seconds to ensure 2 flushes, and then set value to finish
            cothread.Sleep(2.5)
            self.set_attributes(self.child,
                                numCapturedReadback=self.o.done_when_captured)

        self.o.done_when_captured = 5
        # Say that we're getting the first frame
        self.o.first_array_future = Future(None)
        self.o.first_array_future.set_result(None)
        self.o.start_future = Future(None)
        # Need a registrar object or we get AssertionError
        self.o.registrar = MagicMock()
        # Reduce frame timeout so we don't hang on this test for too long
        self.o.frame_timeout = 5
        # Spawn process to finish it after a few seconds
        self.process.spawn(set_num_captured)

        # Run
        self.o.on_run(self.context)

        # Check calls
        assert self.child.handled_requests.mock_calls == [
            call.post("flushNow"),
            call.post("flushNow"),
        ]
        assert self.o.registrar.report.called_once
        assert self.o.registrar.report.call_args_list[0][0][0].steps == 0
        assert self.o.registrar.report.call_args_list[1][0][0].steps == 5
示例#2
0
    def test_run_and_flush(self):
        self.o = HDFWriterPart(name="m", mri="BLOCK:HDF5")

        def set_unique_id():
            # Sleep for 2.5 seconds to ensure 2 flushes, and then set value to finish
            cothread.Sleep(2.5)
            self.set_attributes(self.child, uniqueId=self.o.done_when_reaches)

        self.o.done_when_reaches = 38
        self.o.completed_offset = 0
        # Say that we're getting the first frame
        self.o.array_future = Future(None)
        self.o.array_future.set_result(None)
        self.o.start_future = Future(None)
        self.o.registrar = MagicMock()
        self.o.frame_timeout = 60
        # Spawn process to finish it after a few seconds
        self.process.spawn(set_unique_id)
        # Run
        self.o.on_run(self.context)
        assert self.child.handled_requests.mock_calls == [
            call.post("flushNow"),
            call.post("flushNow"),
        ]
        assert self.o.registrar.report.called_once
        assert self.o.registrar.report.call_args_list[0][0][0].steps == 0
        assert self.o.registrar.report.call_args_list[1][0][0].steps == 38
示例#3
0
 def test_run(self):
     update = MagicMock()
     # Say that we've returned from start
     self.o.start_future = Future(None)
     self.o.start_future.set_result(None)
     self.o.run(self.context, update)
     assert update.mock_calls == []
     assert self.child.handled_requests.mock_calls == []
示例#4
0
 def test_post_run_ready(self):
     # Say that we've returned from start
     self.o.start_future = Future(None)
     self.o.start_future.set_result(None)
     fname = "/tmp/test_filename"
     with open(fname, "w") as f:
         f.write("thing")
     assert os.path.isfile(fname)
     self.o.layout_filename = fname
     self.o.post_run_ready(self.context)
     assert self.child.handled_requests.mock_calls == []
     assert not os.path.isfile(fname)
示例#5
0
 def test_run(self):
     update = MagicMock()
     self.o.done_when_reaches = 38
     self.o.completed_offset = 0
     # Say that we're getting the first frame
     self.o.array_future = Future(None)
     self.o.array_future.set_result(None)
     # run waits for this value
     self.child.parts["uniqueId"].attr.set_value(self.o.done_when_reaches)
     self.o.run(self.context, update)
     assert self.child.handled_requests.mock_calls == []
     assert update.mock_calls == [call(38, self.o)]
示例#6
0
 def test_run(self):
     self.o.done_when_reaches = 38
     self.o.completed_offset = 0
     # Say that we're getting the first frame
     self.o.array_future = Future(None)
     self.o.array_future.set_result(None)
     self.o.registrar = MagicMock()
     # run waits for this value
     self.child.field_registry.get_field("uniqueId").set_value(
         self.o.done_when_reaches)
     self.o.run(self.context)
     assert self.child.handled_requests.mock_calls == []
     assert self.o.registrar.report.called_once
     assert self.o.registrar.report.call_args_list[0][0][0].steps == 38
 def test_post_run_ready_not_done_flush(self):
     # Say that we've returned from start
     self.o = HDFWriterPart(name="m", mri="BLOCK:HDF5")
     self.o.start_future = Future(None)
     fname = "/tmp/test_filename"
     with open(fname, "w") as f:
         f.write("thing")
     assert os.path.isfile(fname)
     self.o.layout_filename = fname
     self.o.on_post_run_ready(self.context)
     assert self.child.handled_requests.mock_calls == [
         call.post("flushNow")
     ]
     assert os.path.isfile(fname)
     self.o.on_reset(self.context)
     assert not os.path.isfile(fname)
示例#8
0
 def test_run(self):
     self.o = HDFWriterPart(name="m", mri="BLOCK:HDF5")
     self.context.set_notify_dispatch_request(
         self.o.notify_dispatch_request)
     self.o.done_when_reaches = 38
     self.o.completed_offset = 0
     # Say that we're getting the first frame
     self.o.array_future = Future(None)
     self.o.array_future.set_result(None)
     self.o.registrar = MagicMock()
     # run waits for this value, so say we have finished immediately
     self.set_attributes(self.child, uniqueId=self.o.done_when_reaches)
     self.mock_when_value_matches(self.child)
     self.o.on_run(self.context)
     assert self.child.handled_requests.mock_calls == [
         call.when_value_matches("uniqueId", 38, None)
     ]
     assert self.o.registrar.report.called_once
     assert self.o.registrar.report.call_args_list[0][0][0].steps == 38
示例#9
0
 def test_run(self):
     # Say that we've returned from start
     self.o.start_future = Future(None)
     self.o.start_future.set_result(None)
     self.o.on_run(self.context)
     assert self.child.handled_requests.mock_calls == []