File tree Expand file tree Collapse file tree 7 files changed +33
-64
lines changed
Expand file tree Collapse file tree 7 files changed +33
-64
lines changed Original file line number Diff line number Diff line change 33
44"""Simple test for the BaseActor."""
55import asyncio
6- from collections .abc import Iterator
76from typing import Literal , assert_never
87
98import async_solipsism
1211from frequenz .sdk .actor import BackgroundService
1312
1413
15- # Setting 'autouse' has no effect as this method replaces the event loop for all tests in the file.
16- @pytest .fixture ()
17- def event_loop () -> Iterator [async_solipsism .EventLoop ]:
18- """Replace the loop with one that doesn't interact with the outside world."""
19- loop = async_solipsism .EventLoop ()
20- yield loop
21- loop .close ()
14+ @pytest .fixture (autouse = True )
15+ def event_loop_policy () -> async_solipsism .EventLoopPolicy :
16+ """Return an event loop policy that uses the async solipsism event loop."""
17+ return async_solipsism .EventLoopPolicy ()
2218
2319
2420class FakeService (BackgroundService ):
Original file line number Diff line number Diff line change 44"""Frequenz Python SDK resampling example."""
55import asyncio
66import dataclasses
7- from collections .abc import Iterator
87from datetime import datetime , timedelta , timezone
98
109import async_solipsism
2221from frequenz .sdk .timeseries import Sample
2322from frequenz .sdk .timeseries ._quantities import Quantity
2423
25- # pylint: disable=too-many-locals,redefined-outer-name
26- #
2724
28-
29- # Setting 'autouse' has no effect as this method replaces the event loop for all tests in the file.
30- @pytest .fixture ()
31- def event_loop () -> Iterator [async_solipsism .EventLoop ]:
32- """Replace the loop with one that doesn't interact with the outside world."""
33- loop = async_solipsism .EventLoop ()
34- yield loop
35- loop .close ()
25+ @pytest .fixture (autouse = True )
26+ def event_loop_policy () -> async_solipsism .EventLoopPolicy :
27+ """Return an event loop policy that uses the async solipsism event loop."""
28+ return async_solipsism .EventLoopPolicy ()
3629
3730
3831def _now () -> datetime :
Original file line number Diff line number Diff line change 55
66import asyncio
77import time
8- from collections .abc import Iterator
98
109import async_solipsism
1110import pytest
1413from frequenz .sdk .actor import Actor , run
1514
1615
17- # Setting 'autouse' has no effect as this method replaces the event loop for all tests in the file.
18- @pytest .fixture ()
19- def event_loop () -> Iterator [async_solipsism .EventLoop ]:
20- """Replace the loop with one that doesn't interact with the outside world."""
21- loop = async_solipsism .EventLoop ()
22- yield loop
23- loop .close ()
16+ @pytest .fixture (autouse = True )
17+ def event_loop_policy () -> async_solipsism .EventLoopPolicy :
18+ """Return an event loop policy that uses the async solipsism event loop."""
19+ return async_solipsism .EventLoopPolicy ()
2420
2521
2622class FaultyActor (Actor ):
Original file line number Diff line number Diff line change 44"""Basic tests for the DataPipeline."""
55
66import asyncio
7- from collections .abc import Iterator
87from datetime import timedelta
98
109import async_solipsism
2423from ..utils .mock_microgrid_client import MockMicrogridClient
2524
2625
27- @pytest .fixture
28- def event_loop () -> Iterator [async_solipsism .EventLoop ]:
29- """Replace the loop with one that doesn't interact with the outside world."""
30- loop = async_solipsism .EventLoop ()
31- yield loop
32- loop .close ()
26+ @pytest .fixture (autouse = True )
27+ def event_loop_policy () -> async_solipsism .EventLoopPolicy :
28+ """Return an event loop policy that uses the async solipsism event loop."""
29+ return async_solipsism .EventLoopPolicy ()
3330
3431
3532# loop time is advanced but not the system time
Original file line number Diff line number Diff line change 1010import dataclasses
1111import logging
1212import math
13- from collections .abc import AsyncIterator , Iterator
13+ from collections .abc import AsyncIterator
1414from dataclasses import dataclass , is_dataclass , replace
1515from datetime import datetime , timedelta , timezone
1616from typing import Any , Generic , TypeVar
5858
5959_logger = logging .getLogger (__name__ )
6060
61- # pylint doesn't understand fixtures. It thinks it is redefined name.
62- # pylint: disable=redefined-outer-name
6361
64- # pylint: disable=too-many-lines
65-
66-
67- @pytest .fixture ()
68- def event_loop () -> Iterator [async_solipsism .EventLoop ]:
69- """Replace the loop with one that doesn't interact with the outside world."""
70- loop = async_solipsism .EventLoop ()
71- yield loop
72- loop .close ()
62+ @pytest .fixture (autouse = True )
63+ def event_loop_policy () -> async_solipsism .EventLoopPolicy :
64+ """Return an event loop policy that uses the async solipsism event loop."""
65+ return async_solipsism .EventLoopPolicy ()
7366
7467
7568def get_components (
Original file line number Diff line number Diff line change 44"""Tests for the moving window."""
55
66import asyncio
7- from collections .abc import Iterator , Sequence
7+ from collections .abc import Sequence
88from datetime import datetime , timedelta , timezone
99
1010import async_solipsism
1919from frequenz .sdk .timeseries ._resampling import ResamplerConfig
2020
2121
22- # Setting 'autouse' has no effect as this method replaces the event loop for all tests in the file.
23- @pytest .fixture ()
24- def event_loop () -> Iterator [async_solipsism .EventLoop ]:
25- """Replace the loop with one that doesn't interact with the outside world."""
26- loop = async_solipsism .EventLoop ()
27- yield loop
28- loop .close ()
22+ @pytest .fixture (autouse = True )
23+ def event_loop_policy () -> async_solipsism .EventLoopPolicy :
24+ """Return an event loop policy that uses the async solipsism event loop."""
25+ return async_solipsism .EventLoopPolicy ()
2926
3027
3128async def push_logical_meter_data (
Original file line number Diff line number Diff line change 66
77import asyncio
88import logging
9- from collections .abc import AsyncIterator , Iterator
9+ from collections .abc import AsyncIterator
1010from datetime import datetime , timedelta , timezone
1111from unittest .mock import AsyncMock , MagicMock
1212
3333
3434from ..utils import a_sequence
3535
36- # We relax some pylint checks as for tests they don't make a lot of sense.
37- # pylint: disable=too-many-lines,disable=too-many-locals,redefined-outer-name
36+ # We relax some pylint checks as for tests they don't make a lot of sense for this test .
37+ # pylint: disable=too-many-lines,disable=too-many-locals
3838
3939
40- # Setting 'autouse' has no effect as this method replaces the event loop for all tests in the file.
41- @pytest .fixture ()
42- def event_loop () -> Iterator [async_solipsism .EventLoop ]:
43- """Replace the loop with one that doesn't interact with the outside world."""
44- loop = async_solipsism .EventLoop ()
45- yield loop
46- loop .close ()
40+ @pytest .fixture (autouse = True )
41+ def event_loop_policy () -> async_solipsism .EventLoopPolicy :
42+ """Return an event loop policy that uses the async solipsism event loop."""
43+ return async_solipsism .EventLoopPolicy ()
4744
4845
4946@pytest .fixture
You can’t perform that action at this time.
0 commit comments