Skip to content

Commit

Permalink
Update imports in moved test files
Browse files Browse the repository at this point in the history
The unit tests that were moved in the previous commit often imported
utilities from a module that used to be located in the main package
`aiida.backends.tests.utils`. This module has also been moved to the
`tests` top level module.

These utilities should really in most cases become pytest fixtures but
that is left for a later time.
  • Loading branch information
sphuber committed Jan 16, 2020
1 parent e4c7fb5 commit 6ce6cd4
Show file tree
Hide file tree
Showing 65 changed files with 126 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ verdi daemon start 4
verdi -p test_${AIIDA_TEST_BACKEND} run .ci/test_daemon.py
verdi daemon stop

AIIDA_TEST_PROFILE=test_$AIIDA_TEST_BACKEND pytest
AIIDA_TEST_PROFILE=test_$AIIDA_TEST_BACKEND pytest tests
AIIDA_TEST_PROFILE=test_$AIIDA_TEST_BACKEND pytest .ci/pytest
pytest --noconftest .ci/test_test_manager.py
pytest --noconftest .ci/test_profile_manager.py
Expand Down
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@
aiida/plugins/entry.py|
aiida/plugins/info.py|
aiida/plugins/registry.py|
aiida/schedulers/plugins/test_direct.py|
aiida/schedulers/plugins/test_lsf.py|
aiida/schedulers/plugins/test_pbspro.py|
aiida/schedulers/plugins/test_sge.py|
aiida/schedulers/plugins/test_torque.py|
aiida/sphinxext/tests/workchain_source/conf.py|
aiida/sphinxext/tests/workchain_source_broken/conf.py|
aiida/tools/data/array/kpoints/legacy.py|
aiida/tools/data/array/kpoints/seekpath.py|
aiida/tools/data/__init__.py|
Expand All @@ -91,12 +84,19 @@
aiida/tools/dbimporters/plugins/nninc.py|
aiida/tools/dbimporters/plugins/oqmd.py|
aiida/tools/dbimporters/plugins/pcod.py|
aiida/transports/plugins/test_all_plugins.py|
aiida/transports/plugins/test_local.py|
aiida/transports/plugins/test_ssh.py|
docs/.*|
examples/.*|
tests/engine/test_work_chain.py|
tests/schedulers/test_direct.py|
tests/schedulers/test_lsf.py|
tests/schedulers/test_pbspro.py|
tests/schedulers/test_sge.py|
tests/schedulers/test_torque.py|
tests/sphinxext/workchain_source/conf.py|
tests/sphinxext/workchain_source_broken/conf.py|
tests/transports/test_all_plugins.py|
tests/transports/test_local.py|
tests/transports/test_ssh.py|
tests/test_dataclasses.py|
tests/test_nodes.py|
)$
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/testbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_backend_class(cls):
# Freeze the __impl_class after the first run
if not hasattr(cls, '__impl_class'):
if PROFILE.database_backend == BACKEND_SQLA:
from aiida.backends.sqlalchemy.tests.testbase import (SqlAlchemyTests)
from aiida.backends.sqlalchemy.testbase import SqlAlchemyTests
cls.__impl_class = SqlAlchemyTests
elif PROFILE.database_backend == BACKEND_DJANGO:
from aiida.backends.djsite.db.testbase import DjangoTests
Expand Down
2 changes: 1 addition & 1 deletion aiida/manage/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _select_db_test_case(self, backend):
from aiida.backends.djsite.db.testbase import DjangoTests
self._test_case = DjangoTests()
elif backend == BACKEND_SQLA:
from aiida.backends.sqlalchemy.tests.testbase import SqlAlchemyTests
from aiida.backends.sqlalchemy.testbase import SqlAlchemyTests
from aiida.backends.sqlalchemy import get_scoped_session

self._test_case = SqlAlchemyTests()
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
testpaths = aiida
testpaths = tests
filterwarnings =
ignore::DeprecationWarning:babel:
ignore::DeprecationWarning:django:
Expand Down
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Module for defining tests that required access to (a temporary) database."""
from aiida import __version__ as version_core

# The following statement needs to be here for the tests in `tests.plugins.test_utils.py` to work. There, some processes
# are defined in place, such as a `WorkChain` and a calcfunction and the version of their "plugin" is defined as the
# version of the top-level module in which they are defined, which is this `tests` module.
__version__ = version_core
Empty file added tests/backends/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from django.db import transaction

from aiida.backends.djsite.db.subtests.migrations.test_migrations_common import TestMigrations
from .test_migrations_common import TestMigrations

# The following sample dictionary can be used for the conversion test of attributes and extras
SAMPLE_DICT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
Tests for the migrations of the attributes, extras and settings from EAV to JSONB
Migration 0037_attributes_extras_settings_json
"""

