Skip to content

Commit

Permalink
updated tests for the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kzqureshi committed Dec 4, 2024
1 parent 90101d4 commit 5b91394
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
8 changes: 5 additions & 3 deletions micromagneticdata/tests/test_combined_drive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import os
from pathlib import Path

import discretisedfield as df
import numpy as np
Expand All @@ -17,15 +18,16 @@ class TestDrive:
# RelaxDriver: 3
# HysteresisDriver: 7 [CURRENTLY MISSING IN THE DATASET]
def setup_method(self):
self.dirname = os.path.join(os.path.dirname(__file__), "test_sample")
self.dirname = Path(os.path.dirname(__file__)) / "test_sample"
self.name = "rectangle"
self.data = md.Data(name=self.name, dirname=self.dirname)
self.path = self.dirname / self.name
self.data = md.Data(path=self.path)
self.combined_drives = [
self.data[0] << self.data[1] << self.data[2],
self.data[3] << self.data[3],
self.data[6] << self.data[6],
]
data = md.Data(name="hysteresis", dirname=self.dirname)
data = md.Data(path=self.dirname / "hysteresis")
self.combined_drives.append(data[0] << data[0])

def test_init(self):
Expand Down
8 changes: 5 additions & 3 deletions micromagneticdata/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import ipywidgets
import pandas as pd
Expand All @@ -9,17 +10,18 @@

class TestData:
def setup_method(self):
self.dirname = os.path.join(os.path.dirname(__file__), "test_sample")
self.dirname = Path(os.path.dirname(__file__)) / "test_sample"
self.name = "rectangle"
self.data = md.Data(name=self.name, dirname=self.dirname)
self.path = self.dirname / self.name
self.data = md.Data(path=self.path)
self.N_SAMPLES = 7

def test_init(self):
assert isinstance(self.data, md.Data)

# Exception
with pytest.raises(IOError):
md.Data(name="wrong", dirname=self.dirname)
md.Data(name="wrong", path=self.dirname / "nonexistent")

def test_repr(self):
assert isinstance(repr(self.data), str)
Expand Down
26 changes: 18 additions & 8 deletions micromagneticdata/tests/test_drive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import discretisedfield as df
import ipywidgets
Expand All @@ -13,17 +14,26 @@

class TestDrive:
def setup_method(self):
self.dirname = os.path.join(os.path.dirname(__file__), "test_sample")
self.dirname = Path(os.path.dirname(__file__), "test_sample")
self.name = "rectangle"
self.data = md.Data(name=self.name, dirname=self.dirname)
self.path = self.dirname / self.name
self.data = md.Data(path=self.path)

def test_init(self):
drive = md.Drive(name=self.name, number=0, dirname=self.dirname)
drive = md.Drive(path=self.path, number=0)
assert isinstance(drive, md.Drive)

with pytest.warns(DeprecationWarning):
drive = md.Drive(name=self.name, dirname=self.dirname, number=0)
assert isinstance(drive, md.Drive)

# Exception
with pytest.raises(IOError):
drive = md.Drive(name=self.name, number=11, dirname=self.dirname)
drive = md.Drive(name=self.name, path=self.path, number=11)

# `name` or `path` must be given
with pytest.raises(ValueError):
drive = md.Drive(number=0)

def test_repr(self):
for drive in self.data:
Expand Down Expand Up @@ -58,9 +68,7 @@ def test_mx3(self):
assert "tableadd" in drive.calculator_script

def test_valid(self):
dirname = os.path.join(os.path.dirname(__file__), "test_sample")
name = "hysteresis"
data = md.Data(name=name, dirname=dirname)
data = md.Data(path=self.dirname / "hysteresis")
m0_field = data[0].m0
test_points = [
m0_field.mesh.point2index(m0_field.mesh.region.pmin),
Expand Down Expand Up @@ -238,7 +246,9 @@ def test_register_callback(self):

def test_cache(self, monkeypatch):
ref = self.data[0]
drive = md.Drive(ref.name, ref.number, ref.dirname, ref.x, use_cache=True)
drive = md.Drive(
path=ref.drive_path.parent, number=ref.number, x=ref.x, use_cache=True
)

assert len(list(drive)) == 25
assert isinstance(drive[0], df.Field)
Expand Down

0 comments on commit 5b91394

Please sign in to comment.