Skip to content

Commit

Permalink
Added testing for SimulationWorkflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Sep 17, 2024
1 parent a047ad0 commit dda3829
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import Optional

import pytest
from nomad.datamodel import EntryArchive
from nomad.datamodel.metainfo.workflow import Link, Task, Workflow

from nomad_simulations.schema_packages.model_method import ModelMethod
from nomad_simulations.schema_packages.model_system import ModelSystem
from nomad_simulations.schema_packages.outputs import Outputs
from nomad_simulations.schema_packages.workflow import (
BeyondDFTMethod,
BeyondDFTWorkflow,
SimulationWorkflow,
)

from . import logger
from .conftest import generate_simulation


class TestSimulationWorkflow:
@pytest.mark.parametrize(
'model_system, model_method, outputs, workflow_inputs, workflow_outputs',
[
# empty sections in archive.data
(None, None, None, [], []),
# only one section in archive.data
(ModelSystem(), None, None, [], []),
# another section in archive.data
(None, ModelMethod(), None, [], []),
# only two sections in archive.data
(ModelSystem(), ModelMethod(), None, [], []),
# all sections in archive.data
(
ModelSystem(),
ModelMethod(),
Outputs(),
[Link(name='Input Model System', section=ModelSystem())],
[Link(name='Output Data', section=Outputs())],
),
],
)
def test_resolve_inputs_outputs(
self,
model_system: Optional[ModelSystem],
model_method: Optional[ModelMethod],
outputs: Optional[Outputs],
workflow_inputs: list[Link],
workflow_outputs: list[Link],
):
archive = EntryArchive()
simulation = generate_simulation(
model_system=model_system, model_method=model_method, outputs=outputs
)
archive.data = simulation
workflow = SimulationWorkflow()
archive.workflow2 = workflow

workflow.resolve_inputs_outputs(archive=archive, logger=logger)
if not workflow_inputs:
assert workflow.inputs == workflow_inputs
else:
assert len(workflow.inputs) == 1
assert workflow.inputs[0].name == workflow_inputs[0].name
# ! direct comparison of section does not work (probably different m_parent)
# assert workflow.inputs[0].section == workflow_inputs[0].section
if not workflow_outputs:
assert workflow.outputs == workflow_outputs
else:
assert len(workflow.outputs) == 1
assert workflow.outputs[0].name == workflow_outputs[0].name
# ! direct comparison of section does not work (probably different m_parent)
# assert workflow.outputs[0].section == workflow_outputs[0].section

def test_normalize(self):
assert True


class TestBeyondDFTMethod:
def test_resolve_beyonddft_method_ref(self):
assert True


class TestBeyondDFT:
def test_resolve_all_outputs(self):
assert True

1 comment on commit dda3829

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py14286%53–55
   atoms_state.py1902189%31–33, 219–222, 246, 301–302, 370–371, 373, 555, 567–568, 629–633, 648–652, 659
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   general.py89891%22–25, 139, 203, 313–314, 324
   model_method.py2657771%28–30, 189–192, 195–202, 294–295, 315, 336–357, 373–399, 402–419, 773, 784, 826–833, 871, 890, 970, 1027, 1102, 1216
   model_system.py2612292%43–45, 520–523, 570–577, 751–752, 973–977, 983–984, 992–993, 998, 1021
   numerical_settings.py2596176%30–32, 235, 237–238, 241–244, 248–249, 256–259, 268–271, 275–278, 280–283, 288–291, 297–300, 487–514, 589, 624–627, 651, 654, 699, 701–704, 708, 712, 759, 763–784, 839–840, 907
   outputs.py1201092%27–28, 270–273, 313–316, 341, 343, 380, 399
   physical_property.py102793%38–40, 220, 349–351
   variables.py861286%26–28, 116, 139, 163, 185, 207, 229, 251, 274, 294
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%26–28, 153–154
   band_structure.py1232580%27–29, 250–283, 296, 303, 339–340, 343, 390–391, 396
   energies.py42979%25–27, 54, 75, 100, 121, 137, 152
   fermi_surface.py17476%25–27, 58
   forces.py22673%26–28, 55, 75, 98
   greens_function.py991387%25–27, 228–229, 232, 253–254, 257, 278–279, 282, 418
   hopping_matrix.py29583%25–27, 76, 112
   permittivity.py48883%25–27, 115–123
   spectral_profile.py26012851%27–29, 75–78, 113–116, 217–318, 374–386, 411–414, 434, 439–442, 484–520, 544, 591–594, 610–611, 616–622
   thermodynamics.py752764%25–27, 53, 74, 90, 99, 108, 119, 128, 155, 165, 175, 190–192, 195, 211, 231–233, 236, 252, 272–274, 277
src/nomad_simulations/schema_packages/utils
   utils.py681479%26–29, 79–88, 97–98, 103, 106
src/nomad_simulations/schema_packages/workflow
   base_workflows.py451762%23–24, 90–99, 119–122, 137–140, 143
   dft_plus_tb.py513629%23–24, 80–92, 98–119, 130–136, 139–166
   single_point.py362433%45–46, 76–92, 101–106, 109–121
TOTAL262157378% 

Tests Skipped Failures Errors Time
390 0 💤 0 ❌ 0 🔥 3.742s ⏱️

Please sign in to comment.