Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse functionality between AiidaTestCase and pytest fixtures #4781

Closed
wants to merge 5 commits into from

Conversation

ltalirz
Copy link
Member

@ltalirz ltalirz commented Feb 25, 2021

  • add a User.orm.objects.get_or_create_default method that can be used anywhere (verdi setup, AiidaTestCase, pytest fixtures, ...)
  • move the only remaining method of the test backend class (clean_db) to a private method of the backend (could also be standalone if that is preferred)

@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #4781 (c975336) into develop (c07e3ef) will decrease coverage by 0.01%.
The diff coverage is 77.28%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4781      +/-   ##
===========================================
- Coverage    79.56%   79.55%   -0.00%     
===========================================
  Files          515      515              
  Lines        36812    36806       -6     
===========================================
- Hits         29285    29279       -6     
  Misses        7527     7527              
Flag Coverage Δ
django 74.23% <77.28%> (-0.02%) ⬇️
sqlalchemy 73.15% <77.28%> (-<0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/manage/tests/__init__.py 88.43% <ø> (-0.10%) ⬇️
aiida/orm/users.py 78.03% <70.59%> (-3.22%) ⬇️
aiida/backends/testbase.py 93.75% <100.00%> (+0.96%) ⬆️
aiida/transports/plugins/local.py 81.80% <0.00%> (+0.26%) ⬆️
aiida/engine/daemon/client.py 76.15% <0.00%> (+1.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c07e3ef...ccca6f6. Read the comment docs.

@chrisjsewell
Copy link
Member

note in #4782 I'm trying to remove all AiidaTestCase 😄 so this will feed into it

@ltalirz
Copy link
Member Author

ltalirz commented Feb 25, 2021

Thanks, yes I've seen - the changes made here are still relevant I think, and I will then abstain from any work converting the aiidatestcase to pytest.

This reminds me - I'm not sure whether we actually can just remove the aiidatestcase entirely before 2.0.0 since it's being used by a couple of plugins https://github.com/search?q=aiidatestcase&type=code

I will check whether any of those are aiida 1 compatible (and whether any of them used the create_user / create_computer methods I deleted in c07e3ef )

@ltalirz
Copy link
Member Author

ltalirz commented Feb 25, 2021

AiidA 1.0 plugins using aiidatestcase:

https://github.com/dev-zero/aiida-gaussian-datatypes/blob/c069c35f9738541d5aee38a37837e4cb666e3335/tests/test_cli.py
https://github.com/zhubonan/aiida-castep/blob/0f172bff7a2f78b5556c91b94d870ac791f171b3/aiida_castep/tests/dbtests/dbtestcalculation.py

P.S. No sign of the create_computer and create_user functions being used (but I could easily reintroduce them for backwards compatibility)

@ltalirz
Copy link
Member Author

ltalirz commented Feb 25, 2021

I.e. we should not delete it (but of course we can still migrate our internal tests).

@chrisjsewell
Copy link
Member

All of this has been quite radically changed in #5330 😬

Note also, we are now relatively close to removing AiidaTestCase usage:

217 results - 74 files

aiida/backends/testbase.py:
   33: class AiidaTestCase(unittest.TestCase):
  138: class AiidaPostgresTestCase(AiidaTestCase):

tests/test_calculation_node.py:
  12: from aiida.backends.testbase import AiidaTestCase
  18: class TestProcessNode(AiidaTestCase):

tests/test_dataclasses.py:
    18: from aiida.backends.testbase import AiidaTestCase
    67: class TestCifData(AiidaTestCase):
   770: class TestKindValidSymbols(AiidaTestCase):
   794: class TestSiteValidWeights(AiidaTestCase):
   841: class TestKindTestGeneral(AiidaTestCase):
   904: class TestKindTestMasses(AiidaTestCase):
   944: class TestStructureDataInit(AiidaTestCase):
  1051: class TestStructureData(AiidaTestCase):
  1778: class TestStructureDataLock(AiidaTestCase):
  1826: class TestStructureDataReload(AiidaTestCase):
  1924: class TestStructureDataFromAse(AiidaTestCase):
  2107: class TestStructureDataFromPymatgen(AiidaTestCase):
  2302: class TestPymatgenFromStructureData(AiidaTestCase):
  2537: class TestArrayData(AiidaTestCase):
  2659: class TestTrajectoryData(AiidaTestCase):
  3071: class TestKpointsData(AiidaTestCase):
  3271: class TestSpglibTupleConversion(AiidaTestCase):
  3423: class TestSeekpathExplicitPath(AiidaTestCase):
  3506: class TestSeekpathPath(AiidaTestCase):
  3583: class TestBandsData(AiidaTestCase):

tests/test_dbimporters.py:
   13: from aiida.backends.testbase import AiidaTestCase
   17: class TestCodDbImporter(AiidaTestCase):
  163: class TestTcodDbImporter(AiidaTestCase):
  199: class TestPcodDbImporter(AiidaTestCase):
  222: class TestMpodDbImporter(AiidaTestCase):
  245: class TestNnincDbImporter(AiidaTestCase):

tests/test_generic.py:
  13: from aiida.backends.testbase import AiidaTestCase
  16: class TestCode(AiidaTestCase):
  93: class TestBool(AiidaTestCase):

tests/test_nodes.py:
    20: from aiida.backends.testbase import AiidaTestCase
    26: class TestNodeIsStorable(AiidaTestCase):
    52: class TestNodeCopyDeepcopy(AiidaTestCase):
    68: class TestNodeHashing(AiidaTestCase):
   136: class TestTransitiveNoLoops(AiidaTestCase):
   157: class TestTypes(AiidaTestCase):
   175: class TestQueryWithAiidaObjects(AiidaTestCase):
   232: class TestNodeBasic(AiidaTestCase):
  1206: class TestSubNodesAndLinks(AiidaTestCase):
  1521: class TestNodeDeletion(AiidaTestCase):

tests/backends/aiida_sqlalchemy/test_nodes.py:
  14: from aiida.backends.testbase import AiidaTestCase
  18: class TestNodeBasicSQLA(AiidaTestCase):

tests/backends/aiida_sqlalchemy/test_query.py:
  12: from aiida.backends.testbase import AiidaTestCase
  16: class TestQueryBuilderSQLA(AiidaTestCase):
  30: class QueryBuilderLimitOffsetsTestSQLA(AiidaTestCase):

tests/backends/aiida_sqlalchemy/test_schema.py:
  18: from aiida.backends.testbase import AiidaTestCase
  25: class TestRelationshipsSQLA(AiidaTestCase):

tests/cmdline/commands/test_calcjob.py:
  17: from aiida.backends.testbase import AiidaTestCase
  30: class TestVerdiCalculation(AiidaTestCase):

tests/cmdline/commands/test_computer.py:
   20: from aiida.backends.testbase import AiidaTestCase
  341: class TestVerdiComputerConfigure(AiidaTestCase):
  556: class TestVerdiComputerCommands(AiidaTestCase):

tests/cmdline/commands/test_data.py:
   26: from aiida.backends.testbase import AiidaTestCase
  193: class TestVerdiData(AiidaTestCase):
  222: class TestVerdiDataArray(AiidaTestCase):
  247: class TestVerdiDataBands(AiidaTestCase, DummyVerdiDataListable):
  385: class TestVerdiDataDict(AiidaTestCase):
  414: class TestVerdiDataRemote(AiidaTestCase):
  480: class TestVerdiDataTrajectory(AiidaTestCase, DummyVerdiDataListable, DummyVerdiDataExportable):
  580: class TestVerdiDataStructure(AiidaTestCase, DummyVerdiDataListable, DummyVerdiDataExportable):
  845: class TestVerdiDataCif(AiidaTestCase, DummyVerdiDataListable, DummyVerdiDataExportable):
  964: class TestVerdiDataSinglefile(AiidaTestCase, DummyVerdiDataListable, DummyVerdiDataExportable):
  995: class TestVerdiDataUpf(AiidaTestCase):

tests/cmdline/commands/test_group.py:
  12: from aiida.backends.testbase import AiidaTestCase
  18: class TestVerdiGroup(AiidaTestCase):

tests/cmdline/commands/test_help.py:
  14: from aiida.backends.testbase import AiidaTestCase
  19: class TestVerdiHelpCommand(AiidaTestCase):

tests/cmdline/commands/test_node.py:
   22: from aiida.backends.testbase import AiidaTestCase
   30: class TestVerdiNode(AiidaTestCase):
  275: class TestVerdiGraph(AiidaTestCase):
  452: class TestVerdiUserCommand(AiidaTestCase):
  496: class TestVerdiRehash(AiidaTestCase):

tests/cmdline/commands/test_process.py:
   21: from aiida.backends.testbase import AiidaTestCase
   33: class TestVerdiProcess(AiidaTestCase):
  339: class TestVerdiProcessCallRoot(AiidaTestCase):

tests/cmdline/commands/test_run.py:
  17: from aiida.backends.testbase import AiidaTestCase
  22: class TestVerdiRun(AiidaTestCase):
  75: class TestAutoGroups(AiidaTestCase):

tests/cmdline/commands/test_user.py:
  15: from aiida.backends.testbase import AiidaTestCase
  32: class TestVerdiUserCommand(AiidaTestCase):

tests/cmdline/params/types/test_calculation.py:
  12: from aiida.backends.testbase import AiidaTestCase
  18: class TestCalculationParamType(AiidaTestCase):

tests/cmdline/params/types/test_data.py:
  12: from aiida.backends.testbase import AiidaTestCase
  18: class TestDataParamType(AiidaTestCase):

tests/cmdline/params/types/test_identifier.py:
  14: from aiida.backends.testbase import AiidaTestCase
  19: class TestIdentifierParamType(AiidaTestCase):

tests/cmdline/params/types/test_node.py:
  11: from aiida.backends.testbase import AiidaTestCase
  17: class TestNodeParamType(AiidaTestCase):

tests/cmdline/params/types/test_path.py:
  11: from aiida.backends.testbase import AiidaTestCase
  15: class TestPath(AiidaTestCase):

tests/cmdline/params/types/test_plugin.py:
  14: from aiida.backends.testbase import AiidaTestCase
  19: class TestPluginParamType(AiidaTestCase):

tests/common/test_hashing.py:
   29: from aiida.backends.testbase import AiidaTestCase
  237: class CheckDBRoundTrip(AiidaTestCase):

tests/common/test_links.py:
  12: from aiida.backends.testbase import AiidaTestCase
  16: class TestValidateLinkLabel(AiidaTestCase):

tests/engine/test_calcfunctions.py:
  13: from aiida.backends.testbase import AiidaTestCase
  42: class TestCalcFunction(AiidaTestCase):

tests/engine/test_class_loader.py:
  12: from aiida.backends.testbase import AiidaTestCase
  17: class TestCalcJob(AiidaTestCase):

tests/engine/test_futures.py:
  15: from aiida.backends.testbase import AiidaTestCase
  22: class TestWf(AiidaTestCase):

tests/engine/test_launch.py:
   14: from aiida.backends.testbase import AiidaTestCase
   68: class TestLaunchers(AiidaTestCase):
  149: class TestLaunchersDryRun(AiidaTestCase):

tests/engine/test_manager.py:
  15: from aiida.backends.testbase import AiidaTestCase
  21: class TestJobManager(AiidaTestCase):
  50: class TestJobsList(AiidaTestCase):

tests/engine/test_persistence.py:
  14: from aiida.backends.testbase import AiidaTestCase
  21: class TestProcess(AiidaTestCase):
  45: class TestAiiDAPersister(AiidaTestCase):

tests/engine/test_ports.py:
  12: from aiida.backends.testbase import AiidaTestCase
  17: class TestInputPort(AiidaTestCase):
  44: class TestPortNamespace(AiidaTestCase):

tests/engine/test_process_function.py:
  14: from aiida.backends.testbase import AiidaTestCase
  27: class TestProcessFunction(AiidaTestCase):

tests/engine/test_process_spec.py:
  12: from aiida.backends.testbase import AiidaTestCase
  17: class TestProcessSpec(AiidaTestCase):

tests/engine/test_process.py:
  19: from aiida.backends.testbase import AiidaTestCase
  40: class TestProcessNamespace(AiidaTestCase):
  98: class TestProcess(AiidaTestCase):

tests/engine/test_rmq.py:
  16: from aiida.backends.testbase import AiidaTestCase
  24: class TestProcessControl(AiidaTestCase):

tests/engine/test_run.py:
  13: from aiida.backends.testbase import AiidaTestCase
  20: class TestRun(AiidaTestCase):

tests/engine/test_transport.py:
  14: from aiida.backends.testbase import AiidaTestCase
  18: class TestTransportQueue(AiidaTestCase):

tests/engine/test_utils.py:
  17: from aiida.backends.testbase import AiidaTestCase
  25: class TestExponentialBackoffRetry(AiidaTestCase):
  70: class TestUtils(AiidaTestCase):
  98: class TestInterruptable(AiidaTestCase):

tests/engine/test_work_chain.py:
    19: from aiida.backends.testbase import AiidaTestCase
   190: class TestExitStatus(AiidaTestCase):
   272: class TestContext(AiidaTestCase):
   294: class TestWorkchain(AiidaTestCase):
  1042: class TestWorkChainAbort(AiidaTestCase):
  1119: class TestWorkChainAbortChildren(AiidaTestCase):
  1212: class TestImmutableInputWorkchain(AiidaTestCase):
  1318: class TestSerializeWorkChain(AiidaTestCase):
  1445: class TestWorkChainExpose(AiidaTestCase):
  1556: class TestWorkChainMisc(AiidaTestCase):
  1593: class TestDefaultUniqueness(AiidaTestCase):

tests/engine/test_workfunctions.py:
  13: from aiida.backends.testbase import AiidaTestCase
  21: class TestWorkFunction(AiidaTestCase):

tests/engine/daemon/test_client.py:
  14: from aiida.backends.testbase import AiidaTestCase
  18: class TestDaemonClient(AiidaTestCase):

tests/engine/processes/calcjobs/test_calc_job.py:
   23: from aiida.backends.testbase import AiidaTestCase
  171: class TestCalcJob(AiidaTestCase):
  787: class TestImport(AiidaTestCase):

tests/engine/processes/workchains/test_utils.py:
  14: from aiida.backends.testbase import AiidaTestCase
  25: class TestRegisterProcessHandler(AiidaTestCase):

tests/manage/configuration/test_options.py:
  14: from aiida.backends.testbase import AiidaTestCase
  20: class TestConfigurationOptions(AiidaTestCase):

tests/manage/configuration/test_profile.py:
  15: from aiida.backends.testbase import AiidaTestCase
  20: class TestProfile(AiidaTestCase):

tests/orm/test_authinfos.py:
  12: from aiida.backends.testbase import AiidaTestCase
  17: class TestAuthinfo(AiidaTestCase):

tests/orm/test_comments.py:
  13: from aiida.backends.testbase import AiidaTestCase
  18: class TestComment(AiidaTestCase):

tests/orm/test_computers.py:
  13: from aiida.backends.testbase import AiidaTestCase
  17: class TestComputer(AiidaTestCase):
  68: class TestComputerConfigure(AiidaTestCase):

tests/orm/test_entities.py:
  13: from aiida.backends.testbase import AiidaTestCase
  16: class TestBackendEntitiesAndCollections(AiidaTestCase):

tests/orm/test_groups.py:
   14: from aiida.backends.testbase import AiidaTestCase
   18: class TestGroups(AiidaTestCase):
  279: class TestGroupsSubclasses(AiidaTestCase):
  408: class TestGroupExtras(AiidaTestCase):

tests/orm/test_logs.py:
  15: from aiida.backends.testbase import AiidaTestCase
  22: class TestBackendLog(AiidaTestCase):

tests/orm/test_mixins.py:
  12: from aiida.backends.testbase import AiidaTestCase
  19: class TestSealable(AiidaTestCase):

tests/orm/implementation/test_comments.py:
  18: from aiida.backends.testbase import AiidaTestCase
  22: class TestBackendComment(AiidaTestCase):

tests/orm/implementation/test_logs.py:
  19: from aiida.backends.testbase import AiidaTestCase
  24: class TestBackendLog(AiidaTestCase):

tests/orm/implementation/test_nodes.py:
  19: from aiida.backends.testbase import AiidaTestCase
  23: class TestBackendNode(AiidaTestCase):

tests/orm/implementation/test_utils.py:
  13: from aiida.backends.testbase import AiidaTestCase
  18: class TestOrmImplementationUtils(AiidaTestCase):

tests/orm/nodes/test_calcjob.py:
  13: from aiida.backends.testbase import AiidaTestCase
  18: class TestCalcJobNode(AiidaTestCase):

tests/orm/nodes/data/test_kpoints.py:
  14: from aiida.backends.testbase import AiidaTestCase
  18: class TestKpoints(AiidaTestCase):

tests/orm/nodes/data/test_orbital.py:
  14: from aiida.backends.testbase import AiidaTestCase
  20: class TestOrbitalData(AiidaTestCase):

tests/orm/nodes/data/test_trajectory.py:
   6: from aiida.backends.testbase import AiidaTestCase
  10: class TestTrajectory(AiidaTestCase):

tests/orm/nodes/data/test_upf.py:
  24: from aiida.backends.testbase import AiidaTestCase
  80: class TestUpfParser(AiidaTestCase):

tests/orm/utils/test_loaders.py:
  11: from aiida.backends.testbase import AiidaTestCase
  18: class TestOrmUtils(AiidaTestCase):

tests/orm/utils/test_node.py:
  13: from aiida.backends.testbase import AiidaTestCase
  18: class TestLoadNodeClass(AiidaTestCase):

tests/parsers/test_parser.py:
  17: from aiida.backends.testbase import AiidaTestCase
  42: class TestParser(AiidaTestCase):

tests/plugins/test_utils.py:
  12: from aiida.backends.testbase import AiidaTestCase
  18: class TestPluginVersionProvider(AiidaTestCase):

tests/restapi/test_routes.py:
  18: from aiida.backends.testbase import AiidaTestCase
  24: class RESTApiTestCase(AiidaTestCase):

tests/tools/data/orbital/test_orbitals.py:
  13: from aiida.backends.testbase import AiidaTestCase
  19: class TestOrbital(AiidaTestCase):
  55: class TestRealhydrogenOrbital(AiidaTestCase):

tests/tools/dbimporters/test_icsd.py:
  17: from aiida.backends.testbase import AiidaTestCase
  50: class TestIcsd(AiidaTestCase):

tests/tools/dbimporters/test_materialsproject.py:
  14: from aiida.backends.testbase import AiidaTestCase
  24: class TestMaterialsProject(AiidaTestCase):

tests/tools/graph/test_age.py:
   16: from aiida.backends.testbase import AiidaTestCase
   83: class TestAiidaGraphExplorer(AiidaTestCase):
  666: class TestAiidaEntitySet(AiidaTestCase):

tests/tools/graph/test_graph_traversers.py:
  12: from aiida.backends.testbase import AiidaTestCase
  85: class TestTraverseGraph(AiidaTestCase):

tests/tools/visualization/test_graph.py:
  13: from aiida.backends.testbase import AiidaTestCase
  21: class TestVisGraph(AiidaTestCase):

@ltalirz
Copy link
Member Author

ltalirz commented Feb 21, 2022

fine to close

@ltalirz ltalirz closed this Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants