Skip to content

Commit 29c37aa

Browse files
committed
add a testing folder for some testing tools
1 parent 5f95396 commit 29c37aa

File tree

3 files changed

+105
-3
lines changed

3 files changed

+105
-3
lines changed

testing/__init__.py

Whitespace-only changes.

testing/bmi.py

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import numpy as np
2+
3+
4+
class BmiExample:
5+
_input_var_names = ("land_surface__elevation", "land_surface_air__temperature")
6+
_output_var_names = (
7+
"land_surface__elevation",
8+
"land_surface~10m-above_air_flow__speed",
9+
)
10+
11+
_var_units = {
12+
"land_surface__elevation": "m",
13+
"land_surface_air__temperature": "C",
14+
"land_surface~10m-above_air_flow__speed": "m/s",
15+
}
16+
17+
def __init__(self):
18+
self._values = {
19+
"land_surface__elevation": np.empty(12, dtype=float),
20+
"land_surface_air__temperature": np.empty(12, dtype=float),
21+
"land_surface~10m-above_air_flow__speed": np.empty(12, dtype=float),
22+
}
23+
24+
def initialize(self, config_file):
25+
with open(config_file):
26+
pass
27+
28+
def update(self):
29+
pass
30+
31+
def finalize(self):
32+
pass
33+
34+
def get_component_name(self):
35+
return "Test BMI component"
36+
37+
def get_input_var_names(self):
38+
return self._input_var_names
39+
40+
def get_output_var_names(self):
41+
return self._output_var_names
42+
43+
def get_current_time(self):
44+
return 0.0
45+
46+
def get_start_time(self):
47+
return 0.0
48+
49+
def get_end_time(self):
50+
return 1.0
51+
52+
def get_time_step(self):
53+
return 1.0
54+
55+
def get_time_units(self):
56+
return "s"
57+
58+
def get_var_grid(self, name):
59+
return 0
60+
61+
def get_var_itemsize(self, name):
62+
return 8
63+
64+
def get_var_nbytes(self, name):
65+
return 8 * 12
66+
67+
def get_var_type(self, name):
68+
return "float"
69+
70+
def get_var_units(self, name):
71+
return self._var_units[name]
72+
73+
def get_var_location(self, name):
74+
return "node"
75+
76+
def get_grid_rank(self, id_):
77+
return 2
78+
79+
def get_grid_size(self, id_):
80+
return 12
81+
82+
def get_grid_node_count(self, id_):
83+
return 12
84+
85+
def get_grid_type(self, id_):
86+
return "uniform_rectilinear"
87+
88+
def get_grid_shape(self, id_, shape):
89+
shape[:] = (3, 4)
90+
return shape
91+
92+
def get_grid_spacing(self, id_, spacing):
93+
spacing[:] = (10.0, 20.0)
94+
return spacing
95+
96+
def get_value(self, name, buffer):
97+
buffer[:] = self._values[name]
98+
return buffer
99+
100+
def set_value(self, name, buffer):
101+
self._values[name][:] = buffer
102+
return buffer

tests/test_api.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_bmi_check(tmpdir):
1313
touch_file("input.yaml")
1414
assert (
1515
check_bmi(
16-
"bmi_tester.bmi:Bmi", input_file="input.yaml", extra_args=["-vvv"]
16+
"testing.bmi:BmiExample", input_file="input.yaml", extra_args=["-vvv"]
1717
)
1818
== 0
1919
)
@@ -24,7 +24,7 @@ def test_bmi_check_with_manifest_as_list(tmpdir):
2424
touch_file("input.yaml")
2525
assert (
2626
check_bmi(
27-
"bmi_tester.bmi:Bmi",
27+
"testing.bmi:BmiExample",
2828
extra_args=["-vvv"],
2929
input_file="input.yaml",
3030
manifest=["input.yaml"],
@@ -41,7 +41,7 @@ def test_bmi_check_with_manifest_as_string(tmpdir):
4141
touch_file("data.dat")
4242
assert (
4343
check_bmi(
44-
"bmi_tester.bmi:Bmi",
44+
"testing.bmi:BmiExample",
4545
extra_args=["-vvv"],
4646
input_file="input.yaml",
4747
manifest="manifest.txt",

0 commit comments

Comments
 (0)