Skip to content

Commit

Permalink
test (loading): Ensure data is loaded in correct step order
Browse files Browse the repository at this point in the history
related to GH 48, occurs test_mock_experiment on some systems.  Previous
passes depended upon how glob ordered files.  Current version adds an
explicit test, in addition to fixing test_mock_experiment
  • Loading branch information
Jacob-Stevens-Haas committed Jun 10, 2024
1 parent fb51cc3 commit 20a3730
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mitosis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def variant_types():

def load_trial_data(hexstr: str, *, trials_folder: Optional[Path | str] = None):
trial = locate_trial_folder(hexstr, trials_folder=trials_folder)
all_files = glob("results*.dill", root_dir=trial)
all_files = sorted(glob("results*.dill", root_dir=trial))
results = []
for file in all_files:
with open(trial / file, "rb") as fh:
Expand Down
2 changes: 1 addition & 1 deletion mitosis/_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def load_mitosis_steps(
)
if any(not isinstance(vals, list) or len(vals) != 2 for vals in result.values()):
raise RuntimeError("tool.mitosis.steps table is malformed")
return {k: tuple(v) for k, v in result.items()}
return {k: tuple(v)[:2] for k, v in result.items()}


@lru_cache
Expand Down
17 changes: 16 additions & 1 deletion mitosis/tests/test_all.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pickle
import sys
from pathlib import Path
from types import ModuleType
Expand Down Expand Up @@ -139,11 +140,25 @@ def test_mock_experiment(mock_steps, tmp_path):
trials_folder=tmp_path,
)
data = mitosis.load_trial_data(exp_key, trials_folder=tmp_path)
assert len(data[1]["data"]) == 5
assert len(data[0]["data"]) == 5
metadata = mitosis._disk.locate_trial_folder(exp_key, trials_folder=tmp_path)
assert (metadata / "experiment").resolve().exists()


def test_load_results_order(tmp_path):
exp_key = "test_results"
(tmp_path / exp_key).mkdir()
filename1 = "results1.dill"
filename2 = "results0.dill"
with open(tmp_path / exp_key / filename1, "wb") as f1:
pickle.dump("second", f1)
with open(tmp_path / exp_key / filename2, "wb") as f2:
pickle.dump("first", f2)
result = mitosis.load_trial_data(exp_key, trials_folder=tmp_path)
expected = ["first", "second"]
assert result == expected


def test_mod_metadata_debug(mock_steps, tmp_path):
hexstr = mitosis.run(
mock_steps,
Expand Down

0 comments on commit 20a3730

Please sign in to comment.