Skip to content

Commit

Permalink
handle empty sample (#188)
Browse files Browse the repository at this point in the history
* handle empty sample

* code cleaning
  • Loading branch information
andped10 authored Sep 25, 2024
1 parent 9a0b0cb commit a0b0df6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/easyreflectometry/sample/collections/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,20 @@ def _enable_changes_to_outermost_layers(self):
Superphase can change thickness and roughness.
Subphase can change thickness.
"""
self.superphase.thickness.enabled = True
self.superphase.roughness.enabled = True
self.subphase.thickness.enabled = True
if len(self) != 0:
self.superphase.thickness.enabled = True
self.superphase.roughness.enabled = True
self.subphase.thickness.enabled = True

def _disable_changes_to_outermost_layers(self):
"""No allowed to change the outermost layers of the sample.
Superphase can change thickness and roughness.
Subphase can change thickness.
"""
self.superphase.thickness.enabled = False
self.superphase.roughness.enabled = False
self.subphase.thickness.enabled = False
if len(self) != 0:
self.superphase.thickness.enabled = False
self.superphase.roughness.enabled = False
self.subphase.thickness.enabled = False

# Representation
def as_dict(self, skip: Optional[List[str]] = None) -> dict:
Expand Down
11 changes: 11 additions & 0 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ def test_remove_assembly_with_interface_refl1d(self):
# assert_equal(len(mod.interface()._wrapper.storage['item']), 1)
# assert_equal(len(mod.interface()._wrapper.storage['layer']), 2)

def test_remove_all_assemblies(self):
# when
mod = Model()

# Then
mod.remove_assembly(0)
mod.remove_assembly(0)

# Expect
assert_equal(len(mod.sample), 0)

def test_resolution_function(self):
mock_resolution_function = MagicMock()
interface = CalculatorFactory()
Expand Down

0 comments on commit a0b0df6

Please sign in to comment.