Skip to content

Commit 951b28f

Browse files
committed
Move EventType to FileWatcher.EventType
This class should be exposed in the public API, but it is just a helper class to be used with the FileWatcher, so it is better to expose it scoped in that class. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent a3265aa commit 951b28f

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ time.
4343

4444
* The class `BidirectionalHandle` was moved to `Bidirectional.Handle`.
4545

46+
* The class `EventType` was moved to `FileWatcher.EventType`.
47+
4648
## New Features
4749

4850
<!-- Here goes the main new features and examples or instructions on how to use them -->

src/frequenz/channels/util/_file_watcher.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
from .._base_classes import ChannelClosedError, Receiver
1414

1515

16-
class EventType(Enum):
17-
"""Available types of changes to watch for."""
18-
19-
CREATE = Change.added
20-
MODIFY = Change.modified
21-
DELETE = Change.deleted
22-
23-
2416
class FileWatcher(Receiver[pathlib.Path]):
2517
"""A channel receiver that watches for file events."""
2618

19+
class EventType(Enum):
20+
"""Available types of changes to watch for."""
21+
22+
CREATE = Change.added
23+
MODIFY = Change.modified
24+
DELETE = Change.deleted
25+
2726
def __init__(
2827
self,
2928
paths: List[Union[pathlib.Path, str]],
@@ -37,7 +36,7 @@ def __init__(
3736
all event types.
3837
"""
3938
if event_types is None:
40-
event_types = {EventType.CREATE, EventType.MODIFY, EventType.DELETE}
39+
event_types = set(FileWatcher.EventType) # all types
4140

4241
self.event_types = event_types
4342
self._stop_event = asyncio.Event()

tests/utils/test_file_watcher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pathlib
88

99
from frequenz.channels.util import FileWatcher, Select, Timer
10-
from frequenz.channels.util._file_watcher import EventType
1110

1211

1312
async def test_file_watcher(tmp_path: pathlib.Path) -> None:
@@ -45,7 +44,9 @@ async def test_file_watcher_change_types(tmp_path: pathlib.Path) -> None:
4544
Created by pytest.
4645
"""
4746
filename = tmp_path / "test-file"
48-
file_watcher = FileWatcher(paths=[str(tmp_path)], event_types={EventType.DELETE})
47+
file_watcher = FileWatcher(
48+
paths=[str(tmp_path)], event_types={FileWatcher.EventType.DELETE}
49+
)
4950

5051
select = Select(
5152
write_timer=Timer(0.1), deletion_timer=Timer(0.5), watcher=file_watcher

0 commit comments

Comments
 (0)