Skip to content

Commit

Permalink
docs: fix typos in docs and type annotations (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Dec 23, 2022
1 parent 25dcdf1 commit 6481543
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_remove_todo(decoy: Decoy) -> None:

subject.remove("abc123")

decoy.verify(todo_store.remove(id="abc123"))
decoy.verify(todo_store.remove(id="abc123"), times=1)
```

See [spying with verify][] for more details.
Expand Down
12 changes: 6 additions & 6 deletions docs/advanced/context-managers.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ From this test, we could sketch out the following dependency APIs...
```python
# config.py
import contextlib
from typing import Iterator
from typing import Generator

class Config:
def read(self, name: str) -> bool:
...

class ConfigLoader:
@contextlib.contextmanager
def load(self) -> Iterator[Config]:
def load(self) -> Generator[Config, None, None]:
...
```

Expand All @@ -65,7 +65,7 @@ class ConfigLoader:
from .config import Config, ConfigLoader

class Core:
def __init__(self, config_laoder: ConfigLoader) -> None:
def __init__(self, config_loader: ConfigLoader) -> None:
self._config_loader = config_loader

def get_config(self, name: str) -> bool:
Expand All @@ -78,7 +78,7 @@ class Core:

## General context managers

A context manager is simply an object with both `__enter__` and `__exit__` methods defined. Decoy mocks have both these methods defined, so they are compatible with the `with` statement. In the author's opinion, tests that mock `__enter__` and `__exit__` (or any double-underscore method) are harder to read and understand than tests that do not, so generator-based context managers should be prefered where applicable.
A context manager is simply an object with both `__enter__` and `__exit__` methods defined. Decoy mocks have both these methods defined, so they are compatible with the `with` statement. In the author's opinion, tests that mock `__enter__` and `__exit__` (or any double-underscore method) are harder to read and understand than tests that do not, so generator-based context managers should be preferred where applicable.

Using our earlier example, maybe you'd prefer to use a single `Config` dependency to both load the configuration resource and read values.

Expand All @@ -101,7 +101,7 @@ def test_loads_config(decoy: Decoy) -> None:
"""Ensure test fails if subject calls `read` after exit."""
decoy.when(
config.read("some_flag")
).then_raise(AssertionError("Context manager was exitted"))
).then_raise(AssertionError("Context manager was exited"))

decoy.when(config.__enter__()).then_do(_handle_enter)
decoy.when(config.__exit__(None, None, None)).then_do(_handle_exit)
Expand Down Expand Up @@ -175,7 +175,7 @@ async def test_loads_config(decoy: Decoy) -> None:
"""Ensure test fails if subject calls `read` after exit."""
decoy.when(
config.read("some_flag")
).then_raise(AssertionError("Context manager was exitted"))
).then_raise(AssertionError("Context manager was exited"))

decoy.when(await config.__aenter__()).then_do(_handle_enter)
decoy.when(await config.__aexit__()).then_do(_handle_exit)
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ dep = decoy.mock()

decoy.when(
decoy.prop(dep.some_property).set(42)
).then_return(RuntimeError("oh no"))
).then_raise(RuntimeError("oh no"))

decoy.when(
decoy.prop(dep.some_property).delete()
).then_return(RuntimeError("what a disaster"))
).then_raise(RuntimeError("what a disaster"))

with pytest.raises(RuntimeError, match="oh no"):
dep.some_property = 42
Expand Down
4 changes: 2 additions & 2 deletions tests/test_decoy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Smoke and acceptance tests for main Decoy interface."""
import contextlib
import sys
from typing import Any, AsyncIterator, ContextManager, Iterator, Optional
from typing import Any, AsyncIterator, ContextManager, Generator, Optional

import pytest

Expand Down Expand Up @@ -267,7 +267,7 @@ def get_value(self) -> int:

class _ValueReaderLoader:
@contextlib.contextmanager
def get_value_reader(self) -> Iterator[_ValueReader]:
def get_value_reader(self) -> Generator[_ValueReader, None, None]:
...

value_reader_loader = decoy.mock(cls=_ValueReaderLoader)
Expand Down
4 changes: 2 additions & 2 deletions tests/typing/test_typing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@
skip: sys.version_info < (3, 7)
main: |
import contextlib
from typing import Iterator
from typing import Generator
from decoy import Decoy
@contextlib.contextmanager
def do_thing(input: str) -> Iterator[int]:
def do_thing(input: str) -> Generator[int, None, None]:
yield 42
decoy = Decoy()
Expand Down

0 comments on commit 6481543

Please sign in to comment.