@@ -32,13 +32,13 @@ def test_disable_browser_sandbox(
32
32
33
33
34
34
def test_apify_configuration_is_always_used () -> None :
35
- """Set Crawlee Configuration in service_locator and verify that Apify Configuration is returned ."""
35
+ """Set Crawlee Configuration in Actor and verify that Apify Configuration is used ."""
36
36
max_used_cpu_ratio = 0.123456 # Some unique value to verify configuration
37
+
37
38
service_locator .set_configuration (CrawleeConfiguration (max_used_cpu_ratio = max_used_cpu_ratio ))
38
39
39
- returned_config = service_locator .get_configuration ()
40
- assert returned_config .max_used_cpu_ratio == max_used_cpu_ratio
41
- assert isinstance (returned_config , ApifyConfiguration )
40
+ assert Actor .config .max_used_cpu_ratio == max_used_cpu_ratio
41
+ assert isinstance (Actor .config , ApifyConfiguration )
42
42
43
43
44
44
async def test_existing_apify_config_respected_by_actor () -> None :
@@ -61,11 +61,10 @@ async def test_existing_crawlee_config_respected_by_actor() -> None:
61
61
async with Actor :
62
62
pass
63
63
64
- returned_config = service_locator .get_configuration ()
65
- assert returned_config is not crawlee_config
66
- assert isinstance (returned_config , ApifyConfiguration )
67
- # Make sure the Crawlee Configuration was used to create returned Apify Configuration
68
- assert returned_config .max_used_cpu_ratio == max_used_cpu_ratio
64
+ assert Actor .config is not crawlee_config
65
+ assert isinstance (Actor .config , ApifyConfiguration )
66
+ # Make sure the Crawlee Configuration was used to create ApifyConfiguration in Actor
67
+ assert Actor .config .max_used_cpu_ratio == max_used_cpu_ratio
69
68
70
69
71
70
async def test_existing_apify_config_throws_error_when_set_in_actor () -> None :
@@ -109,7 +108,7 @@ async def test_crawler_implicit_configuration() -> None:
109
108
async with Actor ():
110
109
crawler = BasicCrawler ()
111
110
112
- assert service_locator .get_configuration () is crawler ._service_locator .get_configuration ()
111
+ assert Actor . config is service_locator .get_configuration () is crawler ._service_locator .get_configuration ()
113
112
114
113
115
114
async def test_crawlers_own_configuration () -> None :
@@ -128,7 +127,7 @@ async def test_crawlers_own_configuration() -> None:
128
127
129
128
130
129
async def test_crawler_global_configuration () -> None :
131
- """Test that crawler and Actor use explicit service_locator based configuration unless explicit configuration
130
+ """Test that crawler and Actor use service_locator based configuration unless explicit configuration
132
131
was passed to them."""
133
132
config_global = ApifyConfiguration ()
134
133
service_locator .set_configuration (config_global )
@@ -140,18 +139,24 @@ async def test_crawler_global_configuration() -> None:
140
139
assert crawler ._service_locator .get_configuration () is config_global
141
140
142
141
142
+ async def test_crawler_uses_implicit_apify_config () -> None :
143
+ """Test that Actor is using implicit ApifyConfiguration in Actor context."""
144
+ async with Actor :
145
+ assert isinstance (Actor .config , ApifyConfiguration )
146
+
147
+
143
148
async def test_storage_retrieved_is_different_with_different_config (tmp_path : Path ) -> None :
144
149
"""Test that retrieving storage depends on used configuration."""
145
150
dir_1 = tmp_path / 'dir_1'
146
151
dir_2 = tmp_path / 'dir_2'
147
152
config_actor = ApifyConfiguration ()
148
153
config_actor .storage_dir = str (dir_1 )
149
- apify_crawler = ApifyConfiguration ()
150
- apify_crawler .storage_dir = str (dir_2 )
154
+ config_crawler = ApifyConfiguration ()
155
+ config_crawler .storage_dir = str (dir_2 )
151
156
152
157
async with Actor (configuration = config_actor ):
153
158
actor_kvs = await Actor .open_key_value_store ()
154
- crawler = BasicCrawler (configuration = apify_crawler )
159
+ crawler = BasicCrawler (configuration = config_crawler )
155
160
crawler_kvs = await crawler .get_key_value_store ()
156
161
157
162
assert actor_kvs is not crawler_kvs
@@ -179,9 +184,3 @@ async def test_storage_retrieved_is_same_with_same_config() -> None:
179
184
crawler_kvs = await crawler .get_key_value_store ()
180
185
181
186
assert actor_kvs is crawler_kvs
182
-
183
-
184
- async def test_crawler_uses_apify_config () -> None :
185
- """Test that crawler is using ApifyConfiguration in SDK context."""
186
- crawler = BasicCrawler ()
187
- assert isinstance (crawler ._service_locator .get_configuration (), ApifyConfiguration )
0 commit comments