1
- # TODO: type ignores and crawlee_storage_dir
1
+ # TODO: Update crawlee_storage_dir args once the Pydantic bug is fixed
2
2
# https://github.com/apify/crawlee-python/issues/146
3
3
4
4
from __future__ import annotations
13
13
if TYPE_CHECKING :
14
14
from pathlib import Path
15
15
16
+ from yarl import URL
17
+
16
18
17
19
def test_global_configuration_works () -> None :
18
20
assert (
@@ -23,11 +25,11 @@ def test_global_configuration_works() -> None:
23
25
)
24
26
25
27
26
- async def test_storage_not_persisted_when_disabled (tmp_path : Path ) -> None :
28
+ async def test_storage_not_persisted_when_disabled (tmp_path : Path , httpbin : URL ) -> None :
27
29
config = Configuration (
28
30
persist_storage = False ,
29
31
write_metadata = False ,
30
- crawlee_storage_dir = str (tmp_path ), # type: ignore
32
+ crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
31
33
)
32
34
storage_client = MemoryStorageClient (config )
33
35
set_storage_client (storage_client , force = True )
@@ -38,18 +40,18 @@ async def test_storage_not_persisted_when_disabled(tmp_path: Path) -> None:
38
40
async def default_handler (context : HttpCrawlingContext ) -> None :
39
41
await context .push_data ({'url' : context .request .url })
40
42
41
- await crawler .run (['https://crawlee.dev' ])
43
+ await crawler .run ([str ( httpbin ) ])
42
44
43
45
# Verify that no files were created in the storage directory.
44
46
content = list (tmp_path .iterdir ())
45
47
assert content == [], 'Expected the storage directory to be empty, but it is not.'
46
48
47
49
48
- async def test_storage_persisted_when_enabled (tmp_path : Path ) -> None :
50
+ async def test_storage_persisted_when_enabled (tmp_path : Path , httpbin : URL ) -> None :
49
51
config = Configuration (
50
52
persist_storage = True ,
51
53
write_metadata = True ,
52
- crawlee_storage_dir = str (tmp_path ), # type: ignore
54
+ crawlee_storage_dir = str (tmp_path ), # type: ignore[call-arg]
53
55
)
54
56
storage_client = MemoryStorageClient (config )
55
57
set_storage_client (storage_client , force = True )
@@ -60,7 +62,7 @@ async def test_storage_persisted_when_enabled(tmp_path: Path) -> None:
60
62
async def default_handler (context : HttpCrawlingContext ) -> None :
61
63
await context .push_data ({'url' : context .request .url })
62
64
63
- await crawler .run (['https://crawlee.dev' ])
65
+ await crawler .run ([str ( httpbin ) ])
64
66
65
67
# Verify that files were created in the storage directory.
66
68
content = list (tmp_path .iterdir ())
0 commit comments