Ejemplo n.º 1
0
    def test_tof_list_file_contents_are_expected(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            tmp_dir = Path(tmp_dir)
            mesu = mo.get_measurement(
                path=tmp_dir / "mesu.info", save_on_creation=True)
            self.run_spectra_calculation(
                mesu, tmp_dir, spectrum_width=0.5)

            tof_file = mesu.get_energy_spectra_dir() / "cuts.1H.ERD.0.tof_list"

            expected = list(
                parser.parse_strs(
                    self.expected_1h_0_tof_list_content, method=parser.COLUMN)
            )
            actual = list(
                parser.parse_file(tof_file, method=parser.COLUMN)
            )

            # energy spectrum must match with certain precision
            np.testing.assert_almost_equal(actual[2], expected[2], decimal=3)

            # other values must match exactly
            self.assertEqual(
                expected[:1] + expected[3:],
                actual[:1] + actual[3:]
            )
Ejemplo n.º 2
0
    def test_espe_params(self, mock_exec):
        esp = EnergySpectrumParamsDialog(Mock(),
                                         "measurement",
                                         measurement=mo.get_measurement())
        esp.close()

        # ValueError is raised if spectrum type is wrong
        self.assertRaises(ValueError,
                          lambda: EnergySpectrumParamsDialog(Mock(), "simu"))

        # AttributeError is raised if simulation has no sample
        self.assertRaises(
            AttributeError, lambda: EnergySpectrumParamsDialog(
                Mock(),
                "simulation",
                simulation=mo.get_simulation(),
                element_simulation=mo.get_element_simulation(),
                recoil_widget=Mock()))

        sample = mo.get_sample()
        sim = mo.get_simulation()
        sim.sample = sample
        elem_sim = sim.add_element_simulation(mo.get_recoil_element(),
                                              save_on_creation=False)
        esp = EnergySpectrumParamsDialog(Mock(),
                                         "simulation",
                                         simulation=sim,
                                         element_simulation=elem_sim,
                                         recoil_widget=Mock())
        esp.close()

        assert mock_exec.call_count == 2
Ejemplo n.º 3
0
 def test_calculation_returns_expected_values_when_ch_equals_05(self):
     with tempfile.TemporaryDirectory() as tmp_dir:
         tmp_dir = Path(tmp_dir)
         mesu = mo.get_measurement(
             path=tmp_dir / "mesu.info", save_on_creation=True)
         es = self.run_spectra_calculation(
             mesu, tmp_dir, spectrum_width=0.5)
         self.assertEqual(self.expected_05, es)
Ejemplo n.º 4
0
    def test_spectra_files_are_created(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            tmp_dir = Path(tmp_dir)
            mesu = mo.get_measurement(path=tmp_dir / "mesu.info",
                                      save_on_creation=True)
            self.run_spectra_calculation(mesu, tmp_dir, spectrum_width=0.5)

            expected = sorted(
                [*self.expected_hist_files, *self.expected_tof_list_files])
            spectra_files = sorted(os.listdir(mesu.get_energy_spectra_dir()))
            self.assertEqual(expected, spectra_files)
Ejemplo n.º 5
0
    def test_initialization(self):
        parent = QWidget()
        parent.measurement = mo.get_measurement()
        parent.measurement.selector = Selector(
            parent.measurement,
            mo.get_global_settings().get_default_colors())
        icon_manager = Mock()
        depth_dir, all_elems, _ = mo.get_sample_depth_files_and_elements()
        w = MatplotlibDepthProfileWidget(parent, depth_dir, all_elems, {},
                                         icon_manager, {})

        w.close()
Ejemplo n.º 6
0
    def test_initialization(self, mock_exec):
        """A simple test to see if various dialogs get initialized properly.
        """
        e = ElementLossesDialog(Mock(), mo.get_measurement())
        e.close()

        c = CalibrationDialog([mo.get_measurement()], mo.get_detector(),
                              mo.get_run())
        c.close()

        # AttributeError is raised if simulation has no sample
        self.assertRaises(
            AttributeError,
            lambda: OptimizationDialog(mo.get_simulation(), Mock()))

        sample = mo.get_sample()
        sim = mo.get_simulation()
        sim.sample = sample
        o = OptimizationDialog(sim, Mock())
        self.assertFalse(o.pushButton_OK.isEnabled())
        o.close()

        assert mock_exec.call_count == 3
Ejemplo n.º 7
0
    def test_directory_reference_update(self):
        self.assertEqual(Path(tempfile.gettempdir(), "Detector", ".detector"),
                         self.det.path)

        mesu = mo.get_measurement()
        mesu_path = Path(tempfile.gettempdir(), "mesu")
        mesu.directory = Path(mesu_path)

        self.det.update_directory_references(mesu)

        self.assertEqual(mesu_path / "Detector" / ".detector", self.det.path)
        self.assertEqual(mesu_path / "Detector" / Detector.EFFICIENCY_DIR,
                         self.det.get_efficiency_dir())
        # Directory is not yet created
        self.assertFalse(self.det.get_efficiency_dir().exists())
Ejemplo n.º 8
0
 def setUp(self) -> None:
     self.measurement = mo.get_measurement()
     self.global_settings = mo.get_global_settings()
     self.parent_widget = Mock()
Ejemplo n.º 9
0
 def test_measurement_has_slots(self):
     m = mo.get_measurement()
     utils.assert_has_slots(m)
Ejemplo n.º 10
0
 def setUp(self):
     self.mesu_widget = MeasurementSettingsWidget(mo.get_measurement())