Skip to content

Commit

Permalink
Merge pull request #2478 from yakutovicha/export_migration
Browse files Browse the repository at this point in the history
Export file migration: v0.3 to v0.4 to v0.5
  • Loading branch information
sphuber committed Jun 19, 2019
2 parents 9b1a3d0 + 6142c1d commit 32496e3
Show file tree
Hide file tree
Showing 27 changed files with 1,070 additions and 438 deletions.
5 changes: 5 additions & 0 deletions aiida/backends/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
'engine.work_chain': ['aiida.backends.tests.engine.test_work_chain'],
'engine.workfunctions': ['aiida.backends.tests.engine.test_workfunctions'],
'export_and_import': ['aiida.backends.tests.test_export_and_import'],
'export_migration.migration': ['aiida-export-migration-tests.tests.test_migration'],
'export_migration.v01_to_v02': ['aiida-export-migration-tests.tests.test_v01_to_v02'],
'export_migration.v02_to_v03': ['aiida-export-migration-tests.tests.test_v02_to_v03'],
'export_migration.v03_to_v04': ['aiida-export-migration-tests.tests.test_v03_to_v04'],
'export_migration.v04_to_v05': ['aiida-export-migration-tests.tests.test_v04_to_v05'],
'generic': ['aiida.backends.tests.test_generic'],
'manage.configuration.config.': ['aiida.backends.tests.manage.configuration.test_config'],
'manage.configuration.migrations.': ['aiida.backends.tests.manage.configuration.migrations.test_migrations'],
Expand Down
42 changes: 14 additions & 28 deletions aiida/backends/tests/cmdline/commands/test_calcjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
from __future__ import print_function
from __future__ import absolute_import

import unittest

from click.testing import CliRunner

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
from aiida.backends.tests.utils.fixtures import import_archive_fixture
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
Expand All @@ -33,9 +31,6 @@ def get_result_lines(result):
class TestVerdiCalculation(AiidaTestCase):
"""Tests for `verdi calcjob`."""

# Note remove this when reenabling the tests after solving issue #2426
# pylint: disable=no-member

@classmethod
def setUpClass(cls, *args, **kwargs):
super(TestVerdiCalculation, cls).setUpClass(*args, **kwargs)
Expand Down Expand Up @@ -96,14 +91,13 @@ def setUpClass(cls, *args, **kwargs):
calc.set_process_state(ProcessState.FINISHED)
cls.calcs.append(calc)

# Uncomment when issue 2426 is addressed
# # Load the fixture containing a single ArithmeticAddCalculation node
# import_archive_fixture('calcjob/arithmetic.add.aiida')
# Load the fixture containing a single ArithmeticAddCalculation node
import_archive('calcjob/arithmetic.add.aiida')

# # Get the imported ArithmeticAddCalculation node
# ArithmeticAddCalculation = CalculationFactory('arithmetic.add')
# calculations = orm.QueryBuilder().append(ArithmeticAddCalculation).all()[0]
# cls.arithmetic_job = calculations[0]
# Get the imported ArithmeticAddCalculation node
ArithmeticAddCalculation = CalculationFactory('arithmetic.add')
calculations = orm.QueryBuilder().append(ArithmeticAddCalculation).all()[0]
cls.arithmetic_job = calculations[0]

def setUp(self):
self.cli_runner = CliRunner()
Expand All @@ -127,7 +121,6 @@ def test_calcjob_res(self):
self.assertNotIn(self.KEY_TWO, result.output)
self.assertNotIn(self.VAL_TWO, result.output)

@unittest.skip("Reenable when issue #2426 has been solved (migrate exported files from 0.3 to 0.4)")
def test_calcjob_inputls(self):
"""Test verdi calcjob inputls"""
options = []
Expand All @@ -149,7 +142,6 @@ def test_calcjob_inputls(self):
self.assertIn('calcinfo.json', get_result_lines(result))
self.assertIn('job_tmpl.json', get_result_lines(result))

