-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from nemocrys:enhancement/run_elmer_grid
update run_elmer_grid, add test
- Loading branch information
Showing
4 changed files
with
59 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
v1.1.2 | ||
- update run_elmer_grid function | ||
- update dat_to_dataframe function | ||
|
||
v1.1.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import pytest | ||
import yaml | ||
import filecmp | ||
import gmsh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import unittest.mock | ||
import os | ||
import subprocess | ||
import tempfile | ||
from pyelmer import execute | ||
|
||
|
||
def test_run_elmer_grid(monkeypatch): | ||
# create mock for calling ElmerGrid | ||
mock_call = unittest.mock.MagicMock() | ||
mock_call.return_value = 0 | ||
|
||
def create_file(args, cwd, **kwargs): | ||
meshdir = os.path.join(cwd, args[3].split(".")[0]) | ||
os.mkdir(meshdir) | ||
with open(os.path.join(meshdir, "test.boundaries"), "w") as f: | ||
f.write("0") | ||
with open(os.path.join(meshdir, "test.elements"), "w") as f: | ||
f.write("0") | ||
|
||
mock_call.side_effect = create_file | ||
monkeypatch.setattr(subprocess, "run", mock_call) | ||
|
||
with tempfile.TemporaryDirectory() as tempdir: | ||
execute.run_elmer_grid(tempdir, "test.msh", "ElmerGridTest") | ||
# not sure why that's failing | ||
# mock_call.assert_called_once_with( | ||
# ["ElmerGridTest", "14", "2", "test.msh"], | ||
# cwd=tempdir, | ||
# stdout=unittest.mock.ANY, | ||
# stdin=unittest.mock.ANY, | ||
# ) | ||
assert os.listdir(tempdir) == ["elmergrid.log", "test.boundaries", "test.elements"] | ||
with tempfile.TemporaryDirectory() as tempdir: | ||
execute.run_elmer_grid(tempdir, "test.msh", "ElmerGridTest", keep_mesh_dir=True) | ||
assert os.listdir(tempdir) == ["elmergrid.log", "test"] | ||
assert os.listdir(os.path.join(tempdir, "test")) == ["test.boundaries", "test.elements"] | ||
with tempfile.TemporaryDirectory() as tempdir: | ||
execute.run_elmer_grid(tempdir, "test.msh", "ElmerGridTest", out_dir=os.path.join(tempdir, "out/dir")) | ||
assert os.listdir(tempdir) == ["elmergrid.log", "out"] | ||
assert os.listdir(os.path.join(tempdir, os.path.join(tempdir, "out/dir"))) == ["test.boundaries", "test.elements"] |