Ejemplo n.º 1
0
    def test_query_string(self):
        """
        This method tests that the query_string method behaves as expected.
        """
        from aiida.manage.backup import backup_utils

        # None should be returned when empty answer and empty default
        # answer is given
        backup_utils.input = lambda _: ''
        self.assertIsNone(backup_utils.query_string('', ''))

        # If no answer is given then the default answer should be returned
        backup_utils.input = lambda _: ''
        self.assertEqual(backup_utils.query_string('', 'Def_answer'),
                         'Def_answer')

        # The answer should be returned when the an answer is given by
        # the user
        backup_utils.input = lambda _: 'Usr_answer'
        self.assertEqual(backup_utils.query_string('', 'Def_answer'),
                         'Usr_answer')
Ejemplo n.º 2
0
    def create_dir(self, question, dir_path):
        """Create the directories for the backup folder and return its path."""
        final_path = utils.query_string(question, dir_path)

        if not os.path.exists(final_path):
            if utils.query_yes_no("The path {} doesn't exist. Should it be created?".format(final_path), 'yes'):
                try:
                    os.makedirs(final_path)
                except OSError:
                    self._logger.error('Error creating the path %s.', final_path)
                    raise
        return final_path