17
17
async def test_write_metadata (tmp_path : Path ) -> None :
18
18
dataset_name = 'test'
19
19
dataset_no_metadata_name = 'test-no-metadata'
20
- ms = MemoryStorageClient (
20
+ ms = MemoryStorageClient . from_config (
21
21
Configuration (
22
22
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
23
23
write_metadata = True ,
24
24
),
25
25
)
26
- ms_no_metadata = MemoryStorageClient (
26
+ ms_no_metadata = MemoryStorageClient . from_config (
27
27
Configuration (
28
28
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
29
29
write_metadata = False ,
@@ -48,7 +48,7 @@ async def test_write_metadata(tmp_path: Path) -> None:
48
48
],
49
49
)
50
50
async def test_persist_storage (persist_storage : bool , tmp_path : Path ) -> None : # noqa: FBT001
51
- ms = MemoryStorageClient (
51
+ ms = MemoryStorageClient . from_config (
52
52
Configuration (
53
53
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
54
54
persist_storage = persist_storage ,
@@ -82,18 +82,20 @@ async def test_persist_storage(persist_storage: bool, tmp_path: Path) -> None:
82
82
83
83
def test_persist_storage_set_to_false_via_string_env_var (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ) -> None :
84
84
monkeypatch .setenv ('CRAWLEE_PERSIST_STORAGE' , 'false' )
85
- ms = MemoryStorageClient (Configuration (crawlee_storage_dir = str (tmp_path ))) # type: ignore[call-arg]
85
+ ms = MemoryStorageClient .from_config (
86
+ Configuration (crawlee_storage_dir = str (tmp_path )), # type: ignore[call-arg]
87
+ )
86
88
assert ms .persist_storage is False
87
89
88
90
89
91
def test_persist_storage_set_to_false_via_numeric_env_var (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ) -> None :
90
92
monkeypatch .setenv ('CRAWLEE_PERSIST_STORAGE' , '0' )
91
- ms = MemoryStorageClient (Configuration (crawlee_storage_dir = str (tmp_path ))) # type: ignore[call-arg]
93
+ ms = MemoryStorageClient . from_config (Configuration (crawlee_storage_dir = str (tmp_path ))) # type: ignore[call-arg]
92
94
assert ms .persist_storage is False
93
95
94
96
95
97
def test_persist_storage_true_via_constructor_arg (tmp_path : Path ) -> None :
96
- ms = MemoryStorageClient (
98
+ ms = MemoryStorageClient . from_config (
97
99
Configuration (
98
100
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
99
101
persist_storage = True ,
@@ -104,20 +106,24 @@ def test_persist_storage_true_via_constructor_arg(tmp_path: Path) -> None:
104
106
105
107
def test_default_write_metadata_behavior (tmp_path : Path ) -> None :
106
108
# Default behavior
107
- ms = MemoryStorageClient (Configuration (crawlee_storage_dir = str (tmp_path ))) # type: ignore[call-arg]
109
+ ms = MemoryStorageClient .from_config (
110
+ Configuration (crawlee_storage_dir = str (tmp_path )), # type: ignore[call-arg]
111
+ )
108
112
assert ms .write_metadata is True
109
113
110
114
111
115
def test_write_metadata_set_to_false_via_env_var (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ) -> None :
112
116
# Test if env var changes write_metadata to False
113
117
monkeypatch .setenv ('CRAWLEE_WRITE_METADATA' , 'false' )
114
- ms = MemoryStorageClient (Configuration (crawlee_storage_dir = str (tmp_path ))) # type: ignore[call-arg]
118
+ ms = MemoryStorageClient .from_config (
119
+ Configuration (crawlee_storage_dir = str (tmp_path )), # type: ignore[call-arg]
120
+ )
115
121
assert ms .write_metadata is False
116
122
117
123
118
124
def test_write_metadata_false_via_constructor_arg_overrides_env_var (tmp_path : Path ) -> None :
119
125
# Test if constructor arg takes precedence over env var value
120
- ms = MemoryStorageClient (
126
+ ms = MemoryStorageClient . from_config (
121
127
Configuration (
122
128
write_metadata = False ,
123
129
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
@@ -127,7 +133,7 @@ def test_write_metadata_false_via_constructor_arg_overrides_env_var(tmp_path: Pa
127
133
128
134
129
135
async def test_purge_datasets (tmp_path : Path ) -> None :
130
- ms = MemoryStorageClient (
136
+ ms = MemoryStorageClient . from_config (
131
137
Configuration (
132
138
write_metadata = True ,
133
139
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
@@ -150,7 +156,7 @@ async def test_purge_datasets(tmp_path: Path) -> None:
150
156
151
157
152
158
async def test_purge_key_value_stores (tmp_path : Path ) -> None :
153
- ms = MemoryStorageClient (
159
+ ms = MemoryStorageClient . from_config (
154
160
Configuration (
155
161
write_metadata = True ,
156
162
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
@@ -185,7 +191,7 @@ async def test_purge_key_value_stores(tmp_path: Path) -> None:
185
191
186
192
187
193
async def test_purge_request_queues (tmp_path : Path ) -> None :
188
- ms = MemoryStorageClient (
194
+ ms = MemoryStorageClient . from_config (
189
195
Configuration (
190
196
write_metadata = True ,
191
197
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
@@ -207,7 +213,7 @@ async def test_purge_request_queues(tmp_path: Path) -> None:
207
213
208
214
209
215
async def test_not_implemented_method (tmp_path : Path ) -> None :
210
- ms = MemoryStorageClient (
216
+ ms = MemoryStorageClient . from_config (
211
217
Configuration (
212
218
write_metadata = True ,
213
219
crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
@@ -230,21 +236,21 @@ async def test_default_storage_path_used(monkeypatch: pytest.MonkeyPatch) -> Non
230
236
monkeypatch .delenv ('CRAWLEE_STORAGE_DIR' , raising = False )
231
237
232
238
# Initialize the service locator with default configuration
233
- msc = MemoryStorageClient ()
239
+ msc = MemoryStorageClient . from_config ()
234
240
assert msc .storage_dir == './storage'
235
241
236
242
237
243
async def test_storage_path_from_env_var_overrides_default (monkeypatch : pytest .MonkeyPatch ) -> None :
238
244
# We expect the env var to override the default value
239
245
monkeypatch .setenv ('CRAWLEE_STORAGE_DIR' , './env_var_storage_dir' )
240
246
service_locator .set_configuration (Configuration ())
241
- ms = MemoryStorageClient ()
247
+ ms = MemoryStorageClient . from_config ()
242
248
assert ms .storage_dir == './env_var_storage_dir'
243
249
244
250
245
251
async def test_parametrized_storage_path_overrides_env_var () -> None :
246
252
# We expect the parametrized value to be used
247
- ms = MemoryStorageClient (
253
+ ms = MemoryStorageClient . from_config (
248
254
Configuration (crawlee_storage_dir = './parametrized_storage_dir' ), # type: ignore[call-arg]
249
255
)
250
256
assert ms .storage_dir == './parametrized_storage_dir'
0 commit comments