77import pytest
88
99from ert .cli .main import ErtCliError
10- from ert .config ._observations import GeneralObservation
10+ from ert .config import ObservationType
11+ from ert .config .parsing import ObservationDict
1112from ert .observation_converters import convert_observations
1213from ert .observation_converters .summary_to_yaml import YamlConverter
13- from tests .ert .unit_tests .cli .test_summary_to_bulk import _make_summary_obs
14+
15+
16+ def _make_obs_dict (
17+ obs_type : ObservationType = ObservationType .SUMMARY ,
18+ key : str = "WOPR" ,
19+ well : str = "OP1" ,
20+ ) -> ObservationDict :
21+ key = f"{ key } :{ well } " if well else key
22+ return ObservationDict (
23+ {
24+ "type" : obs_type ,
25+ "KEY" : key ,
26+ "ERROR" : 5 ,
27+ "VALUE" : 10 ,
28+ "DATE" : "2010-10-10" ,
29+ },
30+ context = MagicMock (),
31+ )
1432
1533
1634@pytest .mark .usefixtures ("snake_oil_case" )
@@ -22,22 +40,22 @@ def test_that_happy_path_on_snake_oil_produces_yaml_and_stdout(capsys):
2240 smry:
2341 - key: WOPR:OP1
2442 observations:
25- - date: '2010-03-31T00:00:00 '
43+ - date: '2010-03-31 '
2644 value: 0.1
2745 error: 0.05
28- - date: '2010-12-26T00:00:00 '
46+ - date: '2010-12-26 '
2947 value: 0.7
3048 error: 0.07
31- - date: '2011-12-21T00:00:00 '
49+ - date: '2011-12-21 '
3250 value: 0.5
3351 error: 0.05
34- - date: '2012-12-15T00:00:00 '
52+ - date: '2012-12-15 '
3553 value: 0.3
3654 error: 0.075
37- - date: '2013-12-10T00:00:00 '
55+ - date: '2013-12-10 '
3856 value: 0.2
3957 error: 0.035
40- - date: '2015-03-15T00:00:00 '
58+ - date: '2015-03-15 '
4159 value: 0.015
4260 error: 0.01
4361 """ )
@@ -52,23 +70,21 @@ def test_that_happy_path_on_snake_oil_produces_yaml_and_stdout(capsys):
5270
5371
5472def test_that_empty_observations_raises_ert_cli_error ():
55- with pytest .raises (ErtCliError , match = "No summary observations found " ):
73+ with pytest .raises (ErtCliError , match = "No summary observations in configuration " ):
5674 YamlConverter ([])
5775
5876
5977def test_that_no_summary_observations_raises_ert_cli_error ():
60- gen_obs = GeneralObservation (
61- name = "foo" , data = "foo" , value = 1.0 , error = 1.0 , restart = 5 , index = 5
62- )
63- with pytest .raises (ErtCliError , match = "No summary observations found" ):
78+ gen_obs = _make_obs_dict (obs_type = ObservationType .GENERAL )
79+ with pytest .raises (ErtCliError , match = "No summary observations in configuration" ):
6480 YamlConverter ([gen_obs ])
6581
6682
6783def test_that_observations_with_same_summary_key_are_gathered_in_yaml_dict (use_tmpdir ):
6884 k1 , k2 = "foo" , "bar"
6985 observations = 2 * [
70- _make_summary_obs (key = k1 , well = None ),
71- _make_summary_obs (key = k2 , well = None ),
86+ _make_obs_dict (key = k1 , well = "" ),
87+ _make_obs_dict (key = k2 , well = "" ),
7288 ]
7389
7490 converter = YamlConverter (observations = observations )
@@ -85,8 +101,8 @@ def test_that_observations_with_same_summary_key_are_gathered_in_yaml_dict(use_t
85101def test_that_observations_with_different_summary_keys_are_separated_in_yaml_dict ():
86102 k1 , k2 = "foo" , "bar"
87103 observations = [
88- _make_summary_obs (key = k1 , well = None ),
89- _make_summary_obs (key = k2 , well = None ),
104+ _make_obs_dict (key = k1 , well = "" ),
105+ _make_obs_dict (key = k2 , well = "" ),
90106 ]
91107
92108 converter = YamlConverter (observations = observations )
@@ -98,7 +114,7 @@ def test_that_observations_with_different_summary_keys_are_separated_in_yaml_dic
98114
99115
100116def test_that_dumping_to_yaml_is_skipped_when_file_already_exists (use_tmpdir ):
101- observations = [_make_summary_obs ()]
117+ observations = [_make_obs_dict ()]
102118
103119 Path ("summary_observations.yaml" ).write_text ("existing" , encoding = "utf-8" )
104120 assert Path ("summary_observations.yaml" ).is_file ()
0 commit comments