|
9 | 9 | from crawlee.memory_storage_client import MemoryStorageClient
|
10 | 10 |
|
11 | 11 |
|
12 |
| -def test_configuration() -> None: |
| 12 | +def test_default_configuration() -> None: |
13 | 13 | default_config = Configuration()
|
14 | 14 | config = service_locator.get_configuration()
|
15 |
| - assert config == default_config |
| 15 | + assert config == default_config # == because these are in fact different instances, which should be fine |
16 | 16 |
|
| 17 | + |
| 18 | +def test_custom_configuration() -> None: |
17 | 19 | custom_config = Configuration(default_browser_path='custom_path')
|
18 | 20 | service_locator.set_configuration(custom_config)
|
19 | 21 | config = service_locator.get_configuration()
|
20 |
| - assert config == custom_config |
| 22 | + assert config is custom_config |
| 23 | + |
| 24 | + |
| 25 | +def test_configuration_overwrite() -> None: |
| 26 | + default_config = Configuration() |
| 27 | + service_locator.set_configuration(default_config) |
| 28 | + |
| 29 | + custom_config = Configuration(default_browser_path='custom_path') |
| 30 | + service_locator.set_configuration(custom_config) |
| 31 | + assert service_locator.get_configuration() is custom_config |
| 32 | + |
21 | 33 |
|
22 |
| - with pytest.raises(ServiceConflictError, match='Configuration has already been set.'): |
| 34 | +def test_configuration_conflict() -> None: |
| 35 | + service_locator.get_configuration() |
| 36 | + custom_config = Configuration(default_browser_path='custom_path') |
| 37 | + |
| 38 | + with pytest.raises(ServiceConflictError, match='Configuration is already in use.'): |
23 | 39 | service_locator.set_configuration(custom_config)
|
24 | 40 |
|
25 | 41 |
|
26 |
| -def test_event_manager() -> None: |
| 42 | +def test_default_event_manager() -> None: |
27 | 43 | default_event_manager = service_locator.get_event_manager()
|
28 | 44 | assert isinstance(default_event_manager, LocalEventManager)
|
29 | 45 |
|
| 46 | + |
| 47 | +def test_custom_event_manager() -> None: |
30 | 48 | custom_event_manager = LocalEventManager()
|
31 | 49 | service_locator.set_event_manager(custom_event_manager)
|
32 | 50 | event_manager = service_locator.get_event_manager()
|
33 |
| - assert event_manager == custom_event_manager |
| 51 | + assert event_manager is custom_event_manager |
| 52 | + |
| 53 | + |
| 54 | +def test_event_manager_overwrite() -> None: |
| 55 | + custom_event_manager = LocalEventManager() |
| 56 | + service_locator.set_event_manager(custom_event_manager) |
34 | 57 |
|
35 |
| - with pytest.raises(ServiceConflictError, match='EventManager has already been set.'): |
| 58 | + another_custom_event_manager = LocalEventManager() |
| 59 | + service_locator.set_event_manager(another_custom_event_manager) |
| 60 | + |
| 61 | + assert custom_event_manager != another_custom_event_manager |
| 62 | + assert service_locator.get_event_manager() is another_custom_event_manager |
| 63 | + |
| 64 | + |
| 65 | +def test_event_manager_conflict() -> None: |
| 66 | + service_locator.get_event_manager() |
| 67 | + custom_event_manager = LocalEventManager() |
| 68 | + |
| 69 | + with pytest.raises(ServiceConflictError, match='EventManager is already in use.'): |
36 | 70 | service_locator.set_event_manager(custom_event_manager)
|
37 | 71 |
|
38 | 72 |
|
39 |
| -def test_storage_client() -> None: |
| 73 | +def test_default_storage_client() -> None: |
40 | 74 | default_storage_client = service_locator.get_storage_client()
|
41 | 75 | assert isinstance(default_storage_client, MemoryStorageClient)
|
42 | 76 |
|
| 77 | + |
| 78 | +def test_custom_storage_client() -> None: |
43 | 79 | custom_storage_client = MemoryStorageClient.from_config()
|
44 | 80 | service_locator.set_storage_client(custom_storage_client)
|
45 | 81 | storage_client = service_locator.get_storage_client()
|
46 |
| - assert storage_client == custom_storage_client |
| 82 | + assert storage_client is custom_storage_client |
| 83 | + |
| 84 | + |
| 85 | +def test_storage_client_overwrite() -> None: |
| 86 | + custom_storage_client = MemoryStorageClient.from_config() |
| 87 | + service_locator.set_storage_client(custom_storage_client) |
| 88 | + |
| 89 | + another_custom_storage_client = MemoryStorageClient.from_config() |
| 90 | + service_locator.set_storage_client(another_custom_storage_client) |
| 91 | + |
| 92 | + assert custom_storage_client != another_custom_storage_client |
| 93 | + assert service_locator.get_storage_client() is another_custom_storage_client |
| 94 | + |
| 95 | + |
| 96 | +def test_storage_client_conflict() -> None: |
| 97 | + service_locator.get_storage_client() |
| 98 | + custom_storage_client = MemoryStorageClient.from_config() |
47 | 99 |
|
48 |
| - with pytest.raises(ServiceConflictError, match='StorageClient has already been set.'): |
| 100 | + with pytest.raises(ServiceConflictError, match='StorageClient is already in use.'): |
49 | 101 | service_locator.set_storage_client(custom_storage_client)
|
0 commit comments