from aiida.backends.djsite.db.subtests.migrations.test_migrations_common import TestMigrations
from aiida.backends.general.migrations.calc_state import STATE_MAPPING
from .test_migrations_common import TestMigrations


class TestLegacyJobCalcStateDataMigration(TestMigrations):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# pylint: disable=import-error,no-name-in-module,invalid-name
"""Tests for the migrations of legacy process attributes."""

from aiida.backends.djsite.db.subtests.migrations.test_migrations_common import TestMigrations
from .test_migrations_common import TestMigrations


class TestLegacyProcessAttributeDataMigration(TestMigrations):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# pylint: disable=import-error,no-name-in-module,invalid-name
"""Tests for the migrations of legacy process attributes."""

from aiida.backends.djsite.db.subtests.migrations.test_migrations_common import TestMigrations
from .test_migrations_common import TestMigrations


class TestSealUnsealedProcessesMigration(TestMigrations):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# pylint: disable=import-error,no-name-in-module,invalid-name
"""Tests for the migrations of legacy process attributes."""

from aiida.backends.djsite.db.subtests.migrations.test_migrations_common import TestMigrations
from .test_migrations_common import TestMigrations


class TestSealUnsealedProcessesMigration(TestMigrations):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestMigrations(AiidaTestCase):

@property
def app(self):
return apps.get_containing_app_config(type(self).__module__).name.split('.')[-1]
return apps.get_containing_app_config('aiida.backends.djsite.db').name.split('.')[-1]

migrate_from = None
migrate_to = None
Expand Down Expand Up @@ -96,7 +96,7 @@ def setUpBeforeMigration(self):

def _revert_database_schema(self):
"""Bring back the DB to the correct state."""
from ...migrations import LATEST_MIGRATION
from aiida.backends.djsite.db.migrations import LATEST_MIGRATION
from aiida.backends import sqlalchemy as sa

self.migrate_to = [(self.app, LATEST_MIGRATION)]
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/aiida_sqlalchemy/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from aiida.backends.general.migrations import utils
from aiida.backends.sqlalchemy import manager
from aiida.backends.sqlalchemy.models.base import Base
from aiida.backends.sqlalchemy.tests.test_utils import new_database
from aiida.backends.sqlalchemy.utils import flag_modified
from aiida.backends.testbase import AiidaTestCase
from aiida.common.utils import Capturing
from .test_utils import new_database


