Ejemplo n.º 1
0
    def test_file_path_translator_drive_mount_succeeds_with_valid_path(self):
        info = FilePathTranslatorInfo("C", "/foo", "")
        part_info = {"WINPATH": [info]}
        win_path = info.translate_filepath(part_info,
                                           "/foo/directory/file_name.xml")

        assert "C:\\directory\\file_name.xml" == win_path
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def test_file_path_translator_raises_AssertionError_with_colon_in_filepath(
            self):
        info = FilePathTranslatorInfo("C", "/foo", "")
        part_info = {"WINPATH": [info]}
        filepath = "/foo/directory/bad:filename"

        self.assertRaises(AssertionError, info.translate_filepath, part_info,
                          filepath)
Ejemplo n.º 4
0
    def test_file_path_translator_raises_AssertionError_with_bad_filepath_prefix(
            self):
        info = FilePathTranslatorInfo("C", "/foo", "")
        part_info = {"WINPATH": [info]}
        filepath = "foo/directory"

        self.assertRaises(AssertionError, info.translate_filepath, part_info,
                          filepath)
Ejemplo n.º 5
0
    def test_configure(self):
        completed_steps = 0
        steps_to_do = 456
        part_info = {"sth": [FilePathTranslatorInfo("Z", "/tmp", "")]}
        self.o.post_configure = MagicMock()
        # We wait to be armed, so set this here
        self.set_attributes(self.child, acquiring=True)

        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.INT, DataType.STRING, DataType.STRING],
            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,
            part_info,
            generator=MagicMock(duration=1.0),
            fileDir="/tmp",
        )
        assert self.child.handled_requests.mock_calls == [
            call.put("arrayCallbacks", True),
            call.put("arrayCounter", completed_steps),
            call.put("autoPixelsPerBuffer", "Manual"),
            call.put("binsInSpectrum", 2048),
            call.put("collectMode", "MCA mapping"),
            call.put("ignoreGate", "No"),
            call.put("inputLogicPolarity", "Normal"),
            call.put("pixelAdvanceMode", "Gate"),
            call.put("pixelsPerBuffer", 1),
            call.put("pixelsPerRun", steps_to_do),
            call.put("presetMode", "No preset"),
            call.post("start"),
            call.when_value_matches("acquiring", True, None),
            call.put("attributesFile", "Z:\\mri-attributes.xml"),
        ]
        with open("/tmp/mri-attributes.xml") 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_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_report_network_mount(self):
     part_info = dict(anyname=[self.o.on_report_status()])
     win_path = FilePathTranslatorInfo.translate_filepath(
         part_info, "/dls/directory")
     assert win_path == "\\\\dc\\dls\\directory"
Ejemplo n.º 8
0
    def test_file_path_translator_network_mount_succeeds_with_valid_path(self):
        info = FilePathTranslatorInfo("", "/foo", "//dc")
        part_info = {"WINPATH": [info]}
        win_path = info.translate_filepath(part_info, "/foo/directory")

        assert "\\\\dc\\foo\\directory" == win_path
