aiida.manage package¶
Managing an AiiDA instance:
- configuration file
- profiles
- databases
- repositories
- external components (such as Postgres, RabbitMQ)
Note
Modules in this sub package may require the database environment to be loaded
Subpackages¶
Submodules¶
Definition of caching mechanism and configuration for calculations.
-
aiida.manage.caching.
get_use_cache
(*args, **kwargs)[source]¶ Return whether the caching mechanism should be used for the given node class according to the configuration.
Parameters: node_class – the Node class or sub class to check if enabled for caching Returns: boolean, True if caching is enabled, False otherwise Raises: ValueError – if the configuration is invalid by defining the class both enabled and disabled
-
aiida.manage.caching.
enable_caching
(*args, **kwds)[source]¶ Context manager to enable caching, either for a specific node class, or globally. Note that this does not affect the behavior of the daemon, only the local Python instance.
Parameters: node_class – Node class for which caching should be enabled.
-
aiida.manage.caching.
disable_caching
(*args, **kwds)[source]¶ Context manager to disable caching, either for a specific node class, or globally. Note that this does not affect the behavior of the daemon, only the local Python instance.
Parameters: node_class – Node class for which caching should be disabled.
Testing tools for related projects like plugins.
Fixtures (pytest) and specific test classes & test runners (unittest) that set up a complete temporary AiiDA environment for plugin tests.
Filesystem:
- temporary config (
.aiida
) folder- temporary repository folder
Database:
- temporary database cluster via the
pgtest
package- with aiida database user
- with aiida_db database
AiiDA:
- set to use the temporary config folder
- create and configure a profile
-
exception
aiida.manage.fixtures.
FixtureError
(msg)[source]¶ Bases:
exceptions.Exception
Raised by FixtureManager, when it encounters a situation in which consistent behaviour can not be guaranteed
-
__module__
= 'aiida.manage.fixtures'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
aiida.manage.fixtures.
FixtureManager
[source]¶ Bases:
object
Manage the life cycle of a completely separated and temporary AiiDA environment
- No previously created database of profile is required to run tests using this environment
- Tests using this environment will never pollute the user’s work environment
Example:
fixtures = FixtureManager() fixtures.create_aiida_db() # set up only the database fixtures.create_profile() # set up a profile (creates the db too if necessary) # ready for testing # run test 1 fixtures.reset_db() # database ready for independent test 2 # run test 2 fixtures.destroy_all() # everything cleaned up
Usage (unittest): See the
PluginTestCase
and theTestRunner
.Usage (pytest):
import pytest @pytest.fixture(scope='session') def aiida_profile(): # set up a test profile for the duration of the tests with aiida.manage.fixtures.fixture_manager() as fixture_manager: yield fixture_manager @pytest.fixture(scope='function') def new_database(aiida_profile): # clear the database after each test yield aiida_profile aiida_profile.reset_db() def test_my_stuff(new_database): # run a test
-
__dict__
= dict_proxy({'profile': <property object>, '__module__': 'aiida.manage.fixtures', 'create_aiida_db': <function create_aiida_db>, 'root_dir': <property object>, '__dict__': <attribute '__dict__' of 'FixtureManager' objects>, 'config_dir_ok': <property object>, 'create_db_cluster': <function create_db_cluster>, 'repo': <property object>, 'db_pass': <property object>, 'last_name': <property object>, 'create_profile': <function create_profile>, 'db_port': <property object>, 'config_dir': <property object>, 'institution': <property object>, '__init__': <function __init__>, 'backend': <property object>, '__weakref__': <attribute '__weakref__' of 'FixtureManager' objects>, 'first_name': <property object>, 'has_profile_open': <function has_profile_open>, 'db_user': <property object>, 'init_db': <staticmethod object>, 'repo_ok': <function repo_ok>, '_backend': <property object>, '_create_test_case': <function _create_test_case>, '__doc__': "\n Manage the life cycle of a completely separated and temporary AiiDA environment\n\n * No previously created database of profile is required to run tests using this environment\n * Tests using this environment will never pollute the user's work environment\n\n Example::\n\n fixtures = FixtureManager()\n fixtures.create_aiida_db() # set up only the database\n fixtures.create_profile() # set up a profile (creates the db too if necessary)\n\n # ready for testing\n\n # run test 1\n\n fixtures.reset_db()\n # database ready for independent test 2\n\n # run test 2\n\n fixtures.destroy_all()\n # everything cleaned up\n\n Usage (unittest): See the :py:class:`PluginTestCase` and the :py:class:`TestRunner`.\n\n\n Usage (pytest)::\n\n import pytest\n\n @pytest.fixture(scope='session')\n def aiida_profile():\n # set up a test profile for the duration of the tests\n with aiida.manage.fixtures.fixture_manager() as fixture_manager:\n yield fixture_manager\n\n @pytest.fixture(scope='function')\n def new_database(aiida_profile):\n # clear the database after each test\n yield aiida_profile\n aiida_profile.reset_db()\n\n def test_my_stuff(new_database):\n # run a test\n\n ", 'db_name': <property object>, '_test_case': None, 'destroy_all': <function destroy_all>, 'reset_db': <function reset_db>, 'db_host': <property object>, 'root_dir_ok': <property object>, 'email': <property object>, '_return_dir': <function _return_dir>})¶
-
__module__
= 'aiida.manage.fixtures'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
_backend
¶ Get the backend
-
_create_test_case
()[source]¶ Create the test case for the correct backend which will be used to clean up
-
_test_case
= None¶
-
backend
¶
-
config_dir
¶
-
config_dir_ok
¶
-
create_profile
()[source]¶ Set AiiDA to use the test config dir and create a default profile there
Warning: the AiiDA dbenv must not be loaded when this is called!
-
db_host
¶
-
db_name
¶
-
db_pass
¶
-
db_port
¶
-
db_user
¶
-
email
¶
-
first_name
¶
-
institution
¶
-
last_name
¶
-
profile
¶ Profile parameters
-
repo
¶
-
root_dir
¶
-
root_dir_ok
¶
-
class
aiida.manage.fixtures.
PluginTestCase
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Set up a complete temporary AiiDA environment for plugin tests.
Note: This test class needs to be run through the
TestRunner
and will not work simply with python -m unittest discover.Usage example:
MyTestCase(aiida.manage.fixtures.PluginTestCase): def setUp(self): # load my test data # optionally extend setUpClass / tearDownClass / tearDown if needed def test_my_plugin(self): # execute tests
-
__module__
= 'aiida.manage.fixtures'¶
-
backend
= None¶
-
-
class
aiida.manage.fixtures.
TestRunner
(stream=<open file '<stderr>', mode 'w'>, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None)[source]¶ Bases:
unittest.runner.TextTestRunner
Testrunner for unit tests using the fixture manager.
Usage example:
import unittest from aiida.manage.fixtures import TestRunner tests = unittest.defaultTestLoader.discover('.') TestRunner().run(tests)
-
__module__
= 'aiida.manage.fixtures'¶
-
-
aiida.manage.fixtures.
fixture_manager
(*args, **kwds)[source]¶ Context manager for FixtureManager objects
Example test runner (unittest):
with fixture_manager(backend) as fixture_mgr: # ready for tests # everything cleaned up
Example fixture (pytest):
def aiida_profile(): with fixture_manager(backend) as fixture_mgr: yield fixture_mgr
Parameters: backend – database backend, either BACKEND_SQLA or BACKEND_DJANGO
AiiDA manager for global settings