Skip to content

Commit f93c8c5

Browse files
committed
Remove suppress statement by providing a correct design matrix
1 parent c6acd72 commit f93c8c5

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

tests/ert/ui_tests/cli/analysis/test_design_matrix.py

-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ def test_run_poly_example_with_design_matrix():
5252
dedent(
5353
"""\
5454
#!/usr/bin/env python
55-
import numpy as np
56-
import sys
5755
import json
5856
5957
def _load_coeffs(filename):
@@ -141,8 +139,6 @@ def test_run_poly_example_with_design_matrix_and_genkw_merge(default_values, err
141139
dedent(
142140
"""\
143141
#!/usr/bin/env python
144-
import numpy as np
145-
import sys
146142
import json
147143
148144
def _load_coeffs(filename):

tests/ert/unit_tests/config/test_analysis_config.py

+35-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from contextlib import suppress
21
from textwrap import dedent
32

43
import hypothesis.strategies as st
4+
import pandas as pd
55
import pytest
66
from hypothesis import given
77

@@ -16,33 +16,43 @@
1616

1717

1818
def test_analysis_config_from_file_is_same_as_from_dict(monkeypatch, tmp_path):
19-
with open(tmp_path / "my_design_matrix.xlsx", "w", encoding="utf-8"):
20-
pass
21-
monkeypatch.chdir(tmp_path)
22-
with suppress(ConfigValidationError):
23-
assert ErtConfig.from_file_contents(
24-
dedent(
25-
"""
26-
NUM_REALIZATIONS 10
27-
MIN_REALIZATIONS 10
28-
ANALYSIS_SET_VAR STD_ENKF ENKF_TRUNCATION 0.8
29-
DESIGN_MATRIX my_design_matrix.xlsx DESIGN_SHEET:my_sheet DEFAULT_SHEET:my_default_sheet
30-
"""
31-
)
32-
).analysis_config == AnalysisConfig.from_dict(
19+
with pd.ExcelWriter(tmp_path / "my_design_matrix.xlsx") as xl_write:
20+
design_matrix_df = pd.DataFrame(
3321
{
34-
ConfigKeys.NUM_REALIZATIONS: 10,
35-
ConfigKeys.MIN_REALIZATIONS: "10",
36-
ConfigKeys.ANALYSIS_SET_VAR: [
37-
("STD_ENKF", "ENKF_TRUNCATION", 0.8),
38-
],
39-
ConfigKeys.DESIGN_MATRIX: [
40-
"my_design_matrix.xlsx",
41-
"DESIGN_SHEET:my_sheet",
42-
"DEFAULT_SHEET:my_default_sheet",
43-
],
22+
"REAL": [0, 1, 2],
23+
"a": [1, 2, 3],
24+
"b": [0, 2, 0],
4425
}
4526
)
27+
default_sheet_df = pd.DataFrame([["a", 1], ["b", 4]])
28+
design_matrix_df.to_excel(xl_write, index=False, sheet_name="my_sheet")
29+
default_sheet_df.to_excel(
30+
xl_write, index=False, sheet_name="my_default_sheet", header=False
31+
)
32+
monkeypatch.chdir(tmp_path)
33+
assert ErtConfig.from_file_contents(
34+
dedent(
35+
"""
36+
NUM_REALIZATIONS 3
37+
MIN_REALIZATIONS 3
38+
ANALYSIS_SET_VAR STD_ENKF ENKF_TRUNCATION 0.8
39+
DESIGN_MATRIX my_design_matrix.xlsx DESIGN_SHEET:my_sheet DEFAULT_SHEET:my_default_sheet
40+
"""
41+
)
42+
).analysis_config == AnalysisConfig.from_dict(
43+
{
44+
ConfigKeys.NUM_REALIZATIONS: 3,
45+
ConfigKeys.MIN_REALIZATIONS: "3",
46+
ConfigKeys.ANALYSIS_SET_VAR: [
47+
("STD_ENKF", "ENKF_TRUNCATION", 0.8),
48+
],
49+
ConfigKeys.DESIGN_MATRIX: [
50+
"my_design_matrix.xlsx",
51+
"DESIGN_SHEET:my_sheet",
52+
"DEFAULT_SHEET:my_default_sheet",
53+
],
54+
}
55+
)
4656

4757

4858
@pytest.mark.filterwarnings(

0 commit comments

Comments
 (0)