Ejemplo n.º 9
0
    def configure_and_check_output(self, on_windows=False):
        energy = LineGenerator("energy", "kEv", 13.0, 15.2, 2)
        spiral = SpiralGenerator(["x", "y"], ["mm", "mm"], [0.0, 0.0],
                                 5.0,
                                 scale=2.0)
        generator = CompoundGenerator([energy, spiral], [], [], 0.1)
        generator.prepare()
        fileDir = "/tmp"
        formatName = "xspress3"
        fileTemplate = "thing-%s.h5"
        completed_steps = 0
        steps_to_do = 38
        part_info = {
            "DET": [NDArrayDatasetInfo(2)],
            "PANDA": [
                NDAttributeDatasetInfo.from_attribute_type(
                    "I0", AttributeDatasetType.DETECTOR, "COUNTER1.COUNTER"),
                NDAttributeDatasetInfo.from_attribute_type(
                    "It", AttributeDatasetType.MONITOR, "COUNTER2.COUNTER"),
                NDAttributeDatasetInfo.from_attribute_type(
                    "t1x", AttributeDatasetType.POSITION, "INENC1.VAL"),
            ],
            "STAT": [CalculatedNDAttributeDatasetInfo("sum", "StatsTotal")],
        }
        if on_windows:
            part_info["WINPATH"] = [FilePathTranslatorInfo("Y", "/tmp", "")]
        infos = self.o.on_configure(
            self.context,
            completed_steps,
            steps_to_do,
            part_info,
            generator,
            fileDir,
            formatName,
            fileTemplate,
        )
        assert len(infos) == 8
        assert infos[0].name == "xspress3.data"
        assert infos[0].filename == "thing-xspress3.h5"
        assert infos[0].type == DatasetType.PRIMARY
        assert infos[0].rank == 4
        assert infos[0].path == "/entry/detector/detector"
        assert infos[0].uniqueid == "/entry/NDAttributes/NDArrayUniqueId"

        assert infos[1].name == "xspress3.sum"
        assert infos[1].filename == "thing-xspress3.h5"
        assert infos[1].type == DatasetType.SECONDARY
        assert infos[1].rank == 2
        assert infos[1].path == "/entry/sum/sum"
        assert infos[1].uniqueid == "/entry/NDAttributes/NDArrayUniqueId"

        assert infos[2].name == "I0.data"
        assert infos[2].filename == "thing-xspress3.h5"
        assert infos[2].type == DatasetType.PRIMARY
        assert infos[2].rank == 2
        assert infos[2].path == "/entry/I0.data/I0.data"
        assert infos[2].uniqueid == "/entry/NDAttributes/NDArrayUniqueId"

        assert infos[3].name == "It.data"
        assert infos[3].filename == "thing-xspress3.h5"
        assert infos[3].type == DatasetType.MONITOR
        assert infos[3].rank == 2
        assert infos[3].path == "/entry/It.data/It.data"
        assert infos[3].uniqueid == "/entry/NDAttributes/NDArrayUniqueId"

        assert infos[4].name == "t1x.value"
        assert infos[4].filename == "thing-xspress3.h5"
        assert infos[4].type == DatasetType.POSITION_VALUE
        assert infos[4].rank == 2
        assert infos[4].path == "/entry/t1x.value/t1x.value"
        assert infos[4].uniqueid == "/entry/NDAttributes/NDArrayUniqueId"

        assert infos[5].name == "energy.value_set"
        assert infos[5].filename == "thing-xspress3.h5"
        assert infos[5].type == DatasetType.POSITION_SET
        assert infos[5].rank == 1
        assert infos[5].path == "/entry/detector/energy_set"
        assert infos[5].uniqueid == ""

        assert infos[6].name == "x.value_set"
        assert infos[6].filename == "thing-xspress3.h5"
        assert infos[6].type == DatasetType.POSITION_SET
        assert infos[6].rank == 1
        assert infos[6].path == "/entry/detector/x_set"
        assert infos[6].uniqueid == ""

        assert infos[7].name == "y.value_set"
        assert infos[7].filename == "thing-xspress3.h5"
        assert infos[7].type == DatasetType.POSITION_SET
        assert infos[7].rank == 1
        assert infos[7].path == "/entry/detector/y_set"
        assert infos[7].uniqueid == ""

        expected_xml_filename_local = "/tmp/BLOCK_HDF5-layout.xml"
        if on_windows:
            expected_xml_filename_remote = "Y:\\BLOCK_HDF5-layout.xml"
            expected_filepath = "Y:" + os.sep
        else:
            expected_xml_filename_remote = expected_xml_filename_local
            expected_filepath = "/tmp" + os.sep
        # 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.put("positionMode", True),
            call.put("arrayCounter", 0),
            call.put("dimAttDatasets", True),
            call.put("enableCallbacks", True),
            call.put("fileName", "xspress3"),
            call.put("filePath", expected_filepath),
            call.put("fileTemplate", "%sthing-%s.h5"),
            call.put("fileWriteMode", "Stream"),
            call.put("lazyOpen", True),
            call.put("storeAttr", True),
            call.put("swmrMode", True),
            call.put("extraDimSize3", 1),
            call.put("extraDimSize4", 1),
            call.put("extraDimSize5", 1),
            call.put("extraDimSize6", 1),
            call.put("extraDimSize7", 1),
            call.put("extraDimSize8", 1),
            call.put("extraDimSize9", 1),
            call.put("extraDimSizeN", 20),
            call.put("extraDimSizeX", 2),
            call.put("extraDimSizeY", 1),
            call.put("numExtraDims", 1),
            call.put("posNameDim3", ""),
            call.put("posNameDim4", ""),
            call.put("posNameDim5", ""),
            call.put("posNameDim6", ""),
            call.put("posNameDim7", ""),
            call.put("posNameDim8", ""),
            call.put("posNameDim9", ""),
            call.put("posNameDimN", "d1"),
            call.put("posNameDimX", "d0"),
            call.put("posNameDimY", ""),
            call.put("flushAttrPerNFrames", 0),
            call.put("flushDataPerNFrames", 38),
            call.put("xmlLayout", expected_xml_filename_remote),
            call.put("numCapture", 0),
            call.post("start"),
            call.when_value_matches("arrayCounterReadback", greater_than_zero,
                                    None),
        ]
        with open(expected_xml_filename_local) as f:
            actual_xml = f.read().replace(">", ">\n")
        # Check the layout filename Malcolm uses for file creation
        assert self.o.layout_filename == expected_xml_filename_local
        return actual_xml