Skip to content

Commit

Permalink
qepw and qepwimmigrant test working for both django and sqlalchemy. e…
Browse files Browse the repository at this point in the history
…xpire_on_commit=False in the SqlaTestCase class
  • Loading branch information
fernandogargiulo1986 committed Dec 2, 2016
1 parent d9a757c commit f8d8b9c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 29 deletions.
18 changes: 11 additions & 7 deletions aiida/backends/sqlalchemy/tests/quantumespressopw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@
__authors__ = "The AiiDA team."


class QETestCase(SqlAlchemyTests):
class TestQEPWInputGenerationSqla(SqlAlchemyTests, TestQEPWInputGeneration):
"""
tests that are specific to Django
"""

#The setupClass is overwritten to add specific objects
@classmethod
def setUpClass(cls):
super(QETestCase, cls).setUpClass()
super(TestQEPWInputGenerationSqla, cls).setUpClass()

cls.calc_params = {
'computer': cls.computer,
'resources': {
'num_machines': 1,
'num_mpiprocs_per_machine': 1
}
}
cls.code = Code(remote_computer_exec=(cls.computer, '/x.x'))

cls.code = Code()
cls.code.set_remote_computer_exec((cls.computer, '/x.x'))
cls.code.store()


class TestQEPWInputGenerationSqla(QETestCase, TestQEPWInputGeneration):
"""
tests that are specific to Django
"""
pass

8 changes: 5 additions & 3 deletions aiida/backends/sqlalchemy/tests/quantumespressopwimmigrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from aiida.backends.sqlalchemy.tests.testbase import SqlAlchemyTests
from aiida.orm.code import Code
from aiida.backends.sqlalchemy.models.authinfo import DbAuthInfo
import aiida.backends.sqlalchemy

#Tests imports
from aiida.backends.tests.quantumespressopwimmigrant import LocalSetup, \
Expand All @@ -31,7 +32,7 @@ class LocalTestCase(SqlAlchemyTests, LocalSetup):
def setUpClass(cls):
super(LocalTestCase, cls).setUpClass()

# Change transport type to local.
# Change transport type to local
cls.computer.set_transport_type('local')

# Configure authinfo for cls.computer and cls.user.
Expand All @@ -40,8 +41,9 @@ def setUpClass(cls):
authinfo.set_auth_params({})
authinfo.save()

# Set up a code linked to cls.computer. The path is just a fake string.
cls.code = Code(remote_computer_exec=(cls.computer, '/x.x')).store()
cls.code = Code()
cls.code.set_remote_computer_exec((cls.computer, '/x.x'))
cls.code.store()

class TestPwImmigrantCalculationManualSqla(LocalTestCase,
TestPwImmigrantCalculationManual):
Expand Down
9 changes: 5 additions & 4 deletions aiida/backends/sqlalchemy/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ def find_classes(module_str):

def run_tests():
modules_str = [
# "aiida.backends.sqlalchemy.tests.query",
# "aiida.backends.sqlalchemy.tests.query",
# "aiida.backends.sqlalchemy.tests.nodes",
# "aiida.backends.sqlalchemy.tests.backup_script",
# "aiida.backends.sqlalchemy.tests.export_and_import",
"aiida.backends.sqlalchemy.tests.quantumespressopw",
"aiida.backends.sqlalchemy.tests.quantumespressopwimmigrant"
# "aiida.backends.sqlalchemy.tests.export_and_import",
"aiida.backends.sqlalchemy.tests.nwchem",
"aiida.backends.sqlalchemy.tests.quantumespressopw",
"aiida.backends.sqlalchemy.tests.quantumespressopwimmigrant"
]
for module_str in modules_str:
# Dynamically importing the module that interests us
Expand Down
7 changes: 4 additions & 3 deletions aiida/backends/sqlalchemy/tests/testbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
__authors__ = "The AiiDA team."
__version__ = "0.7.0"

