async-timer 1.1.2__tar.gz → 1.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: async-timer
3
- Version: 1.1.2
3
+ Version: 1.1.4
4
4
  Summary: The missing Python async timer.
5
5
  License: MIT
6
6
  Keywords: async,timer
@@ -1,12 +1,13 @@
1
1
  [tool.poetry]
2
2
  name = "async-timer"
3
- version = "v1.1.2"
3
+ version = "v1.1.4"
4
4
  description = "The missing Python async timer."
5
5
  authors = ["Ilya O. <vrghost@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "README.md"
8
8
  packages = [
9
- {include = "async_timer", from = "src"}
9
+ {include = "async_timer", from = "src"},
10
+ {include = "mock_async_timer", from = "src"}
10
11
  ]
11
12
  classifiers = [
12
13
  "Intended Audience :: Developers",
@@ -0,0 +1,3 @@
1
+ """This module provides an async timer mock class for your unittest needs."""
2
+ from . import timer
3
+ from .timer import MockTimer
@@ -0,0 +1,39 @@
1
+ import asyncio
2
+ import unittest.mock
3
+
4
+ import async_timer
5
+
6
+
7
+ class MockPacemaker(async_timer.pacemaker.TimerPacemaker):
8
+ sleep: unittest.mock.AsyncMock
9
+
10
+ def __init__(self, *args, **kwargs):
11
+ super().__init__(*args, **kwargs)
12
+ self.sleep = unittest.mock.AsyncMock(name="mock-timer-sleep")
13
+
14
+ async def _try_wait(self, delay: float):
15
+ if self._cancel_evt.is_set():
16
+ raise StopAsyncIteration()
17
+
18
+ await self._sleep_until_next_loop_iter()
19
+ await self.sleep(delay)
20
+
21
+ async def _sleep_until_next_loop_iter(self):
22
+ """Awaiting this function will release on the next async loop iteration"""
23
+ fut = asyncio.Future()
24
+ asyncio.get_event_loop().call_soon(lambda: fut.set_result(42))
25
+ await fut
26
+
27
+
28
+ class MockTimer(async_timer.Timer):
29
+ """Test-friendly mock timer class.
30
+
31
+ The main difference is that it is using test-friendly pacemaker
32
+ that doesn't sleep.
33
+ """
34
+
35
+ pacemaker: MockPacemaker
36
+
37
+ def __init__(self, *args, **kwargs):
38
+ super().__init__(*args, **kwargs)
39
+ self.pacemaker = MockPacemaker(self.pacemaker.delay)
File without changes