Exemple #1
0
    def test_recoil_file_contents(self):
        recoil_file = utils.get_resource_dir() / "mcerd_recoil_file.txt"
        expected = utils.get_template_file_contents(
            recoil_file
        )
        output = self.mcerd.get_recoil_file_contents()

        self.assertEqual(expected, output)
Exemple #2
0
    def test_get_detector_file_contents(self):
        detector_file = utils.get_resource_dir() / "detector_file.txt"

        expected = utils.get_template_file_contents(
            detector_file,
            foils_file=self.directory / "Default.foils"
        )
        output = self.mcerd.get_detector_file_contents()

        self.assertEqual(expected, output)
Exemple #3
0
    def test_get_command_file_contents(self):
        detector_file = utils.get_resource_dir() / "mcerd_command.txt"

        expected = utils.get_template_file_contents(
            detector_file,
            tgt_file=self.directory / "Default.erd_target",
            det_file=self.directory / "Default.erd_detector",
            rec_file=self.directory / "He-Default.recoil",
            pre_file=self.directory / "Default.pre"
        )
        output = self.mcerd.get_command_file_contents()

        self.assertEqual(expected, output)
    def test_multiline(self):
        input_file = utils.get_resource_dir() / "foils_file.txt"

        with tempfile.TemporaryDirectory() as tmp_dir:
            file = Path(tmp_dir, "foo.bar")
            with subprocess.Popen(["cat", str(input_file)],
                                  **self.default_kwargs) as proc:
                xs = sutils.process_output(proc, file=file)

                self.assertTrue(1 < len(xs))
                with input_file.open("r") as f0, file.open("r") as f1:
                    f0_contents = f0.readlines()
                    f1_contents = f1.readlines()
                    utils.assert_all_equal(xs, f0_contents, f1_contents)
Exemple #5
0
 def run_spectra_calculation(mesu, tmp_dir: Path, **kwargs):
     """Helper for running spectra calculations"""
     det = mesu.get_detector_or_default()
     det.update_directories(tmp_dir / "Detector")
     resource_dir = utils.get_resource_dir()
     cuts = [
         resource_dir / "cuts.1H.ERD.0.cut",
         resource_dir / "cuts.1H.ERD.1.cut",
         resource_dir / "cuts.35Cl.RBS_Mn.0.cut",
         resource_dir / "cuts.7Li.0.0.0.cut",
     ]
     es = EnergySpectrum.calculate_measured_spectra(
         mesu, cuts, **kwargs, verbose=False
     )
     return es
Exemple #6
0
 def setUp(self):
     input_file = utils.get_resource_dir() / "events.evnt"
     self.params = {
         "adc_count": 3,
         "columns": "$3,$5,$4",
         "input_file": input_file,
         "nevents": 0,
         "skip_lines": 1,
         "tablesize": 10,
         "timediff": True,
         "timing": {
             "1": (-1000, 1000)
         },
         "trigger": 2,
         "verbose": False,
     }
     self.expected = [
         "10 100 -100\n",
         "20 200 100\n",
     ]
Exemple #7
0
__author__ = "Juhani Sundell"
__version__ = "2.0"

import unittest
import tests.mock_objects as mo
import tempfile
import tests.utils as utils
import time

import modules.general_functions as gf

from modules.get_espe import GetEspe
from pathlib import Path
from tests.utils import PlatformSwitcher

resource_dir = utils.get_resource_dir()
_RECOIL_FILE = resource_dir / "C-Default.recoil"
_ERD_FILE = resource_dir / "C-Default.*.erd"
_EXPECTED_SPECTRUM_FILE = resource_dir / "C-Default-expected.simu"

del resource_dir


class TestGetCommand(unittest.TestCase):
    def setUp(self):
        beam = mo.get_beam()
        det = mo.get_detector()
        self.rec_file = Path(tempfile.gettempdir(), "rec")
        self.erd_file = Path(tempfile.gettempdir(), "erd")

        self.espe = GetEspe(