コード例 #1
0
    def test_show_interface_McXtrace(self):
        """
        Ensure that show_interface runs without errors and returns widget
        """

        sim_interface = SimInterface(setup_populated_instr_McXtrace())
        widget = sim_interface.show_interface()

        self.assertIsInstance(widget, widgets.widgets.widget_box.VBox)
コード例 #2
0
    def test_initialization_McStas(self):
        """
        Checking that interface can initialize from instrument and retrieve the
        parameters that has a default value.
        """

        sim_interface = SimInterface(setup_populated_instr_McStas())
        self.assertEqual(sim_interface.parameters["has_default"], 37)
コード例 #3
0
    def test_update_mpi(self):
        """
        Check mpi can be set correctly
        """
        sim_interface = SimInterface(setup_populated_instr_McStas())
        sim_interface.show_interface()

        fake_change = FakeChange(new=3)
        sim_interface.update_mpi(fake_change)
        self.assertEqual(sim_interface.mpi, 3)

        # Check input that wouldn't work is ignored
        fake_change = FakeChange(new="wrong input")
        sim_interface.update_mpi(fake_change)
        self.assertEqual(sim_interface.mpi, 3)
コード例 #4
0
    def test_update_ncount(self):
        """
        Check ncount can be set correctly
        """
        sim_interface = SimInterface(setup_populated_instr_McStas())
        sim_interface.show_interface()

        fake_change = FakeChange(new=100)
        sim_interface.update_ncount(fake_change)
        self.assertEqual(sim_interface.ncount, 100)
コード例 #5
0
    def test_complex_instrument_interface(self, mock_stdout):
        """
        Test that a simulation can be performed through the simulation
        interface, or as close as I can through scripting.
        Need to join the simulation thread to the main thread in order
        to wait for the completion as it is performed in a new thread.
        """
        CURRENT_DIR = os.getcwd()
        THIS_DIR = os.path.dirname(os.path.abspath(__file__))
        os.chdir(THIS_DIR)

        Instr = setup_complex_instrument()

        interface = SimInterface(Instr)
        interface.show_interface()

        change = FakeChange()

        interface.run_simulation_thread(change)

        for thread in threading.enumerate():
            if thread.name != "MainThread":
                thread.join()

        data = interface.plot_interface.data

        os.chdir(CURRENT_DIR)

        intensity_data_pos = functions.name_search("PSD_1D_1", data).Intensity
        sum_outside_beam = sum(intensity_data_pos[0:50])
        sum_inside_beam = sum(intensity_data_pos[51:99])
        self.assertTrue(1000 * sum_outside_beam < sum_inside_beam)

        intensity_data_neg = functions.name_search("PSD_1D_2", data).Intensity
        sum_outside_beam = sum(intensity_data_neg[51:99])
        sum_inside_beam = sum(intensity_data_neg[0:50])
        self.assertTrue(1000 * sum_outside_beam < sum_inside_beam)

        intensity_data_all = functions.name_search("PSD_1D", data).Intensity
        sum_outside_beam = sum(intensity_data_all[49:51])
        sum_inside_beam = (sum(intensity_data_all[0:45]) +
                           sum(intensity_data_all[56:99]))
        self.assertTrue(1000 * sum_outside_beam < sum_inside_beam)