Skip to content

Commit

Permalink
Renamed function to validate-invariants + documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahsonder committed Jul 26, 2023
1 parent 5187329 commit 8f255ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions docs/contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ AssertionError: divide argument '2' did not match type annotation for parameter

## API

The `python_ta.contracts` module offers three functions for enabling contract checking.
The `python_ta.contracts` module offers two functions for enabling contract checking.
The first, `check_all_contracts`, enables contract checking for all functions and classes defined within a module or set of modules.
The second, `check_contracts`, is a decorator allowing more fine-grained control over which
functions/classes have contract checking enabled. The third, `check_invariants`, takes in an object and checks
that the representation invariants of the object are satisfied.
The second, `check_contracts`, is a decorator allowing more fine-grained control over which functions/classes have contract checking enabled.

```{eval-rst}
.. autofunction:: python_ta.contracts.check_all_contracts
Expand All @@ -62,6 +60,8 @@ that the representation invariants of the object are satisfied.
.. autofunction:: python_ta.contracts.check_contracts(func_or_class)
```

You can pass an object into the function `validate_invariants` to manually check the representation invariants of the object.

```{eval-rst}
.. autofunction:: python_ta.contracts.check_invariants(object)
```
Expand Down
2 changes: 1 addition & 1 deletion python_ta/contracts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def _set_invariants(klass: type) -> None:
setattr(klass, "__representation_invariants__", rep_invariants)


def check_invariants(obj: object) -> None:
def validate_invariants(obj: object) -> None:
"""Check that the representation invariants of obj are satisfied."""
klass = obj.__class__
klass_mod = _get_module(klass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from python_ta.contracts import check_contracts, check_invariants
from python_ta.contracts import check_contracts, validate_invariants


@check_contracts
Expand Down Expand Up @@ -34,9 +34,9 @@ def test_no_errors() -> None:
person = Person("Jim", 50, ["Pam", "Dwight"])

try:
check_invariants(person)
except Exception:
pytest.fail("check_invariants has incorrectly raised an error")
validate_invariants(person)
except AssertionError:
pytest.fail("check_invariants has incorrectly raised an AssertionError")


def test_raise_error() -> None:
Expand All @@ -45,4 +45,4 @@ def test_raise_error() -> None:
person.friends.pop()

with pytest.raises(AssertionError):
check_invariants(person)
validate_invariants(person)

0 comments on commit 8f255ae

Please sign in to comment.