def tearDown(self):
        ADS.clear()
        if os.path.exists(self.pr.recovery_directory_hostname):
            shutil.rmtree(self.pr.recovery_directory_hostname)

        if os.path.exists(self.working_directory):
            shutil.rmtree(self.working_directory)
    def recover_selected_checkpoint(self, selected):
        """
        Recover the passed checkpoint
        :param selected: String; Checkpoint name to be recovered
        """
        # If this is a valid file then it should only be the checkpoint here
        if os.path.exists(selected):
            selected = os.path.basename(selected)

        self.is_recovery_running = True
        self.presenter.change_start_mantid_to_cancel_label()

        ADS.clear()

        # Recover given the checkpoint selected
        pid_dir = self.project_recovery.get_pid_folder_to_load_a_checkpoint_from()
        selected = selected.replace(" ", "T")
        checkpoint = os.path.join(pid_dir, selected)
        self.selected_checkpoint = selected

        try:
            self._start_recovery_of_checkpoint(checkpoint)
        except Exception as e:
            # Fail "Silently" by setting failed run to true, setting checkpoint to tried and closing the view.
            logger.debug("Project Recovery: " + str(e))
            self.has_failed_run = True
            self._update_checkpoint_tried(selected)
            self.presenter.close_view()
    def open_selected_in_editor(self, selected):
        """
        Open the passed checkpoint in the editor
        :param selected: String; Checkpoint name to be opened
        """
        self.is_recovery_running = True
        ADS.clear()

        # Open editor for this checkpoint
        pid_dir = self.project_recovery.get_pid_folder_to_load_a_checkpoint_from()
        selected = selected.replace(" ", "T")
        checkpoint = os.path.join(pid_dir, selected)

        try:
            self.project_recovery.open_checkpoint_in_script_editor(checkpoint)
        except Exception as e:
            if isinstance(e, KeyboardInterrupt):
                raise
            # Fail "silently"
            self.has_failed_run = True

        if self.has_failed_run:
            self._update_checkpoint_tried(selected)

        self.is_recovery_running = False
        self.presenter.close_view()
    def test_observeClear_calls_clearHandle_when_set_on_ads_its_cleared(self):
        CreateSampleWorkspace(OutputWorkspace="ws")

        self.fake_class.observeClear(True)
        self.fake_class.clearHandle = mock.MagicMock()
        ADS.clear()

        self.assertEqual(self.fake_class.clearHandle.call_count, 1)
    def test_observeAll_calls_anyChangeHandle_when_set_on_ads_clear(self):
        self.fake_class.observeAll(True)
        CreateSampleWorkspace(OutputWorkspace="ws")
        expected_count = 1

        # Will replace first workspace
        ADS.clear()
        expected_count += 1

        self.assertEqual(self.fake_class.anyChangeHandle.call_count, expected_count)
示例#6
0
    def test_load_calls_loads_successfully(self):
        working_directory = tempfile.mkdtemp()
        return_value_for_load = os.path.join(working_directory, os.path.basename(working_directory) + ".mtdproj")
        self.project._save_file_dialog = mock.MagicMock(return_value=working_directory)
        CreateSampleWorkspace(OutputWorkspace="ws1")
        self.project.save_as()

        self.assertEqual(self.project._save_file_dialog.call_count, 1)
        ADS.clear()

        self.project._load_file_dialog = mock.MagicMock(return_value=return_value_for_load)
        self.project.load()
        self.assertEqual(self.project._load_file_dialog.call_count, 1)
        self.assertEqual(["ws1"], ADS.getObjectNames())