class TestMigrationsSQLA(AiidaTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_calcjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils.archives import import_archive
from aiida.cmdline.commands import cmd_calcjob as command
from aiida.common.datastructures import CalcJobState
from aiida.plugins import CalculationFactory
from aiida.plugins.entry_point import get_entry_point_string_from_class

from tests.utils.archives import import_archive


def get_result_lines(result):
return [e for e in result.output.split('\n') if e]
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from click.testing import CliRunner

from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils.configuration import with_temporary_config_instance
from aiida.cmdline.commands import cmd_verdi
from aiida.manage.configuration import get_config

from tests.utils.configuration import with_temporary_config_instance


class TestVerdiConfig(AiidaTestCase):
"""Tests for `verdi config`."""
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
from click.testing import CliRunner

from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils.archives import get_archive_file
from aiida.cmdline.commands import cmd_export
from aiida.tools.importexport import EXPORT_VERSION

from tests.utils.archives import get_archive_file


def delete_temporary_file(filepath):
"""Attempt to delete a file, given an absolute path. If the deletion fails because the file does not exist
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.commands import cmd_verdi
from aiida.backends.tests.utils.configuration import with_temporary_config_instance

from tests.utils.configuration import with_temporary_config_instance


class TestVerdiHelpCommand(AiidaTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from click.exceptions import BadParameter

from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils.archives import get_archive_file
from aiida.cmdline.commands import cmd_import
from aiida.orm import Group
from aiida.tools.importexport import EXPORT_VERSION

from tests.utils.archives import get_archive_file


class TestVerdiImport(AiidaTestCase):
"""Tests for `verdi import`."""
Expand Down
5 changes: 3 additions & 2 deletions tests/cmdline/commands/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

from click.testing import CliRunner
from tornado import gen
import plumpy
import kiwipy
import plumpy

from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils import processes as test_processes
from aiida.cmdline.commands import cmd_process
from aiida.common.links import LinkType
from aiida.common.log import LOG_LEVEL_REPORT
from aiida.manage.manager import get_manager
from aiida.orm import WorkflowNode, WorkFunctionNode, WorkChainNode

from tests.utils import processes as test_processes


def get_result_lines(result):
return [e for e in result.output.split('\n') if e]
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

from aiida.backends.testbase import AiidaPostgresTestCase
from aiida.cmdline.commands import cmd_profile, cmd_verdi
from aiida.backends.tests.utils.configuration import create_mock_profile, with_temporary_config_instance
from aiida.manage import configuration

from tests.utils.configuration import create_mock_profile, with_temporary_config_instance


class TestVerdiProfileSetup(AiidaPostgresTestCase):
"""Tests for `verdi profile`."""
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
from aiida import orm
from aiida.backends import BACKEND_DJANGO
from aiida.backends.testbase import AiidaPostgresTestCase
from aiida.backends.tests.utils.configuration import with_temporary_config_instance
from aiida.cmdline.commands import cmd_setup
from aiida.manage import configuration
from aiida.manage.external.postgres import Postgres

from tests.utils.configuration import with_temporary_config_instance


class TestVerdiSetup(AiidaPostgresTestCase):
"""Tests for `verdi setup` and `verdi quicksetup`."""
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.commands import cmd_status
from aiida.backends.tests.utils.configuration import with_temporary_config_instance

from tests.utils.configuration import with_temporary_config_instance


class TestVerdiStatus(AiidaTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/cmdline/commands/test_verdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
from click.testing import CliRunner

from aiida import get_version
from aiida.backends.tests.utils.configuration import with_temporary_config_instance
from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.commands import cmd_verdi

from tests.utils.configuration import with_temporary_config_instance


class TestVerdi(AiidaTestCase):
"""Tests for `verdi`."""
Expand Down
Empty file.
3 changes: 1 addition & 2 deletions tests/cmdline/params/options/test_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Unit tests for the ConditionalOption."""

import unittest

import click
from click.testing import CliRunner

from .conditional import ConditionalOption
from aiida.cmdline.params.options.conditional import ConditionalOption


class ConditionalOptionTest(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/cmdline/params/options/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from click.testing import CliRunner
from click.types import IntParamType

from . import NON_INTERACTIVE
from .interactive import InteractiveOption
from aiida.cmdline.params.options import NON_INTERACTIVE
from aiida.cmdline.params.options.interactive import InteractiveOption


class Only42IntParamType(IntParamType):
Expand Down
2 changes: 1 addition & 1 deletion tests/engine/test_calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def execution_counter_calcfunction(data):
class TestCalcFunction(AiidaTestCase):
"""Tests for calcfunctions.
.. note: tests common to all process functions should go in `aiida.backends.tests.work.test_process_function.py`
.. note: tests common to all process functions should go in `tests.engine.test_process_function.py`
"""

def setUp(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/engine/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from tornado import gen

from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils import processes as test_processes
from aiida.engine import processes, run
from aiida.manage.manager import get_manager

from tests.utils import processes as test_processes


class TestWf(AiidaTestCase):
"""Test process futures."""
Expand Down
3 changes: 2 additions & 1 deletion tests/engine/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import plumpy

from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils.processes import DummyProcess
from aiida.engine.persistence import AiiDAPersister
from aiida.engine import Process, run

from tests.utils.processes import DummyProcess


class TestProcess(AiidaTestCase):
"""Test the basic saving and loading of process states."""
Expand Down
3 changes: 2 additions & 1 deletion tests/engine/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils import processes as test_processes
from aiida.common.lang import override
from aiida.engine import ExitCode, ExitCodesNamespace, Process, run, run_get_pk, run_get_node
from aiida.engine.processes.ports import PortNamespace
from aiida.manage.caching import enable_caching
from aiida.plugins import CalculationFactory

from tests.utils import processes as test_processes


class NameSpacedProcess(Process):
"""Name spaced process."""
Expand Down
5 changes: 3 additions & 2 deletions tests/engine/test_rmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
"""Module to test RabbitMQ."""
import datetime

import plumpy
from tornado import gen
import plumpy

from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils import processes as test_processes
from aiida.engine import ProcessState, submit
from aiida.manage.manager import get_manager
from aiida.orm import Int

from tests.utils import processes as test_processes


class TestProcessControl(AiidaTestCase):
"""Test AiiDA's RabbitMQ functionalities."""
Expand Down
Loading

0 comments on commit 6ce6cd4

Please sign in to comment.