|
1 |
| -from contextlib import suppress |
2 | 1 | from textwrap import dedent
|
3 | 2 |
|
4 | 3 | import hypothesis.strategies as st
|
| 4 | +import pandas as pd |
5 | 5 | import pytest
|
6 | 6 | from hypothesis import given
|
7 | 7 |
|
|
16 | 16 |
|
17 | 17 |
|
18 | 18 | 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( |
33 | 21 | {
|
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], |
44 | 25 | }
|
45 | 26 | )
|
| 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 | + ) |
46 | 56 |
|
47 | 57 |
|
48 | 58 | @pytest.mark.filterwarnings(
|
|
0 commit comments