# Session = sessionmaker(expire_on_commit=False)
Session = sessionmaker(expire_on_commit=True)
Session = sessionmaker(expire_on_commit=False)
# Session = sessionmaker(expire_on_commit=True)


class SqlAlchemyTests(unittest.TestCase):

# Specify the need to drop the table at the beginning of a test case
drop_all = False
drop_all = True

test_session = None

Expand Down Expand Up @@ -91,6 +91,7 @@ def _create_computer(**kwargs):
defaults.update(kwargs)
return Computer(**defaults)


@staticmethod
def inject_computer(f):
@functools.wraps(f)
Expand Down
8 changes: 4 additions & 4 deletions aiida/backends/tests/quantumespressopwimmigrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
if fnm.endswith('.in')]


class LocalSetup():
class LocalSetup(object):
"""
Setup functions that are common to all backends
"""
Expand Down Expand Up @@ -186,7 +186,7 @@ def run_tests_on_calcs_with_prefixes(self, prefixes):
)


class TestPwImmigrantCalculationManual():
class TestPwImmigrantCalculationManual(object):
"""
Tests for immigration, retrieval, and parsing of manual kpoint jobs.
"""
Expand All @@ -205,7 +205,7 @@ def test_manual(self):
self.run_tests_on_calcs_with_prefixes(manual_prefixes)


class TestPwImmigrantCalculationAutomatic():
class TestPwImmigrantCalculationAutomatic(object):
"""
Tests for immigration, retrieval, and parsing of automatic kpoint jobs.
"""
Expand All @@ -222,7 +222,7 @@ def test_automatic(self):
self.run_tests_on_calcs_with_prefixes(automatic_prefixes)


class TestPwImmigrantCalculationGamma():
class TestPwImmigrantCalculationGamma(object):
"""
Tests for immigration, retrieval, and parsing of gamma kpoint jobs.
"""
Expand Down
13 changes: 6 additions & 7 deletions aiida/orm/implementation/django/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

import copy

from django.core.exceptions import ObjectDoesNotExist
from django.db import IntegrityError, transaction
from django.db.models import F
from django.core.exceptions import ObjectDoesNotExist

from aiida.orm.implementation.general.node import AbstractNode, _NO_DEFAULT
from aiida.backends.djsite.db.models import DbLink
from aiida.backends.djsite.utils import get_automatic_user
from aiida.common.exceptions import (InternalError, ModificationNotAllowed,
NotExistent, UniquenessError)
from aiida.common.utils import get_new_uuid
from aiida.common.folders import RepositoryFolder
from aiida.common.links import LinkType
from aiida.common.lang import override

from aiida.backends.djsite.utils import get_automatic_user
from aiida.backends.djsite.db.models import DbLink
from aiida.common.links import LinkType
from aiida.common.utils import get_new_uuid
from aiida.orm.implementation.general.node import AbstractNode, _NO_DEFAULT

__copyright__ = u"Copyright (c), This file is part of the AiiDA platform. For further information please visit http://www.aiida.net/. All rights reserved."
__license__ = "MIT license, see LICENSE.txt file."
Expand Down
1 change: 1 addition & 0 deletions aiida/orm/implementation/sqlalchemy/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def set_remote_computer_exec(self, remote_computer_exec):
remote_exec_path is the absolute path of the main executable on
remote computer.
"""

if (not isinstance(remote_computer_exec, (list, tuple))
or len(remote_computer_exec) != 2):
raise ValueError("remote_computer_exec must be a list or tuple "
Expand Down
5 changes: 4 additions & 1 deletion aiida/orm/implementation/sqlalchemy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,10 @@ def store(self, with_transaction=True):
self._store_cached_input_links(with_transaction=False)

if with_transaction:
self.dbnode.session.commit()
try:
self.dbnode.session.commit()
except SQLAlchemyError as e:
self.dbnode.session.rollback()

# This is one of the few cases where it is ok to do a 'global'
# except, also because I am re-raising the exception
Expand Down

0 comments on commit f8d8b9c

Please sign in to comment.