Skip to content

Commit

Permalink
Merge pull request #85 from ubermag/system_name
Browse files Browse the repository at this point in the history
Make system name required in __init__
  • Loading branch information
samjrholt authored Jan 23, 2024
2 parents 12cb9a6 + 216d6a4 commit fc4c5b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion micromagneticmodel/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class System:
"""

def __init__(self, energy=0, dynamics=0, m=None, T=0, name="unnamed"):
def __init__(self, name, energy=0, dynamics=0, m=None, T=0):
self.energy = energy
self.dynamics = dynamics
self.m = m
Expand Down
17 changes: 10 additions & 7 deletions micromagneticmodel/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ def setup_method(self):
self.m = df.Field(mesh=mesh, nvdim=3, value=(0, 1, 1), norm=Ms)

def test_init_valid_args(self):
system = mm.System()
system = mm.System("test")
check_system(system)
assert len(system.energy) == 0
assert len(system.dynamics) == 0
assert system.m is None
assert system.T == 0
assert system.name == "unnamed" # Default value
assert system.name == "test"

system.energy = mm.Exchange(A=1e-12) + mm.Demag()
check_system(system)
Expand All @@ -39,19 +39,22 @@ def test_init_valid_args(self):

def test_init_invalid_args(self):
with pytest.raises(TypeError):
mm.System(energy=5)
mm.System("test", energy=5)

with pytest.raises(TypeError):
mm.System(dynamics=5)
mm.System("test", dynamics=5)

with pytest.raises(TypeError):
mm.System(name=152)
mm.System("test", name=152)

with pytest.raises(ValueError):
mm.System(T=-0.1)
mm.System("test", T=-0.1)

with pytest.raises(TypeError):
mm.System(m=-0.1)
mm.System("test", m=-0.1)

with pytest.raises(TypeError):
mm.System()

def test_repr(self):
system = mm.System(name="my_very_cool_system")
Expand Down

0 comments on commit fc4c5b0

Please sign in to comment.