Skip to content

Commit

Permalink
Update pytest fixtures (#26)
Browse files Browse the repository at this point in the history
* use new pytest fixtures
* fix usage of code factory
* fix test of cli
* bump minimal aiida-core version to 1.0
* update aiida-diff version to 1.0.0
* pre-commit: move yapf to virtualenv, update version of modernizer
* fix check-syntax.sh script (would not delete files if removed from package)
  • Loading branch information
ltalirz committed Nov 1, 2019
1 parent de06660 commit ef6ac8f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 180 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Install pre-commit hooks via
# Install pre-commit hooks via:
# pre-commit install

# modernizer: make sure our code-base is Python 3 ready
- repo: https://github.com/python-modernize/python-modernize.git
sha: a234ce4e185cf77a55632888f1811d83b4ad9ef2
rev: b8e29d95ed6e0f03ab82280ec0ab36136472e9c4
hooks:
- id: python-modernize
exclude: ^docs/
args:
- --write
- --nobackups

- repo: local
# yapf = yet another python formatter
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.28.0
hooks:
# yapf = yet another python formatter
- id: yapf
name: yapf
entry: yapf
language: system
types: [python]
args: ["-i"]

- repo: local
hooks:
# prospector: collection of linters
- id: prospector
language: system
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ addons:

env:
global:
- TEST_AIIDA_BACKEND: django
- AIIDA_TEST_BACKEND: django
# show timings of tests
- PYTEST_ADDOPTS: --durations=0

Expand All @@ -27,7 +27,7 @@ matrix:
python: 2.7
env:
TEST_TYPE: tests
TEST_AIIDA_BACKEND: sqlalchemy
AIIDA_TEST_BACKEND: sqlalchemy
- name: "python-2.7 (pre-commit)"
python: 2.7
env:
Expand All @@ -43,7 +43,7 @@ matrix:
python: 3.6
env:
TEST_TYPE: tests
TEST_AIIDA_BACKEND: sqlalchemy
AIIDA_TEST_BACKEND: sqlalchemy
- name: "python-3.6 (docs)"
python: 3.6
env:
Expand Down
2 changes: 1 addition & 1 deletion aiida_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

from __future__ import absolute_import

__version__ = "1.0.0b1"
__version__ = "1.0.0"
108 changes: 0 additions & 108 deletions aiida_diff/helpers.py

This file was deleted.

4 changes: 2 additions & 2 deletions aiida_diff/tests/test_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aiida_diff import tests


def test_process(aiida_code):
def test_process(diff_code):
"""Test running a calculation
note this does not test that the expected outputs are created of output parsing"""
from aiida.plugins import DataFactory, CalculationFactory
Expand All @@ -26,7 +26,7 @@ def test_process(aiida_code):

# set up calculation
inputs = {
'code': aiida_code,
'code': diff_code,
'parameters': parameters,
'file1': file1,
'file2': file2,
Expand Down
3 changes: 2 additions & 1 deletion aiida_diff/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from __future__ import print_function
from __future__ import absolute_import

from aiida.manage.fixtures import PluginTestCase
from aiida.manage.tests.unittest_classes import PluginTestCase


class TestDataCli(PluginTestCase):
"""Test verdi data cli plugin."""
def setUp(self):
from click.testing import CliRunner
from aiida.plugins import DataFactory
Expand Down
61 changes: 8 additions & 53 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,15 @@
"""
For pytest
initialise a text database and profile
"""
"""pytest fixtures for simplified testing."""
from __future__ import absolute_import
import tempfile
import shutil
import pytest

from aiida.manage.fixtures import fixture_manager


@pytest.fixture(scope='session', autouse=True)
def aiida_profile():
"""Set up a test profile for the duration of the tests"""
with fixture_manager() as fixture_mgr:
yield fixture_mgr
pytest_plugins = ['aiida.manage.tests.pytest_fixtures']


@pytest.fixture(scope='function', autouse=True)
def clear_database(aiida_profile):
"""Clear the database after each test"""
yield
aiida_profile.reset_db()


@pytest.fixture(scope='function')
def new_workdir():
"""Get a temporary folder to use as the computer's work directory."""
dirpath = tempfile.mkdtemp()
yield dirpath
shutil.rmtree(dirpath)


@pytest.fixture(scope='function')
def aiida_localhost_computer(new_workdir):
"""Get an AiiDA computer for localhost.
:return: The computer node
:rtype: :py:class:`aiida.orm.Computer`
"""
from aiida_diff.helpers import get_computer

computer = get_computer(workdir=new_workdir)

return computer


def clear_database_auto(clear_database): # pylint: disable=unused-argument
"""Automatically clear database in between tests."""
@pytest.fixture(scope='function')
def aiida_code(aiida_localhost_computer):
"""Get an AiiDA code.
:return: The code node
:rtype: :py:class:`aiida.orm.Code`
def diff_code(aiida_local_code_factory):
"""Get a diff code.
"""
from aiida_diff.helpers import get_code

code = get_code(entry_point='diff', computer=aiida_localhost_computer)

return code
diff_code = aiida_local_code_factory(executable='diff', entry_point='diff')
return diff_code
1 change: 0 additions & 1 deletion docs/requirements_for_rtd.txt

This file was deleted.

9 changes: 5 additions & 4 deletions setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Natural Language :: English",
"Framework :: AiiDA"
],
"version": "1.0.0b1",
"version": "1.0.0",
"entry_points": {
"aiida.data": [
"diff = aiida_diff.data:DiffParameters"
Expand All @@ -31,7 +31,7 @@
"setup_requires": ["reentry"],
"reentry_register": true,
"install_requires": [
"aiida-core>=1.0.0b6,<2.0.0",
"aiida-core>=1.0.0,<2.0.0",
"six",
"voluptuous"
],
Expand All @@ -44,8 +44,9 @@
"pytest-cov>=2.6.1,<5.0.0"
],
"pre-commit": [
"pre-commit==1.17.0",
"yapf==0.28.0",
"astroid==1.6.6; python_version<'3.0'",
"astroid==2.2.5; python_version>='3.0'",
"pre-commit==1.20.0",
"prospector==1.1.7",
"pylint-django<0.9; python_version<'3.0'",
"pylint==1.9.4; python_version<'3.0'",
Expand Down

0 comments on commit ef6ac8f

Please sign in to comment.