示例#1
0
 def test_OpenStudy_non_existing(self):
     with self.assertRaisesRegex(
             FileNotFoundError,
             'File "some_completely_random_non_existin_path" does not exist!'
     ):
         salome_study_utilities.OpenStudy(
             Path("some_completely_random_non_existin_path"))
示例#2
0
    def test_OpenStudy(self):
        num_objs_in_study = salome_study_utilities.GetNumberOfObjectsInStudy()

        # this creates the study file
        study_file_name = self.__execute_test_save_study_in_folder()

        salome_study_utilities.ResetStudy()

        self.assertTrue(salome_study_utilities.OpenStudy(study_file_name))

        self.assertEqual(num_objs_in_study,
                         salome_study_utilities.GetNumberOfObjectsInStudy(),
                         msg="Number of objects in study has changed!")
示例#3
0
    def test_OpenStudy_fake_failure(self):
        file_path = Path("my_study_open_faked_failure.hdf")
        self.addCleanup(lambda: DeleteFileIfExisting(file_path))
        file_path.touch()

        with patch('salome.myStudy.Open', return_value=False):
            with self.assertLogs('kratos_salome_plugin.salome_study_utilities',
                                 level='CRITICAL') as cm:
                salome_study_utilities.OpenStudy(file_path)
                self.assertEqual(len(cm.output), 1)
                self.assertEqual(
                    cm.output[0],
                    'CRITICAL:kratos_salome_plugin.salome_study_utilities:Study could not be opened from path: "{}"'
                    .format(file_path))
示例#4
0
    def test_OpenStudy_warning_logs_modified_but_empty_study(
            self, mock_num_objs_study, mock_is_modified, mock_open_study):
        # if the study is modified but empty it should not give the warning
        file_path = Path("my_empty_study_file.hdf")
        self.addCleanup(lambda: DeleteFileIfExisting(file_path))
        file_path.touch()

        with self.assertLogs('kratos_salome_plugin.salome_study_utilities',
                             level='DEBUG') as cm:
            salome_study_utilities.OpenStudy(file_path)
            self.assertEqual(len(cm.output), 1)
            self.assertEqual(
                cm.output[0],
                'DEBUG:kratos_salome_plugin.salome_study_utilities:Study was openend from path: "{}"'
                .format(file_path))
示例#5
0
    def test_OpenStudy_warning_logs_modified_study(self, mock_num_objs_study,
                                                   mock_is_modified,
                                                   mock_open_study):
        file_path = Path("my_study_file.hdf")
        self.addCleanup(lambda: DeleteFileIfExisting(file_path))
        file_path.touch()

        with self.assertLogs('kratos_salome_plugin.salome_study_utilities',
                             level='WARNING') as cm:
            salome_study_utilities.OpenStudy(file_path)
            self.assertEqual(len(cm.output), 1)
            self.assertEqual(
                cm.output[0],
                'WARNING:kratos_salome_plugin.salome_study_utilities:Opening study when current study has unsaved changes'
            )
示例#6
0
    def test_OpenStudy_warning_logs_wrong_suffix(self, mock_num_objs_study,
                                                 mock_is_modified,
                                                 mock_open_study):
        file_path = Path("without_suffix")
        self.addCleanup(lambda: DeleteFileIfExisting(file_path))
        file_path.touch()

        with self.assertLogs('kratos_salome_plugin.salome_study_utilities',
                             level='WARNING') as cm:
            salome_study_utilities.OpenStudy(file_path)
            self.assertEqual(len(cm.output), 1)
            self.assertEqual(
                cm.output[0],
                'WARNING:kratos_salome_plugin.salome_study_utilities:Opening study from file without ".hdf" extension: "{}"'
                .format(file_path))
示例#7
0
    def test_OpenStudy_exception(self):
        file_path = Path("my_empty_invaid_study_file.hdf")
        self.addCleanup(lambda: DeleteFileIfExisting(file_path))
        file_path.touch()  # this is of course no vaild study_file

        with self.assertLogs('kratos_salome_plugin.salome_study_utilities',
                             level='ERROR') as cm:
            salome_study_utilities.OpenStudy(file_path)
            self.assertEqual(len(cm.output), 2)
            self.assertIn(
                'ERROR:kratos_salome_plugin.salome_study_utilities:Exception when opening study:',
                cm.output[0])
            self.assertEqual(
                cm.output[1],
                'CRITICAL:kratos_salome_plugin.salome_study_utilities:Study could not be opened from path: "{}"'
                .format(file_path))
示例#8
0
 def test_OpenStudy_string(self):
     with self.assertRaisesRegex(TypeError,
                                 'Path must be a "pathlib.Path" object!'):
         salome_study_utilities.OpenStudy("open_study_name")
示例#9
0
 def test_OpenStudy_empty_input(self):
     with self.assertRaisesRegex(NameError, 'Path cannot be empty!'):
         salome_study_utilities.OpenStudy(Path())