@@ -23,7 +23,7 @@ The effects of time removal can be seen from both sides:
2323 all activities of the event loop, such as sleeps, events/conditions waits,
2424 timeouts, "later" callbacks, happen in near-zero amount of the real time
2525 (above the usual code overhead).
26- This speeds up the tests execution without breaking the tests' time-based
26+ This speeds up the execution of tests without breaking the tests' time-based
2727 design, even if they are designed to run in seconds or minutes.
2828
2929For the latter case, there are a few exceptions when the event loop's activities
@@ -65,8 +65,8 @@ In textbook cases with simple coroutines that are more like regular functions,
6565it is possible to design a test so that it runs straight to the end in one hop
6666— with all the preconditions set and data prepared in advance in the test setup.
6767
68- However, in the real-world cases, the tests often must verify that
69- the corotuine stops at some point, waits for a condition for some limited time,
68+ However, in real-world cases, the tests often must verify that
69+ the coroutine stops at some point, waits for a condition for some limited time,
7070and then passes or fails.
7171
7272The problem is often "solved" by mocking the low-level coroutines of sleep/wait
@@ -77,8 +77,8 @@ of how the coroutine is implemented internally, which can change over time.
7777Good tests do not change on refactoring if the protocol remains the same.
7878
7979Another (straightforward) approach is to not mock the low-level routines, but
80- to spend the real-world time, just in short bursts as hard-cded in the test.
81- Not only it makes the whole test-suite slower, it also brings the exection
80+ to spend the real-world time, just in short bursts as hard-coded in the test.
81+ Not only it makes the whole test-suite slower, it also brings the execution
8282time close to the values where the code overhead affects the timing
8383and makes it difficult to assert on the coroutine's pure time.
8484
@@ -107,7 +107,7 @@ pip install pytest-asyncio
107107pip install looptime
108108```
109109
110- Nothing is needed to make async tests to run with the fake time, it just works:
110+ Nothing is needed to make async tests run with the fake time, it just works:
111111
112112``` python
113113import asyncio
@@ -203,14 +203,14 @@ for each setting separately (i.e. not the closest marker as a whole).
203203marked as using the fake loop time —including those not marked at all—
204204as if all tests were implicitly marked.
205205
206- ` --no-looptime ` runs all tests —both marked and unmarked— with real time.
206+ ` --no-looptime ` runs all tests —both marked and unmarked— with the real time.
207207This flag effectively disables the plugin.
208208
209209
210210## Settings
211211
212212The marker accepts several settings for the test. The closest to the test
213- function applies. This lets you to define the test-suite defaults
213+ function applies. This lets you define the test-suite defaults
214214and override them on the directory, module, class, function, or test level:
215215
216216``` python
@@ -232,7 +232,7 @@ async def test_me():
232232` start ` (` float ` or ` None ` , or a no-argument callable that returns the same)
233233is the initial time of the event loop.
234234
235- If it is a callable, it is invoked once per event loop to get the value:
235+ If it is callable, it is invoked once per event loop to get the value:
236236e.g. ` start=time.monotonic ` to align with the true time,
237237or ` start=lambda: random.random() * 100 ` to add some unpredictability.
238238
@@ -286,7 +286,7 @@ Normally, it should not fail. However, with fake time (without workarounds)
286286the following scenario is possible:
287287
288288* ` async_timeout ` library sets its delayed timer at 9 seconds since now.
289- * the event loop notices that there is and and only one timer at T0+9s.
289+ * the event loop notices that there is only one timer at T0+9s.
290290* the event loop fast-forwards time to be ` 9 ` .
291291* since there are no other handles/timers, that timer is executed.
292292* ` async_timeout ` fails the test with ` asyncio.TimeoutError `
@@ -341,11 +341,11 @@ However, with the fake time (with no workarounds), the following happens:
341341* The test suppresses the timeout, checks the assertion, and fails:
342342 the sync event is still unset.
343343* A fraction of a second (e.g. ` 0.001 ` second) later, the thread starts,
344- calls the function, and sets the sync event, but it is too late.
344+ calls the function and sets the sync event, but it is too late.
345345
346346Compared to the fake fast-forwarding time, even such fast things as threads
347347are too slow to start. Unfortunately, ` looptime ` and the event loop can
348- neither control what is happening outside of the event loop, nor predict
348+ neither control what is happening outside of the event loop nor predict
349349how long it will take.
350350
351351To work around this, ` looptime ` remembers all calls to executors and then
@@ -357,11 +357,11 @@ So, the fake time and real time move along while waiting for executors.
357357Luckily for this case, in 1 or 2 such steps, the executor's thread will
358358do its job, the event will be set, so as the synchronous & asynchronous
359359futures of the executor. The latter one (the async future) will also
360- let the ` await ` to move on.
360+ let the ` await ` move on.
361361
362362The ` idle_step ` (` float ` or ` None ` ) setting is the duration of a single
363363time step when fast-forwarding the time if there are executors used —
364- i.e. if there are some synchronous tasks running in the thread pools.
364+ i.e. if some synchronous tasks are running in the thread pools.
365365
366366Note that the steps are both true-time and fake-time: they spend the same
367367amount of the observer's true time as they increment the loop's fake time.
@@ -395,7 +395,7 @@ With no workarounds, the test will hang forever waiting for the i/o to happen.
395395This mostly happens when the only thing left in the event loop is the i/o,
396396all internal scheduled callbacks are gone.
397397
398- ` looptime ` can artifically limit the lifetime of the event loop.
398+ ` looptime ` can artificially limit the lifetime of the event loop.
399399This can be done as a default setting for the whole test suite, for example.
400400
401401The ` idle_timeout ` (` float ` or ` None ` ) setting is the true-time limit
@@ -441,7 +441,7 @@ while `looptime(end=N)` applies to the lifecycle of the whole event loop,
441441which is usually the duration of the whole test and monotonically increases.
442442
443443Second, ` looptime(end=N) ` syncs the loop time with the real time for N seconds,
444- i.e. it does not instantly fast-forwards the loop time when the loops
444+ i.e. it does not instantly fast-forward the loop time when the loops
445445attempts to make an "infinite sleep" (technically, ` selector.select(None) ` ).
446446` async_timeout.timeout() ` and ` asyncio.wait_for() ` set a delayed callback,
447447so the time fast-forwards to it on the first possible occasion.
@@ -560,7 +560,7 @@ async def test_me(chronometer, event_loop):
560560
561561### Loop time assertions
562562
563- The ` looptime ` ** fixture** is a syntax sugar for easy loop time assertions::
563+ The ` looptime ` ** fixture** is syntax sugar for easy loop time assertions::
564564
565565``` python
566566import asyncio
@@ -575,13 +575,13 @@ async def test_me(looptime):
575575
576576Technically, it is a proxy object to ` asyncio.get_running_loop().time() ` .
577577The proxy object supports the direct comparison with numbers (integers/floats),
578- so as some basic arithmetics (adding, substracting , multiplication, etc).
578+ so as some basic arithmetics (adding, subtracting , multiplication, etc).
579579However, it adjusts to the time precision of 1 nanosecond (1e-9): every digit
580580beyond that precision is ignored — so you can be not afraid of
581581` 123.456/1.2 ` suddenly becoming ` 102.88000000000001 ` and not equal to ` 102.88 `
582582(as long as the time proxy object is used and not converted to a native float).
583583
584- The proxy object can be used to create a new proxy which is bound to a specific
584+ The proxy object can be used to create a new proxy that is bound to a specific
585585event loop (it works for loops both with fake- and real-world time)::
586586
587587``` python
0 commit comments