Skip to content

Commit 192aa65

Browse files
committed
Apply ruff
1 parent c9dddc3 commit 192aa65

File tree

3 files changed

+58
-40
lines changed

3 files changed

+58
-40
lines changed

src/nomad_simulations/schema_packages/physical_property.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,17 @@ def _is_contribution(self) -> bool:
130130
"""
131131
Determines if this instance is a contribution by checking if it's contained
132132
in a parent's contributions list.
133-
133+
134134
Returns:
135135
(bool): True if this instance is a contribution, False otherwise.
136136
"""
137137
if hasattr(self, 'm_parent') and self.m_parent:
138138
parent_section = self.m_parent
139139
# If parent has contributions containing this instance, we are a contribution
140-
if hasattr(parent_section, 'contributions') and parent_section.contributions:
140+
if (
141+
hasattr(parent_section, 'contributions')
142+
and parent_section.contributions
143+
):
141144
if self in parent_section.contributions:
142145
return True
143146
return False
@@ -147,20 +150,20 @@ def _validate_contributions_structure(self, logger) -> bool:
147150
Validates that contributions do not contain nested contributions.
148151
This prevents recursive contribution structures which are not intended.
149152
Only runs for top-level PhysicalProperty instances, not for contributions themselves.
150-
153+
151154
Args:
152155
logger: Logger instance for error reporting.
153-
156+
154157
Returns:
155158
(bool): True if validation passes, False if nested contributions are found.
156159
"""
157160
# Skip validation for contribution instances
158161
if self._is_contribution():
159162
return True
160-
163+
161164
if not self.contributions:
162165
return True
163-
166+
164167
has_nested_contributions = False
165168
for i, contribution in enumerate(self.contributions):
166169
if hasattr(contribution, 'contributions') and contribution.contributions:
@@ -169,30 +172,30 @@ def _validate_contributions_structure(self, logger) -> bool:
169172
'Contributions should not have their own contributions subsection populated.'
170173
)
171174
has_nested_contributions = True
172-
175+
173176
return not has_nested_contributions
174177

175178
def _validate_contribution_type(self, logger) -> bool:
176179
"""
177180
Validates that contribution_type is only set for contribution instances
178181
and is not set for top-level PhysicalProperty instances.
179-
182+
180183
Args:
181184
logger: Logger instance for error reporting.
182-
185+
183186
Returns:
184187
(bool): True if validation passes, False if contribution_type is incorrectly set.
185188
"""
186189
is_contribution = self._is_contribution()
187-
190+
188191
# Check for incorrect usage
189192
if not is_contribution and self.contribution_type is not None:
190193
logger.error(
191194
f'{self.__class__.__name__} has contribution_type set but is not a contribution. '
192195
'contribution_type should only be set for instances in the contributions subsection.'
193196
)
194197
return False
195-
198+
196199
return True
197200

198201
def plot(self, **kwargs) -> list[PlotlyFigure]:

src/nomad_simulations/schema_packages/properties/thermodynamics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ class HelmholtzFreeEnergy(BaseEnergy):
130130
class ChemicalPotential(BaseEnergy):
131131
"""
132132
Free energy cost of adding or extracting a particle from a thermodynamic system.
133-
133+
134134
At finite temperature, the chemical potential determines the equilibrium condition
135135
for particle exchange between different phases or subsystems. It can be defined
136136
as the partial derivative of the internal energy with respect to particle number
137-
at constant entropy and volume, or equivalently as the partial derivative of
138-
the Gibbs free energy with respect to particle number at constant temperature
137+
at constant entropy and volume, or equivalently as the partial derivative of
138+
the Gibbs free energy with respect to particle number at constant temperature
139139
and pressure.
140140
"""
141141

tests/test_physical_properties.py

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def test_plotting_and_contributions(self):
100100
(DummyPhysicalProperty, 'DummyPhysicalProperty'),
101101
],
102102
)
103-
def test_name_setting_during_normalization(self, instantiator: callable, reference: str):
103+
def test_name_setting_during_normalization(
104+
self, instantiator: callable, reference: str
105+
):
104106
"""
105107
Test that the name is set during normalization for PhysicalProperty.
106108
"""
@@ -110,37 +112,43 @@ def test_name_setting_during_normalization(self, instantiator: callable, referen
110112

111113
@pytest.mark.parametrize(
112114
'has_nested_contributions, log_ref',
113-
[
114-
(True, True),
115-
(False, False)
116-
],
115+
[(True, True), (False, False)],
117116
)
118-
def test_contributions_validation(self, caplog, has_nested_contributions: bool, log_ref: bool):
117+
def test_contributions_validation(
118+
self, caplog, has_nested_contributions: bool, log_ref: bool
119+
):
119120
"""
120121
Test contributions validation during normalization.
121-
122+
122123
Args:
123124
has_nested_contributions: Whether to create nested contribution structure
124125
log_ref: Whether validation error should be logged
125126
"""
126127
main_property = DummyPhysicalProperty(source='simulation', name='main')
127-
128+
128129
if has_nested_contributions:
129-
nested_contribution = DummyPhysicalProperty(source='analysis', name='nested')
130-
contribution_with_nested = DummyPhysicalProperty(source='analysis', name='parent_contribution')
130+
nested_contribution = DummyPhysicalProperty(
131+
source='analysis', name='nested'
132+
)
133+
contribution_with_nested = DummyPhysicalProperty(
134+
source='analysis', name='parent_contribution'
135+
)
131136
contribution_with_nested.contributions = [nested_contribution]
132137
main_property.contributions = [contribution_with_nested]
133138
else:
134139
contribution1 = DummyPhysicalProperty(source='analysis', name='contrib1')
135140
contribution2 = DummyPhysicalProperty(source='analysis', name='contrib2')
136141
main_property.contributions = [contribution1, contribution2]
137-
142+
138143
with caplog.at_level('ERROR'):
139144
main_property.normalize(EntryArchive(), logger)
140-
141-
has_nested_error = any('nested contributions' in record.message.lower() for record in caplog.records)
145+
146+
has_nested_error = any(
147+
'nested contributions' in record.message.lower()
148+
for record in caplog.records
149+
)
142150
assert has_nested_error == log_ref
143-
151+
144152
if log_ref:
145153
assert any('Contribution 0' in record.message for record in caplog.records)
146154

@@ -153,11 +161,16 @@ def test_contributions_validation(self, caplog, has_nested_contributions: bool,
153161
(True, True, True),
154162
],
155163
)
156-
def test_contribution_type_validation(self, caplog, set_contribution_type_on_main: bool,
157-
set_contribution_type_on_contrib: bool, log_ref: bool):
164+
def test_contribution_type_validation(
165+
self,
166+
caplog,
167+
set_contribution_type_on_main: bool,
168+
set_contribution_type_on_contrib: bool,
169+
log_ref: bool,
170+
):
158171
"""
159172
Test contribution_type validation during normalization.
160-
173+
161174
Args:
162175
set_contribution_type_on_main: Whether to set contribution_type on main property
163176
set_contribution_type_on_contrib: Whether to set contribution_type on contribution
@@ -166,18 +179,20 @@ def test_contribution_type_validation(self, caplog, set_contribution_type_on_mai
166179
main_property = DummyPhysicalProperty(source='simulation', name='main')
167180
if set_contribution_type_on_main:
168181
main_property.contribution_type = 'invalid_main_type'
169-
182+
170183
contribution = DummyPhysicalProperty(source='analysis', name='contrib')
171184
if set_contribution_type_on_contrib:
172185
contribution.contribution_type = 'valid_contrib_type'
173-
186+
174187
main_property.contributions = [contribution]
175-
188+
176189
with caplog.at_level('ERROR'):
177190
main_property.normalize(EntryArchive(), logger)
178-
179-
has_contrib_type_error = any('contribution_type set but is not a contribution' in record.message.lower()
180-
for record in caplog.records)
191+
192+
has_contrib_type_error = any(
193+
'contribution_type set but is not a contribution' in record.message.lower()
194+
for record in caplog.records
195+
)
181196
assert has_contrib_type_error == log_ref
182197

183198
def test_is_contribution_method(self):
@@ -186,11 +201,11 @@ def test_is_contribution_method(self):
186201
"""
187202
main_property = DummyPhysicalProperty(source='simulation', name='main')
188203
contribution = DummyPhysicalProperty(source='analysis', name='contrib')
189-
204+
190205
assert not main_property._is_contribution()
191206
assert not contribution._is_contribution()
192-
207+
193208
main_property.contributions = [contribution]
194209
main_property.normalize(EntryArchive(), logger)
195-
210+
196211
assert not main_property._is_contribution()

0 commit comments

Comments
 (0)