-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add test for pgtest
argument of TemporaryProfileManager
#3486
Merged
sphuber
merged 3 commits into
aiidateam:develop
from
ltalirz:issue_3482_pgtest_argument
Nov 12, 2019
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Unittests for TestManager""" | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import absolute_import | ||
import os | ||
import unittest | ||
import warnings | ||
import sys | ||
|
||
from pgtest import pgtest | ||
|
||
from aiida.manage.tests import TemporaryProfileManager, TestManagerError, get_test_backend_name | ||
from aiida.common.utils import Capturing | ||
|
||
|
||
class TemporaryProfileManagerTestCase(unittest.TestCase): | ||
"""Test the TemporaryProfileManager class""" | ||
|
||
def setUp(self): | ||
if sys.version_info[0] >= 3: | ||
# tell unittest not to warn about running processes | ||
warnings.simplefilter('ignore', ResourceWarning) # pylint: disable=no-member,undefined-variable | ||
|
||
self.backend = get_test_backend_name() | ||
self.profile_manager = TemporaryProfileManager(backend=self.backend) | ||
|
||
def tearDown(self): | ||
self.profile_manager.destroy_all() | ||
|
||
def test_create_db_cluster(self): | ||
self.profile_manager.create_db_cluster() | ||
self.assertTrue(pgtest.is_server_running(self.profile_manager.pg_cluster.cluster)) | ||
|
||
def test_create_aiida_db(self): | ||
self.profile_manager.create_db_cluster() | ||
self.profile_manager.create_aiida_db() | ||
self.assertTrue(self.profile_manager.postgres.db_exists(self.profile_manager.profile_info['database_name'])) | ||
|
||
def test_create_use_destroy_profile2(self): | ||
""" | ||
Test temporary test profile creation | ||
|
||
* The profile gets created, the dbenv loaded | ||
* Data can be stored in the db | ||
* reset_db deletes all data added after profile creation | ||
* destroy_all removes all traces of the test run | ||
|
||
Note: This test function loads the dbenv - i.e. you cannot run similar test functions (that create profiles) | ||
in the same test session. aiida.manage.configuration.reset_profile() was not yet enough, see | ||
https://github.com/aiidateam/aiida-core/issues/3482 | ||
""" | ||
with Capturing() as output: | ||
self.profile_manager.create_profile() | ||
|
||
self.assertTrue(self.profile_manager.root_dir_ok, msg=output) | ||
self.assertTrue(self.profile_manager.config_dir_ok, msg=output) | ||
self.assertTrue(self.profile_manager.repo_ok, msg=output) | ||
from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER | ||
self.assertEqual(AIIDA_CONFIG_FOLDER, self.profile_manager.config_dir, msg=output) | ||
|
||
from aiida.orm import load_node | ||
from aiida.plugins import DataFactory | ||
data = DataFactory('dict')(dict={'key': 'value'}) | ||
data.store() | ||
data_pk = data.pk | ||
self.assertTrue(load_node(data_pk)) | ||
|
||
with self.assertRaises(TestManagerError): | ||
self.test_create_aiida_db() | ||
|
||
self.profile_manager.reset_db() | ||
with self.assertRaises(Exception): | ||
load_node(data_pk) | ||
|
||
temp_dir = self.profile_manager.root_dir | ||
self.profile_manager.destroy_all() | ||
with self.assertRaises(Exception): | ||
self.profile_manager.postgres.db_exists(self.profile_manager.dbinfo['db_name']) | ||
self.assertFalse(os.path.exists(temp_dir)) | ||
self.assertIsNone(self.profile_manager.root_dir) | ||
self.assertIsNone(self.profile_manager.pg_cluster) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use the
which
frompgtest
? And/or add another test that tests what we expect withwhich
from AiiDA is the same thatpgtest
expects. There is a tight connection between AiiDA andpgtest
now, but that might change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since pgtest is a bit more clever than the standard "which", we could do that.
I'll make the change.
I don't think that needs to be the case, and it's not what I'm testing here - I'm just trying to see of the
TemporaryProfileManager
works if I give it some valid path topg_ctl
(could be a different one than the one autodiscovered by pgtest).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main question for you was to check whether you are ok with me removing the
pgtest
argument from the internal functions of theTemporaryProfileManager
(since I guess you were the main user) - I guess as long as the functionality is still accessible from the constructor, it is fine with you, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely. I was using it from the
test_manager
, which run the constructor I think, so for me this would work nicely.