|
2 | 2 | # Copyright © 2022 Frequenz Energy-as-a-Service GmbH |
3 | 3 |
|
4 | 4 | """Test for ConfigManager.""" |
| 5 | +import os |
5 | 6 | import pathlib |
6 | 7 | from typing import Any |
7 | 8 |
|
@@ -48,17 +49,6 @@ class TestActorConfigManager: |
48 | 49 |
|
49 | 50 | @pytest.fixture() |
50 | 51 | def config_file(self, tmp_path: pathlib.Path) -> pathlib.Path: |
51 | | - """Create a test config file.""" |
52 | | - file_path = tmp_path / TestActorConfigManager.conf_path |
53 | | - file_path.parent.mkdir() |
54 | | - file_path.touch() |
55 | | - file_path.write_text(TestActorConfigManager.conf_content) |
56 | | - return file_path |
57 | | - |
58 | | - @pytest.fixture() |
59 | | - def real_config_file( |
60 | | - self, tmp_path: pathlib.Path = pathlib.Path("/tmp/") |
61 | | - ) -> pathlib.Path: |
62 | 52 | """Create a test config file.""" |
63 | 53 | file_path = tmp_path / TestActorConfigManager.conf_path |
64 | 54 | if not file_path.exists(): |
@@ -98,3 +88,26 @@ async def test_update(self, config_file: pathlib.Path) -> None: |
98 | 88 | assert config.get("var2") == str(number) |
99 | 89 | assert config.get("var3") is None |
100 | 90 | assert config_file.read_text() == create_content(number=number) |
| 91 | + |
| 92 | + async def test_update_relative_path(self, config_file: pathlib.Path) -> None: |
| 93 | + """Test ConfigManagingActor with a relative path.""" |
| 94 | + config_channel: Broadcast[dict[str, Any]] = Broadcast( |
| 95 | + name="Config Channel", resend_latest=True |
| 96 | + ) |
| 97 | + config_receiver = config_channel.new_receiver() |
| 98 | + |
| 99 | + current_dir = pathlib.Path.cwd() |
| 100 | + relative_path = os.path.relpath(config_file, current_dir) |
| 101 | + |
| 102 | + async with ConfigManagingActor(relative_path, config_channel.new_sender()): |
| 103 | + config = await config_receiver.receive() |
| 104 | + assert config is not None |
| 105 | + assert config.get("var2") is None |
| 106 | + |
| 107 | + number = 8 |
| 108 | + config_file.write_text(create_content(number=number)) |
| 109 | + |
| 110 | + config = await config_receiver.receive() |
| 111 | + assert config is not None |
| 112 | + assert config.get("var2") == str(number) |
| 113 | + assert config_file.read_text() == create_content(number=number) |
0 commit comments