generated from daniil-berg/boilerplate-py
✨ Overload @post_load
decorator to retain the function type
This commit is contained in:
@ -12,7 +12,9 @@ class GenericInsightMixinTestCase(TestCase):
|
||||
mock_super.return_value = MagicMock(__init_subclass__=mock_super_meth)
|
||||
|
||||
# Should be `None` by default:
|
||||
self.assertIsNone(_util.GenericInsightMixin._type_arg) # type: ignore[misc]
|
||||
self.assertIsNone(
|
||||
_util.GenericInsightMixin._type_arg # type: ignore[misc]
|
||||
)
|
||||
|
||||
# If the mixin type argument was not specified (still generic),
|
||||
# ensure that the attribute remains `None` on the subclass:
|
||||
|
28
tests/test_decorators.py
Normal file
28
tests/test_decorators.py
Normal file
@ -0,0 +1,28 @@
|
||||
from collections.abc import Callable
|
||||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from marshmallow_generic import decorators
|
||||
|
||||
|
||||
class DecoratorsTestCase(TestCase):
|
||||
@patch.object(decorators, "_post_load")
|
||||
def test_post_load(self, mock_original_post_load: MagicMock) -> None:
|
||||
mock_original_post_load.return_value = expected_output = object()
|
||||
|
||||
def test_function(x: int) -> str:
|
||||
return str(x)
|
||||
|
||||
pass_many, pass_original = MagicMock(), MagicMock()
|
||||
# Explicit annotation to possibly catch mypy errors:
|
||||
output: Callable[[int], str] = decorators.post_load(
|
||||
test_function,
|
||||
pass_many=pass_many,
|
||||
pass_original=pass_original,
|
||||
)
|
||||
self.assertIs(expected_output, output)
|
||||
mock_original_post_load.assert_called_once_with(
|
||||
test_function,
|
||||
pass_many=pass_many,
|
||||
pass_original=pass_original,
|
||||
)
|
Reference in New Issue
Block a user