Skip to content

Commit

Permalink
Add typing to propcache_module in tests (#33)
Browse files Browse the repository at this point in the history
Add typing to propcache_module
  • Loading branch information
bdraco authored Oct 6, 2024
1 parent d85d326 commit f2105c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
17 changes: 9 additions & 8 deletions tests/test_cached_property.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from operator import not_
from types import ModuleType

import pytest


def test_cached_property(propcache_module) -> None:
def test_cached_property(propcache_module: ModuleType) -> None:
class A:
def __init__(self):
self._cache = {}
Expand All @@ -16,7 +17,7 @@ def prop(self):
assert a.prop == 1


def test_cached_property_class(propcache_module) -> None:
def test_cached_property_class(propcache_module: ModuleType) -> None:
class A:
def __init__(self):
"""Init."""
Expand All @@ -30,7 +31,7 @@ def prop(self):
assert A.prop.__doc__ == "Docstring."


def test_cached_property_without_cache(propcache_module) -> None:
def test_cached_property_without_cache(propcache_module: ModuleType) -> None:
class A:

__slots__ = ()
Expand All @@ -48,7 +49,7 @@ def prop(self):
a.prop = 123


def test_cached_property_check_without_cache(propcache_module) -> None:
def test_cached_property_check_without_cache(propcache_module: ModuleType) -> None:
class A:

__slots__ = ()
Expand All @@ -65,7 +66,7 @@ def prop(self):
assert a.prop == 1


def test_cached_property_caching(propcache_module) -> None:
def test_cached_property_caching(propcache_module: ModuleType) -> None:

class A:
def __init__(self):
Expand All @@ -80,7 +81,7 @@ def prop(self):
assert 1 == a.prop


def test_cached_property_class_docstring(propcache_module) -> None:
def test_cached_property_class_docstring(propcache_module: ModuleType) -> None:

class A:
def __init__(self):
Expand All @@ -94,7 +95,7 @@ def prop(self):
assert "Docstring." == A.prop.__doc__


def test_set_name(propcache_module) -> None:
def test_set_name(propcache_module: ModuleType) -> None:
"""Test that the __set_name__ method is called and checked."""

class A:
Expand All @@ -110,7 +111,7 @@ def prop(self):
A.prop.__set_name__(A, "something_else")


def test_get_without_set_name(propcache_module) -> None:
def test_get_without_set_name(propcache_module: ModuleType) -> None:
"""Test that get without __set_name__ fails."""
cp = propcache_module.cached_property(not_)

Expand Down
18 changes: 11 additions & 7 deletions tests/test_under_cached_property.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from types import ModuleType

import pytest


def test_under_cached_property(propcache_module) -> None:
def test_under_cached_property(propcache_module: ModuleType) -> None:
class A:
def __init__(self):
self._cache = {}
Expand All @@ -14,7 +16,7 @@ def prop(self):
assert a.prop == 1


def test_under_cached_property_class(propcache_module) -> None:
def test_under_cached_property_class(propcache_module: ModuleType) -> None:
class A:
def __init__(self):
"""Init."""
Expand All @@ -28,7 +30,7 @@ def prop(self):
assert A.prop.__doc__ == "Docstring."


def test_under_cached_property_assignment(propcache_module) -> None:
def test_under_cached_property_assignment(propcache_module: ModuleType) -> None:
class A:
def __init__(self):
self._cache = {}
Expand All @@ -43,7 +45,7 @@ def prop(self):
a.prop = 123


def test_under_cached_property_without_cache(propcache_module) -> None:
def test_under_cached_property_without_cache(propcache_module: ModuleType) -> None:
class A:
def __init__(self):
pass
Expand All @@ -58,7 +60,9 @@ def prop(self):
a.prop = 123


def test_under_cached_property_check_without_cache(propcache_module) -> None:
def test_under_cached_property_check_without_cache(
propcache_module: ModuleType,
) -> None:
class A:
def __init__(self):
pass
Expand All @@ -72,7 +76,7 @@ def prop(self):
assert a.prop == 1


def test_under_cached_property_caching(propcache_module) -> None:
def test_under_cached_property_caching(propcache_module: ModuleType) -> None:

class A:
def __init__(self):
Expand All @@ -87,7 +91,7 @@ def prop(self):
assert 1 == a.prop


def test_under_cached_property_class_docstring(propcache_module) -> None:
def test_under_cached_property_class_docstring(propcache_module: ModuleType) -> None:
class A:
def __init__(self):
"""Init."""
Expand Down

0 comments on commit f2105c0

Please sign in to comment.