Exemplo n.º 1
0
    def test_integration(self):
        # Fill in the repository with data
        self.fill_repo()
        try:
            # Create a temp folder where the backup files will be placed
            # and the backup will be stored
            temp_folder = tempfile.mkdtemp()
            # Create the backup scripts
            backup_full_path = self.create_backup_scripts(temp_folder)

            # Put the backup folder in the path
            sys.path.append(backup_full_path)
            # Import the backup script - this action will also run it
            # It is assumed that the backup script ends with .py
            importlib.import_module(self._bs_instance._script_filename[:-3])

            # Check the backup
            from aiida import settings
            from filecmp import dircmp
            import os
            from aiida.common.utils import are_dir_trees_equal
            source_dir = os.path.join(settings.REPOSITORY_PATH,
                                      self._repo_rel_path)
            dest_dir = os.path.join(backup_full_path,
                                    self._bs_instance._file_backup_folder_rel,
                                    self._repo_rel_path)
            self.assertTrue(
                are_dir_trees_equal(source_dir, dest_dir),
                "The backed-up repository has differences "
                "to the original one.")
        finally:
            shutil.rmtree(temp_folder, ignore_errors=True)
Exemplo n.º 2
0
    def test_integration(self):
        """Test integration"""
        from aiida.common.utils import Capturing

        # Fill in the repository with data
        self.fill_repo()
        try:
            # Create a temp folder where the backup files will be placed
            # and the backup will be stored
            temp_folder = tempfile.mkdtemp()

            # Capture the sysout of the following command
            with Capturing():
                # Create the backup scripts
                backup_full_path = self.create_backup_scripts(temp_folder)

            # Put the backup folder in the path
            sys.path.append(backup_full_path)

            # Import the backup script - this action will also run it
            # It is assumed that the backup script ends with .py
            importlib.import_module(self._bs_instance._script_filename[:-3])

            # Check the backup
            import os
            from aiida.manage.configuration import get_profile
            from aiida.common.utils import are_dir_trees_equal

            dirpath_repository = get_profile().repository_path
            source_dir = os.path.join(dirpath_repository, self._repo_rel_path)
            dest_dir = os.path.join(backup_full_path,
                                    self._bs_instance._file_backup_folder_rel,
                                    self._repo_rel_path)
            res, msg = are_dir_trees_equal(source_dir, dest_dir)
            self.assertTrue(
                res,
                'The backed-up repository has differences to the original one. '
                + str(msg) + '. If the test fails, report it in issue #2134.')
        finally:
            shutil.rmtree(temp_folder, ignore_errors=True)