def test_FilenameGetterWithDirectoryInitialization_WithoutDirectory( self, mock_class): mock_instance = mock_class.return_value mock_instance.GetFileName.return_value = 'kratos.h5' settings = self._FilenameGetterSettings() with patch('os.makedirs', autospec=True) as p: obj = file_io._FilenameGetterWithDirectoryInitialization(settings) obj.Get(_SurrogateModelPart()) self.assertEqual(p.call_count, 0)
def test_FilenameGetterWithDirectoryInitialization_DirectoryDoesNotExist(self): settings = self._FilenameGetterSettings(file_name='/foo/kratos.h5') patcher1 = patch('os.path.exists', autospec=True) patcher2 = patch('os.makedirs', autospec=True) pathexists = patcher1.start() makedirs = patcher2.start() pathexists.return_value = False obj = file_io._FilenameGetterWithDirectoryInitialization(settings) obj.Get(_SurrogateModelPart()) pathexists.assert_called_once_with('/foo') makedirs.assert_called_once_with('/foo') patcher1.stop() patcher2.stop()
def test_FilenameGetterWithDirectoryInitialization_DirectoryExists( self, mock_class): mock_instance = mock_class.return_value mock_instance.GetFileName.return_value = '/foo/kratos.h5' settings = self._FilenameGetterSettings(file_name='/foo/kratos.h5') patcher1 = patch('os.path.exists', autospec=True) patcher2 = patch('os.makedirs', autospec=True) pathexists = patcher1.start() makedirs = patcher2.start() pathexists.return_value = True obj = file_io._FilenameGetterWithDirectoryInitialization(settings) obj.Get(_SurrogateModelPart()) pathexists.assert_called_once_with('/foo') self.assertEqual(makedirs.call_count, 0) patcher1.stop() patcher2.stop()
def test_FilenameGetterWithDirectoryInitialization_DirectoryDoesNotExist( self, mock_class): mock_instance = mock_class.return_value mock_instance.GetFileName.return_value = '/foo/kratos.h5' settings = self._FilenameGetterSettings(file_name='/foo/kratos.h5') patcher1 = patch('os.path.exists', autospec=True) patcher2 = patch('os.makedirs', autospec=True) pathexists = patcher1.start() makedirs = patcher2.start() pathexists.return_value = False data_comm = KratosMultiphysics.Testing.GetDefaultDataCommunicator() obj = file_io._FilenameGetterWithDirectoryInitialization( settings, data_comm) obj.Get(_SurrogateModelPart()) pathexists.assert_called_once_with('/foo') makedirs.assert_called_once_with('/foo') patcher1.stop() patcher2.stop()
def test_FilenameGetterWithDirectoryInitialization_WithoutDirectory(self): settings = self._FilenameGetterSettings() with patch('os.makedirs', autospec=True) as p: obj = file_io._FilenameGetterWithDirectoryInitialization(settings) obj.Get(_SurrogateModelPart()) self.assertEqual(p.call_count, 0)