示例#7
0
    def setUp(self):
        AnalysisDataService.clear()
        self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0]
        self.load_result, self.run_number, self.filename = load_workspace_from_filename(self.filepath)
        self.loaded_data = MuonLoadData()
        self.data_context = MuonDataContext(self.loaded_data)
        self.gui_context = MuonGuiContext()
        self.group_pair_context = MuonGroupPairContext()
        self.gui_context.update({'RebinType': 'None'})

        self.context = MuonContext(muon_data_context=self.data_context, muon_gui_context=self.gui_context, muon_group_context=self.group_pair_context)

        self.data_context.instrument = 'EMU'

        self.loaded_data.add_data(workspace=self.load_result, run=[self.run_number], filename=self.filename,
                                  instrument='EMU')
        self.data_context.current_runs = [[self.run_number]]
        self.data_context.update_current_data()
        self.group_pair_context.reset_group_and_pairs_to_default(self.load_result['OutputWorkspace'][0]._workspace,
                                                                 'EMU', '')
    def test_recovery_save_with_just_interfaces(self, windows_that_are_savable):
        CreateSampleWorkspace(OutputWorkspace="ws")
        # Return a FakeEncoder object that will return an empty dictionary
        windows_that_are_savable.return_value = [[FakeEncoder(), FakeEncoder()]]
        self.pr_saver._spin_off_another_time_thread = mock.MagicMock()
        ADS.clear()

        self.pr_saver.gfm = mock.MagicMock()
        self.pr_saver.gfm.figs = {}

        self.pr_saver.recovery_save()

        # Check no 0.py was made
        checkpoint = self.pr.listdir_fullpath(self.pr.recovery_directory_pid)[0]
        self.assertTrue(not os.path.exists(os.path.join(checkpoint, "0.py")))
        self.assertEqual(self.pr_saver._spin_off_another_time_thread.call_count, 1)

        # Read the .json file and check nothing is in workspace and something is in the interfaces dictionary
        with open(os.path.join(checkpoint, (os.path.basename(checkpoint) + self.pr.recovery_file_ext))) as f:
            dictionary = json.load(f)
            self.assertEqual(len(dictionary["interfaces"]), 1)
            self.assertEqual(len(dictionary["workspaces"]), 0)
 def tearDown(self):
     AnalysisDataService.clear()
示例#10
0
 def tearDownClass(cls):
     AnalysisDataService.clear()
 def setUp(self):
     AnalysisDataService.clear()
 def tearDown(self):
     self.model = None
     AnalysisDataService.clear()
示例#13
0
 def tearDown(self):
     ADS.clear()
 def cleanup(self):
     self.fsg_presenter = None
     self.fsg_view = None
     self.fsg_model = None
     self._app = None
     AnalysisDataService.clear()
示例#15
0
    def tearDown(self):
        # Make sure to clear the hostname layer between tests
        ADS.clear()

        if os.path.exists(self.pid):
            shutil.rmtree(self.pid)
示例#16
0
 def cleanup(self):
     ADS.clear()
     _try_delete_cal_and_focus_dirs(CWDIR)
 def tearDown(self):
     AnalysisDataService.clear()
示例#18
0
 def cleanup(self):
     ADS.clear()
     try:
         os.remove(self._peaks_file)
     except:
         pass
示例#19
0
 def cleanup(self):
     ADS.clear()
     try:
         os.remove(self._filepath)
     except:
         pass
示例#20
0
 def cleanup(self):
     ADS.clear()
示例#21
0
 def cleanup(self):
     AnalysisDataService.clear()
 def tearDown(self):
     self.fake_class.observeAll(False)
     ADS.clear()
示例#23
0
 def tearDown(self):
     ADS.clear()
示例#24
0
 def tearDown(self):
     self.fake_class.observeAll(False)
     ADS.clear()
示例#25
0
 def tearDown(self):
     ADS.clear()
     if isdir(self.working_directory):
         rmtree(self.working_directory)
示例#26
0
 def tearDown(self):
     ADS.clear()
     if isdir(self.working_directory):
         rmtree(self.working_directory)
示例#27
0
 def tearDown(self):
     AnalysisDataService.clear()
     config['default.facility'] = self._oldFacility
     config['default.instrument'] = self._oldInstrument
    def tearDown(self):
        # Make sure to clear the hostname layer between tests
        ADS.clear()

        if os.path.exists(self.pid):
            shutil.rmtree(self.pid)