forked from equinor/fmu-settings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
154 lines (128 loc) · 4.51 KB
/
Copy pathconftest.py
File metadata and controls
154 lines (128 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""Root configuration for pytest."""
from datetime import UTC, datetime
from pathlib import Path
from typing import Any
from unittest.mock import patch
import pytest
from fmu.settings._fmu_dir import ProjectFMUDirectory, UserFMUDirectory
from fmu.settings._init import init_fmu_directory, init_user_fmu_directory
from fmu.settings._version import __version__
from fmu.settings.models.project_config import ProjectConfig
from fmu.settings.models.user_config import UserConfig
@pytest.fixture
def unix_epoch_utc() -> datetime:
"""Returns a fixed datetime used in testing."""
return datetime(1970, 1, 1, 0, 0, tzinfo=UTC)
@pytest.fixture
def config_dict(unix_epoch_utc: datetime) -> dict[str, Any]:
"""A dictionary representing a .fmu config."""
return {
"version": __version__,
"created_at": unix_epoch_utc,
"created_by": "user",
"masterdata": None,
"model": None,
}
@pytest.fixture
def masterdata_dict() -> dict[str, Any]:
"""Example masterdata from SMDA."""
return {
"smda": {
"country": [
{
"identifier": "Norway",
"uuid": "ad214d85-8a1d-19da-e053-c918a4889309",
}
],
"discovery": [
{
"short_identifier": "DROGON",
"uuid": "ad214d85-8a1d-19da-e053-c918a4889309",
}
],
"field": [
{
"identifier": "DROGON",
"uuid": "ad214d85-8a1d-19da-e053-c918a4889309",
}
],
"coordinate_system": {
"identifier": "ST_WGS84_UTM37N_P32637",
"uuid": "ad214d85-dac7-19da-e053-c918a4889309",
},
"stratigraphic_column": {
"identifier": "DROGON_HAS_NO_STRATCOLUMN",
"uuid": "ad214d85-8a1d-19da-e053-c918a4889309",
},
}
}
@pytest.fixture
def model_dict() -> dict[str, Any]:
"""Example model information."""
return {
"name": "Drogon",
"revision": "21.0.0",
"description": None,
}
@pytest.fixture
def config_dict_with_masterdata(
unix_epoch_utc: datetime,
masterdata_dict: dict[str, Any],
model_dict: dict[str, Any],
) -> dict[str, Any]:
"""A dictionary representing a .fmu config."""
return {
"version": __version__,
"created_at": unix_epoch_utc,
"created_by": "user",
"masterdata": masterdata_dict,
"model": model_dict,
}
@pytest.fixture
def config_model(config_dict: dict[str, Any]) -> ProjectConfig:
"""A ProjectConfig model representing a .fmu config file."""
return ProjectConfig.model_validate(config_dict)
@pytest.fixture
def config_model_with_masterdata(
config_dict_with_masterdata: dict[str, Any],
) -> ProjectConfig:
"""A ProjectConfig model representing a .fmu config file."""
return ProjectConfig.model_validate(config_dict_with_masterdata)
@pytest.fixture
def user_config_dict(unix_epoch_utc: datetime) -> dict[str, Any]:
"""A dictionary representing a .fmu user config."""
return {
"version": __version__,
"created_at": unix_epoch_utc,
"user_api_keys": {
"smda_subscription": None,
},
"recent_directories": [],
}
@pytest.fixture
def user_config_model(user_config_dict: dict[str, Any]) -> UserConfig:
"""A UserConfig model representing a .fmu config file."""
return UserConfig.model_validate(user_config_dict)
@pytest.fixture
def fmu_dir(tmp_path: Path, unix_epoch_utc: datetime) -> ProjectFMUDirectory:
"""Create an ProjectFMUDirectory instance for testing."""
with (
patch(
"fmu.settings.models.project_config.getpass.getuser",
return_value="user",
),
patch("fmu.settings.models.project_config.datetime") as mock_datetime,
):
mock_datetime.now.return_value = unix_epoch_utc
mock_datetime.datetime.now.return_value = unix_epoch_utc
return init_fmu_directory(tmp_path)
@pytest.fixture
def user_fmu_dir(tmp_path: Path, unix_epoch_utc: datetime) -> UserFMUDirectory:
"""Create an ProjectFMUDirectory instance for testing."""
with (
patch("pathlib.Path.home", return_value=tmp_path),
patch("fmu.settings.models.user_config.datetime") as mock_datetime,
):
mock_datetime.now.return_value = unix_epoch_utc
mock_datetime.datetime.now.return_value = unix_epoch_utc
return init_user_fmu_directory()