Skip to content

Commit

Permalink
Try to test against a jl file (python side)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Oct 16, 2023
1 parent ceff03c commit ac4fdac
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/fake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
BMI.initialize(::Type{Model}) = Model()

BMI.get_grid_x(m::Model, grid, x)
copyto!(x, [0.0, 1.0])
copyto!(x, [1.0, 2.0])
end

end
47 changes: 46 additions & 1 deletion test/test_julia.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
except ImportError:
BmiJulia = None

@pytest.mark.skipif(not BmiJulia, reason="R and its dependencies are not installed")
@pytest.mark.skipif(not BmiJulia, reason="Julia and its dependencies are not installed")
class TestJuliaHeatModel:
@pytest.fixture(scope="class", autouse=True)
def install_heat(self):
Expand Down Expand Up @@ -117,4 +117,49 @@ def test_get_value_ptr(self, model: BmiJulia):
# result = model.get_value("plate_surface__temperature", np.zeros((48,)))
# assert_array_equal(result, np.ones((48,)))

# TODO test set_value_at_indices method

# TODO Heat.jl does not implement all methods, use fake.jl to test all methods not covered by Heat.jl
"""
To test
get_grid_x
get_grid_y
get_grid_z
get_grid_edge_count
get_grid_face_count
get_grid_edge_nodes
get_grid_face_edges
get_grid_face_nodes
get_grid_nodes_per_face
"""
@pytest.mark.skipif(not BmiJulia, reason="Julia and its dependencies are not installed")
class TestJuliaFakeModel:
@pytest.fixture(scope="class", autouse=True)
def install_fake(self):
install('BasicModelInterface')

@pytest.fixture
def model(self, cfg_file):
jl.seval('include("fake.jl")')
model = BmiJulia.from_name(".FakeModel.Model", ".FakeModel.BMI")
model.initialize(str(cfg_file))
return model

@pytest.mark.parametrize(
"fn_name,fn_args,expected",
[
("get_grid_x", [0, np.zeros((2,))], [1, 2]),
],
)
def test_methods(self, model: BmiJulia, fn_name, fn_args, expected):
fn = getattr(model, fn_name)
if fn_args == tuple():
result = fn()
else:
result = fn(*fn_args)

try:
assert_array_equal(result, expected)
except:
assert result == expected

0 comments on commit ac4fdac

Please sign in to comment.