aiida.manage.tests package¶
Testing infrastructure for easy testing of AiiDA plugins.
-
class
aiida.manage.tests.
TestManager
[source]¶ Bases:
object
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, seeunittest_classes
.-
__dict__
= mappingproxy({'__module__': 'aiida.manage.tests', '__doc__': '\n Test manager for plugin tests.\n\n Uses either ProfileManager for wrapping an existing profile or TemporaryProfileManager for setting up a complete\n temporary AiiDA environment.\n\n For usage with pytest, see :py:class:`~aiida.manage.tests.pytest_fixtures`.\n For usage with unittest, see :py:class:`~aiida.manage.tests.unittest_classes`.\n ', '__init__': <function TestManager.__init__>, 'use_temporary_profile': <function TestManager.use_temporary_profile>, 'use_profile': <function TestManager.use_profile>, 'has_profile_open': <function TestManager.has_profile_open>, 'reset_db': <function TestManager.reset_db>, 'destroy_all': <function TestManager.destroy_all>, '__dict__': <attribute '__dict__' of 'TestManager' objects>, '__weakref__': <attribute '__weakref__' of 'TestManager' objects>})¶
-
__module__
= 'aiida.manage.tests'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
use_profile
(profile_name)[source]¶ Set up Test manager to use existing profile.
Uses
aiida.manage.tests.ProfileManager
internally.- Parameters
profile_name – Name of existing test profile to use.
-
use_temporary_profile
(backend=None, pgtest=None)[source]¶ Set up Test manager to use temporary AiiDA profile.
Uses
aiida.manage.tests.TemporaryProfileManager
internally.- Parameters
backend – Backend to use.
pgtest – parameters for pgtest.pgtest.PGTest
-
-
exception
aiida.manage.tests.
TestManagerError
(msg)[source]¶ Bases:
Exception
Raised by TestManager in situations that may lead to inconsistent behaviour.
-
__module__
= 'aiida.manage.tests'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
aiida.manage.tests.
ProfileManager
(profile_name)[source]¶ Bases:
object
Wraps existing AiiDA profile.
-
__dict__
= mappingproxy({'__module__': 'aiida.manage.tests', '__doc__': '\n Wraps existing AiiDA profile.\n ', '__init__': <function ProfileManager.__init__>, '_select_db_test_case': <function ProfileManager._select_db_test_case>, 'reset_db': <function ProfileManager.reset_db>, 'init_db': <function ProfileManager.init_db>, 'has_profile_open': <function ProfileManager.has_profile_open>, 'destroy_all': <function ProfileManager.destroy_all>, '__dict__': <attribute '__dict__' of 'ProfileManager' objects>, '__weakref__': <attribute '__weakref__' of 'ProfileManager' objects>})¶
-
__init__
(profile_name)[source]¶ Use an existing profile.
- Parameters
profile_name – Name of the profile to be loaded
-
__module__
= 'aiida.manage.tests'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
aiida.manage.tests.
TemporaryProfileManager
(backend='django')[source]¶ Bases:
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
Filesystem:
temporary
.aiida
configuration foldertemporary repository folder
Database:
temporary database cluster (via the
pgtest
package)with
aiida
database userwith
aiida_db
database
AiiDA:
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
-
__init__
(backend='django')[source]¶ Use an existing profile.
- Parameters
profile_name – Name of the profile to be loaded
-
__module__
= 'aiida.manage.tests'¶
-
_test_case
= None¶
-
property
backend
¶
-
property
config_dir
¶
-
property
config_dir_ok
¶
-
create_aiida_db
(pgtest=None)[source]¶ Create the necessary database on the temporary postgres instance.
By utilizing pgtest it is possible to forward initialization arguments to PGTest().
- Parameters
pgtest – a dictionary containing input to PGTest()
-
create_db_cluster
(pgtest=None)[source]¶ Create the database cluster using PGTest.
- Parameters
pgtest – a dictionary containing input to PGTest()
-
create_profile
(pgtest=None)[source]¶ 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! :param pgtest: a dictionary containing input to PGTest()
-
property
profile_dictionary
¶ Profile parameters.
Used to set up AiiDA profile from self.profile_info dictionary.
-
property
repo
¶
-
property
root_dir
¶
-
property
root_dir_ok
¶
Submodules¶
Collection of pytest fixtures using the TestManager for easy testing of AiiDA plugins.
aiida_profile
clear_database
aiida_localhost
aiida_local_code_factory
-
aiida.manage.tests.pytest_fixtures.
aiida_local_code_factory
(aiida_localhost)[source]¶ 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('pw.x', 'quantumespresso.pw') # use code for testing ...
- Returns
A function get_code(executable, entry_point) that returns the Code node.
- Return type
object
-
aiida.manage.tests.pytest_fixtures.
aiida_localhost
(temp_dir)[source]¶ Get an AiiDA computer for localhost.
Usage:
def test_1(aiida_localhost): name = aiida_localhost.get_name() # proceed to set up code or use 'aiida_local_code_factory' instead
- Returns
The computer node
- Return type
-
aiida.manage.tests.pytest_fixtures.
aiida_profile
()[source]¶ Set up AiiDA test profile for the duration of the tests.
- Note: scope=’session’ limits this fixture to run once per session. Thanks to
autouse=True
, you don’t actually need to depend on it explicitly - it will activate as soon as you import it in your
conftest.py
.
- Note: scope=’session’ limits this fixture to run once per session. Thanks to
-
aiida.manage.tests.pytest_fixtures.
clear_database
(aiida_profile)[source]¶ Clear the database after each test.
-
aiida.manage.tests.pytest_fixtures.
temp_dir
()[source]¶ Get a temporary directory.
E.g. to use as the working directory of an AiiDA computer.
- Returns
The path to the directory
- Return type
str
Test classes and test runners for testing AiiDA plugins with unittest.
-
class
aiida.manage.tests.unittest_classes.
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.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
-
__module__
= 'aiida.manage.tests.unittest_classes'¶
-
backend
= None¶
-
-
class
aiida.manage.tests.unittest_classes.
TestRunner
(stream=None, descriptions=True, verbosity=1, failfast=False, buffer=False, resultclass=None, warnings=None, *, tb_locals=False)[source]¶ Bases:
unittest.runner.TextTestRunner
Testrunner for unit tests using the fixture manager.
Usage example:
import unittest from aiida.manage.tests.unittest_classes import TestRunner tests = unittest.defaultTestLoader.discover('.') TestRunner().run(tests)
-
__module__
= 'aiida.manage.tests.unittest_classes'¶
-
run
(suite, backend=None, profile_name=None)[source]¶ Run tests using fixture manager for specified backend.
- Parameters
suite – A suite of tests, as returned e.g. by
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)
-