@unittest.skip("Reenable when issue #2426 has been solved (migrate exported files from 0.3 to 0.4)")
def test_calcjob_outputls(self):
"""Test verdi calcjob outputls"""
options = []
Expand All @@ -164,7 +156,6 @@ def test_calcjob_outputls(self):
self.assertIn('_scheduler-stdout.txt', get_result_lines(result))
self.assertIn('aiida.out', get_result_lines(result))

@unittest.skip("Reenable when issue #2426 has been solved (migrate exported files from 0.3 to 0.4)")
def test_calcjob_inputcat(self):
"""Test verdi calcjob inputcat"""
options = []
Expand All @@ -183,7 +174,6 @@ def test_calcjob_inputcat(self):
self.assertEqual(len(get_result_lines(result)), 1)
self.assertEqual(get_result_lines(result)[0], '2 3')

@unittest.skip("Reenable when issue #2426 has been solved (migrate exported files from 0.3 to 0.4)")
def test_calcjob_outputcat(self):
"""Test verdi calcjob outputcat"""
options = []
Expand Down Expand Up @@ -231,19 +221,15 @@ def test_calcjob_inoutputcat_old(self):
"""Test most recent process class / plug-in can be successfully used to find filenames"""

# Import old archive of ArithmeticAddCalculation
import_archive_fixture('calcjob/arithmetic.add_old.aiida')
import_archive('calcjob/arithmetic.add_old.aiida')
ArithmeticAddCalculation = CalculationFactory('arithmetic.add')
calculations = orm.QueryBuilder().append(ArithmeticAddCalculation).all()
# Uncomment when issue 2426 is addressed
# for job in calculations:
# if job[0].uuid == self.arithmetic_job.uuid:
# continue
# else:
# add_job = job[0]
# return

# Remove when issue 2426 is addressed
add_job = calculations[0][0]
for job in calculations:
if job[0].uuid == self.arithmetic_job.uuid:
continue
else:
add_job = job[0]
return

