コード例 #1
0
    def test_copy_load_task(self):
        # Simulate a copy of a project between 2 users:
        copy2(self.filepath, self.filepath_temp)
        task, legacy = load_project(self.filepath_temp)
        self.assertIsInstance(task, KromatographyTask)
        self.assertTrue(legacy)

        # Make sure that loading the new file leads to a task that has updated
        # its project_filepath attribute
        self.assertEqual(task.project_filepath, self.filepath_temp)
コード例 #2
0
    def test_save_task_to_new_file(self):
        task, legacy = load_project(self.filepath)
        self.assertTrue(legacy)

        save_project(self.filepath_temp, task)

        # Test that the resulting file contains the new file since load_object
        # doesn't modify the object it loads:
        task_again, legacy = load_object(self.filepath_temp)
        self.assertIsInstance(task_again, KromatographyTask)
        self.assertEqual(task_again.project_filepath, self.filepath_temp)
        self.assertFalse(legacy)
コード例 #3
0
    def test_save_task_to_new_file_wrong_ext(self):
        """ If trying to save to wrong file extension, it's appended.
        """
        backup_filepath = self.filepath_wrong_ext + KROM_EXTENSION
        if isfile(backup_filepath):
            os.remove(backup_filepath)

        self.assertFalse(isfile(backup_filepath))

        task, _ = load_project(self.filepath)
        save_project(self.filepath_wrong_ext, task)
        self.assertFalse(isfile(self.filepath_wrong_ext))
        self.assertTrue(isfile(backup_filepath))
コード例 #4
0
    def open_project_from_file(self, path):
        """ Open a saved task from a project file.
        """
        from kromatography.io.task import load_project

        path = os.path.abspath(path)
        self.add_to_recent_files(path)
        already_open = self.activate_window_if_already_open(path)

        if already_open:
            msg = "Project {} already loaded.".format(path)
            logger.info(msg)
        else:
            try:
                task, legacy_file = load_project(path)
            except Exception as e:
                msg = ("The object found in {} didn't load successfully. Error"
                       " was {}".format(path, e))
                logger.exception(msg)
                error(None, msg)
                raise IOError(msg)

            if not isinstance(task, KromatographyTask):
                msg = "The object found in {} is not a {} project but a {}"
                msg = msg.format(path, APP_TITLE, type(task))
                logger.exception(msg)
                error(None, msg)
                raise IOError(msg)

            self._finalize_task_and_open_task_window(task)

            if legacy_file and self.warn_if_old_file:
                from pyface.api import warning
                from ..ui.tasks.kromatography_task import KROM_EXTENSION
                msg = "The file {} doesn't use the newest {} format. It is " \
                      "recommended to re-save the project to ensure future " \
                      "readability."
                msg = msg.format(path, KROM_EXTENSION)
                warning(None, msg)

            if self.auto_close_empty_windows_on_open:
                self.close_empty_windows()

            return task
コード例 #5
0
 def test_load_wrong_obj_type(self):
     obj = Simulation(name="dslkjf")
     save_object(self.filepath_temp, obj)
     task, legacy = load_project(self.filepath_temp)
     self.assertFalse(legacy)
     assert_has_traits_almost_equal(task, obj)
コード例 #6
0
 def test_load_task(self):
     task, legacy = load_project(self.filepath)
     self.assertIsInstance(task, KromatographyTask)
     self.assertEqual(task.project_filepath, self.filepath)
     self.assertTrue(legacy)