Testing infrastructure for easy testing of AiiDA plugins.
aiida.manage.tests.
ProfileManager
Bases: object
object
Wraps existing AiiDA profile.
__dict__
__init__
Use an existing profile.
profile_name – Name of the profile to be loaded
__module__
__weakref__
list of weak references to the object (if defined)
_select_db_test_case
Selects tests case for the correct database backend.
destroy_all
has_profile_open
init_db
Initialise the database state for running of tests.
Adds default user if necessary.
reset_db
TemporaryProfileManager
Bases: aiida.manage.tests.ProfileManager
aiida.manage.tests.ProfileManager
Manage the life cycle of a completely separated and temporary AiiDA environment.
No profile / database setup required Tests run via the TemporaryProfileManager never pollute the user’s working environment
No profile / database setup required
Tests run via the TemporaryProfileManager never pollute the user’s working environment
Filesystem:
temporary .aiida configuration folder temporary repository folder
temporary .aiida configuration folder
.aiida
temporary repository folder
Database:
temporary database cluster (via the pgtest package) with aiida database user with aiida_db database
temporary database cluster (via the pgtest package)
pgtest
with aiida database user
aiida
with aiida_db database
aiida_db
AiiDA:
configured to use the temporary configuration sets up a temporary profile for tests
configured to use the temporary configuration
sets up a temporary profile for tests
All of this happens automatically when using the corresponding tests classes & tests runners (unittest) or fixtures (pytest).
Example:
tests = TemporaryProfileManager(backend=backend) tests.create_aiida_db() # set up only the database tests.create_profile() # set up a profile (creates the db too if necessary) # ready for tests # run tests 1 tests.reset_db() # database ready for independent tests 2 # run tests 2 tests.destroy_all() # everything cleaned up
Construct a TemporaryProfileManager
backend – a database backend
pgtest – a dictionary of arguments to be passed to PGTest() for starting the postgresql cluster, e.g. {‘pg_ctl’: ‘/somepath/pg_ctl’}. Should usually not be necessary.
_return_dir
Return a path to a directory from the fs environment
_test_case
backend
config_dir
config_dir_ok
create_aiida_db
Create the necessary database on the temporary postgres instance.
create_db_cluster
Create the database cluster using PGTest.
create_profile
Set AiiDA to use the tests config dir and create a default profile there
Warning: the AiiDA dbenv must not be loaded when this is called!
Remove all traces of the tests run
profile_dictionary
Profile parameters.
Used to set up AiiDA profile from self.profile_info dictionary.
repo
repo_ok
root_dir
root_dir_ok
TestManager
Test manager for plugin tests.
Uses either ProfileManager for wrapping an existing profile or TemporaryProfileManager for setting up a complete temporary AiiDA environment.
For usage with pytest, see pytest_fixtures. For usage with unittest, see unittest_classes.
pytest_fixtures
unittest_classes
Initialize self. See help(type(self)) for accurate signature.
use_profile
Set up Test manager to use existing profile.
Uses aiida.manage.tests.ProfileManager internally.
profile_name – Name of existing test profile to use.
use_temporary_profile
Set up Test manager to use temporary AiiDA profile.
Uses aiida.manage.tests.TemporaryProfileManager internally.
aiida.manage.tests.TemporaryProfileManager
backend – Backend to use.
TestManagerError
Bases: Exception
Exception
Raised by TestManager in situations that may lead to inconsistent behaviour.
__str__
Return str(self).
Collection of pytest fixtures using the TestManager for easy testing of AiiDA plugins.
aiida_profile clear_database aiida_localhost aiida_local_code_factory
aiida_profile
clear_database
aiida_localhost
aiida_local_code_factory
aiida.manage.tests.pytest_fixtures.
aiida_caplog
A copy of pytest’s caplog fixture, which allows AIIDA_LOGGER to propagate.
AIIDA_LOGGER
Get an AiiDA code on localhost.
Searches in the PATH for a given executable and creates an AiiDA code with provided entry point.
Usage:
def test_1(aiida_local_code_factory): code = aiida_local_code_factory('quantumespresso.pw', '/usr/bin/pw.x') # use code for testing ...
A function get_code(entry_point, executable) that returns the Code node.
Get an AiiDA computer for localhost.
def test_1(aiida_localhost): label = aiida_localhost.get_label() # proceed to set up code or use 'aiida_local_code_factory' instead
The computer node
aiida.orm.Computer
Set up AiiDA test profile for the duration of the tests.
autouse=True
need to depend on it explicitly - it will activate as soon as you import it in your conftest.py.
conftest.py
Alias for ‘clear_database_after_test’.
Clears the database after each test. Use of the explicit ‘clear_database_after_test’ is preferred.
clear_database_after_test
Clear the database after the test.
clear_database_before_test
Clear the database before the test.
temp_dir
Get a temporary directory.
E.g. to use as the working directory of an AiiDA computer.
The path to the directory
str
temporary_event_loop
Create a temporary loop for independent test case
Test classes and test runners for testing AiiDA plugins with unittest.
aiida.manage.tests.unittest_classes.
PluginTestCase
Bases: unittest.case.TestCase
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.
TestRunner
Usage example:
MyTestCase(aiida.manage.tests.unittest_classes.PluginTestCase): def setUp(self): # load my tests data # optionally extend setUpClass / tearDownClass / tearDown if needed def test_my_plugin(self): # execute tests
setUpClass
Hook method for setting up class fixture before running tests in the class.
tearDown
Hook method for deconstructing the test fixture after testing it.
Bases: unittest.runner.TextTestRunner
unittest.runner.TextTestRunner
Testrunner for unit tests using the fixture manager.
import unittest from aiida.manage.tests.unittest_classes import TestRunner tests = unittest.defaultTestLoader.discover('.') TestRunner().run(tests)
run
Run tests using fixture manager for specified backend.
suite – A suite of tests, as returned e.g. by unittest.TestLoader.discover()
unittest.TestLoader.discover()
backend – name of database backend to be used.
profile_name – name of test profile to be used or None (will use temporary profile)