# Make sure add_job does not specify options 'input_filename' and 'output_filename'
self.assertIsNone(
Expand Down
59 changes: 22 additions & 37 deletions aiida/backends/tests/cmdline/commands/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import tempfile
import tarfile
import traceback
import unittest
import zipfile

from click.testing import CliRunner

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


def delete_temporary_file(filepath):
Expand All @@ -41,21 +41,6 @@ def delete_temporary_file(filepath):
pass


def get_archive_file(archive):
"""
Return the absolute path of the archive file used for testing purposes. The expected path for these files:
aiida.backends.tests.export_import_test_files.migrate
:param archive: the relative filename of the archive
:returns: absolute filepath of the archive test file
"""
dirpath_current = os.path.dirname(os.path.abspath(__file__))
dirpath_archive = os.path.join(dirpath_current, os.pardir, os.pardir, 'fixtures', 'export', 'migrate')

return os.path.join(dirpath_archive, archive)


class TestVerdiExport(AiidaTestCase):
"""Tests for `verdi export`."""

Expand Down Expand Up @@ -88,6 +73,7 @@ def tearDownClass(cls, *args, **kwargs):

def setUp(self):
self.cli_runner = CliRunner()
self.fixture_archive = 'export/migrate'

def test_create_file_already_exists(self):
"""Test that using a file that already exists, which is the case when using NamedTemporaryFile, will raise."""
Expand Down Expand Up @@ -155,18 +141,18 @@ def test_create_tar_gz(self):
finally:
delete_temporary_file(filename)

@unittest.skip("Reenable when issue #2426 has been solved (migrate exported files from 0.3 to 0.4)")
def test_migrate_versions_old(self):
"""Migrating archives with a version older than the current should work."""
archives = [
'export_v0.1.aiida',
'export_v0.2.aiida',
'export_v0.3.aiida'
'export_v0.1_simple.aiida',
'export_v0.2_simple.aiida',
'export_v0.3_simple.aiida',
'export_v0.4_simple.aiida'
]

for archive in archives:

filename_input = get_archive_file(archive)
filename_input = get_archive_file(archive, filepath=self.fixture_archive)
filename_output = next(tempfile._get_candidate_names()) # pylint: disable=protected-access

try:
Expand All @@ -178,16 +164,15 @@ def test_migrate_versions_old(self):
finally:
delete_temporary_file(filename_output)

@unittest.skip("Reenable when issue #2426 has been solved (migrate exported files from 0.3 to 0.4)")
def test_migrate_versions_recent(self):
"""Migrating an archive with the current version should exit with non-zero status."""
archives = [
'export_v0.4.aiida',
'export_v0.5_simple.aiida',
]

for archive in archives:

filename_input = get_archive_file(archive)
filename_input = get_archive_file(archive, filepath=self.fixture_archive)
filename_output = next(tempfile._get_candidate_names()) # pylint: disable=protected-access

try:
Expand All @@ -200,12 +185,12 @@ def test_migrate_versions_recent(self):
def test_migrate_force(self):
"""Test that passing the -f/--force option will overwrite the output file even if it exists."""
archives = [
'export_v0.1.aiida',
'export_v0.1_simple.aiida',
]

for archive in archives:

filename_input = get_archive_file(archive)
filename_input = get_archive_file(archive, filepath=self.fixture_archive)

# Using the context manager will create the file and so the command should fail
with tempfile.NamedTemporaryFile() as file_output:
Expand All @@ -226,12 +211,12 @@ def test_migrate_force(self):
def test_migrate_silent(self):
"""Test that the captured output is an empty string when the -s/--silent option is passed."""
archives = [
'export_v0.1.aiida',
'export_v0.1_simple.aiida',
]

for archive in archives:

filename_input = get_archive_file(archive)
filename_input = get_archive_file(archive, filepath=self.fixture_archive)
filename_output = next(tempfile._get_candidate_names()) # pylint: disable=protected-access

for option in ['-s', '--silent']:
Expand All @@ -248,12 +233,12 @@ def test_migrate_silent(self):
def test_migrate_tar_gz(self):
"""Test that -F/--archive-format option can be used to write a tar.gz instead."""
archives = [
'export_v0.1.aiida',
'export_v0.1_simple.aiida',
]

for archive in archives:

filename_input = get_archive_file(archive)
filename_input = get_archive_file(archive, filepath=self.fixture_archive)
filename_output = next(tempfile._get_candidate_names()) # pylint: disable=protected-access

for option in ['-F', '--archive-format']:
Expand All @@ -266,19 +251,19 @@ def test_migrate_tar_gz(self):
finally:
delete_temporary_file(filename_output)

@unittest.skip("Reenable when issue #2426 has been solved (migrate exported files from 0.3 to 0.4)")
def test_inspect(self):
"""Test the functionality of `verdi export inspect`."""
archives = [
('export_v0.1.aiida', '0.1'),
('export_v0.2.aiida', '0.2'),
('export_v0.3.aiida', '0.3'),
('export_v0.4.aiida', '0.4')
('export_v0.1_simple.aiida', '0.1'),
('export_v0.2_simple.aiida', '0.2'),
('export_v0.3_simple.aiida', '0.3'),
('export_v0.4_simple.aiida', '0.4'),
('export_v0.5_simple.aiida', '0.5')
]

for archive, version_number in archives:

filename_input = get_archive_file(archive)
filename_input = get_archive_file(archive, filepath=self.fixture_archive)

# Testing the options that will print the meta data and data respectively
for option in ['-m', '-d']:
Expand All @@ -294,7 +279,7 @@ def test_inspect(self):

def test_inspect_empty_archive(self):
"""Test the functionality of `verdi export inspect` for an empty archive."""
filename_input = get_archive_file('empty.aiida')
filename_input = get_archive_file('empty.aiida', filepath=self.fixture_archive)

options = [filename_input]
result = self.cli_runner.invoke(cmd_export.inspect, options)
Expand Down
Loading

0 comments on commit 32496e3

Please sign in to comment.