Skip to content

Commit

Permalink
Fix test_is_derived
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Apr 29, 2024
1 parent 62227a6 commit f952263
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/nomad_simulations/physical_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ class PhysicalProperty(ArchiveSection):
""",
)

physical_property_ref = Quantity(
type=Reference(SectionProxy('PhysicalProperty')),
physical_property_ref = SubSection(
section_def=SectionProxy('PhysicalProperty'),
description="""
Reference to the `PhysicalProperty` section from which the physical property was derived. If `physical_property_ref`
is populated, the quantity `is_derived` is set to True via normalization.
""",
repeats=False,
)

is_derived = Quantity(
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from nomad.units import ureg
from nomad.datamodel import EntryArchive
from nomad.datamodel.data import ArchiveSection
from nomad.metainfo import Quantity, Section, Context, SubSection

from . import logger

Expand All @@ -31,6 +33,7 @@
from nomad_simulations.model_method import ModelMethod
from nomad_simulations.numerical_settings import SelfConsistency
from nomad_simulations.outputs import Outputs, SCFOutputs
from nomad_simulations.physical_property import PhysicalProperty
from nomad_simulations.variables import Energy2 as Energy
from nomad_simulations.properties import (
ElectronicBandGap,
Expand Down
34 changes: 22 additions & 12 deletions tests/test_physical_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

from nomad.units import ureg
from nomad.datamodel import EntryArchive
from nomad.metainfo import Quantity, Section, Context
from nomad.datamodel.data import ArchiveSection
from nomad.metainfo import Quantity, Section, Context, SubSection

from . import logger

Expand All @@ -48,6 +49,12 @@ def __init__(
super().__init__(m_def, m_context, **kwargs)


class SectionWithProperties(ArchiveSection):
m_def = Section()

physical_property = SubSection(sub_section=PhysicalProperty.m_def, repeats=True)


class TestPhysicalProperty:
"""
Test the `PhysicalProperty` class defined in `physical_property.py`.
Expand Down Expand Up @@ -162,24 +169,27 @@ def test_is_derived(self):
"""
Test the `normalize` and `_is_derived` methods.
"""
section = SectionWithProperties()
# Testing a directly parsed physical property
not_derived_physical_property = PhysicalProperty(
not_derived_property = PhysicalProperty(
m_def=Section(
iri='http://fairmat-nfdi.eu/taxonomy/PhysicalProperty', rank=[]
)
)
not_derived_physical_property.source = 'simulation'
assert not_derived_physical_property._is_derived() is False
not_derived_physical_property.normalize(EntryArchive(), logger)
assert not_derived_physical_property.is_derived is False
not_derived_property.source = 'simulation'
section.physical_property.append(not_derived_property)
assert not_derived_property._is_derived() is False
not_derived_property.normalize(EntryArchive(), logger)
assert not_derived_property.is_derived is False
# Testing a derived physical property
derived_physical_property = PhysicalProperty(
derived_property = PhysicalProperty(
m_def=Section(
iri='http://fairmat-nfdi.eu/taxonomy/PhysicalProperty', rank=[]
)
)
derived_physical_property.source = 'analysis'
derived_physical_property.physical_property_ref = not_derived_physical_property
assert derived_physical_property._is_derived() is True
derived_physical_property.normalize(EntryArchive(), logger)
assert derived_physical_property.is_derived is True
section.physical_property.append(derived_property)
derived_property.source = 'analysis'
derived_property.physical_property_ref = not_derived_property
assert derived_property._is_derived() is True
derived_property.normalize(EntryArchive(), logger)
assert derived_property.is_derived is True

0 comments on commit f952263

Please sign in to comment.