Esempio n. 1
0
    def test_environment_variable_not_set(self):
        """Check that if the environment variable is not set, config folder will be created in `DEFAULT_AIIDA_PATH`.

        To make sure we do not mess with the actual default `.aiida` folder, which often lives in the home folder
        we create a temporary directory and set the `DEFAULT_AIIDA_PATH` to it.
        """
        try:
            directory = tempfile.mkdtemp()

            # Change the default configuration folder path to temp folder instead of probably `~`.
            settings.DEFAULT_AIIDA_PATH = directory

            # Make sure that the environment variable is not set
            try:
                del os.environ[settings.DEFAULT_AIIDA_PATH_VARIABLE]
            except KeyError:
                pass
            settings.set_configuration_directory()

            config_folder = os.path.join(directory,
                                         settings.DEFAULT_CONFIG_DIR_NAME)
            self.assertTrue(os.path.isdir(config_folder))
            self.assertEqual(settings.AIIDA_CONFIG_FOLDER, config_folder)
        finally:
            shutil.rmtree(directory)
Esempio n. 2
0
    def test_environment_variable_path_including_config_folder(self):  # pylint: disable=invalid-name
        """If `AIIDA_PATH` is set and the path contains the base name of the config folder, it should work, i.e:

            `/home/user/.virtualenvs/dev/`
            `/home/user/.virtualenvs/dev/.aiida`

        Are both legal and will both result in the same configuration folder path.
        """
        try:
            directory = tempfile.mkdtemp()

            # Set the environment variable with a path that include base folder name and call config initialization
            env_variable = '{}'.format(
                os.path.join(directory, settings.DEFAULT_CONFIG_DIR_NAME))
            os.environ[settings.DEFAULT_AIIDA_PATH_VARIABLE] = env_variable
            settings.set_configuration_directory()

            # This should have created the configuration directory in the pathpath
            config_folder = os.path.join(directory,
                                         settings.DEFAULT_CONFIG_DIR_NAME)
            self.assertTrue(os.path.isdir(config_folder))
            self.assertEqual(settings.AIIDA_CONFIG_FOLDER, config_folder)

        finally:
            shutil.rmtree(directory)
Esempio n. 3
0
    def test_environment_variable_set_single_path_with_config_folder(self):  # pylint: disable=invalid-name
        """If `AIIDA_PATH` is set and already contains a configuration folder it should simply be used."""
        try:
            directory = tempfile.mkdtemp()
            os.makedirs(os.path.join(directory, settings.DEFAULT_CONFIG_DIR_NAME))

            # Set the environment variable and call configuration initialization
            env_variable = '{}'.format(directory)
            os.environ[settings.DEFAULT_AIIDA_PATH_VARIABLE] = env_variable
            settings.set_configuration_directory()

            # This should have created the configuration directory in the pathpath
            config_folder = os.path.join(directory, settings.DEFAULT_CONFIG_DIR_NAME)
            self.assertTrue(os.path.isdir(config_folder))
            self.assertEqual(settings.AIIDA_CONFIG_FOLDER, config_folder)
        finally:
            shutil.rmtree(directory)
Esempio n. 4
0
    def test_environment_variable_set_multiple_path(self):  # pylint: disable=invalid-name
        """If `AIIDA_PATH` is set with multiple paths without actual config folder, one is created in the last."""
        try:
            directory_a = tempfile.mkdtemp()
            directory_b = tempfile.mkdtemp()
            directory_c = tempfile.mkdtemp()

            # Set the environment variable to contain three paths and call configuration initialization
            env_variable = '{}:{}:{}'.format(directory_a, directory_b, directory_c)
            os.environ[settings.DEFAULT_AIIDA_PATH_VARIABLE] = env_variable
            settings.set_configuration_directory()

            # This should have created the configuration directory in the last path
            config_folder = os.path.join(directory_c, settings.DEFAULT_CONFIG_DIR_NAME)
            self.assertTrue(os.path.isdir(config_folder))
            self.assertEqual(settings.AIIDA_CONFIG_FOLDER, config_folder)

        finally:
            shutil.rmtree(directory_a)
            shutil.rmtree(directory_b)
            shutil.rmtree(directory_c)