From 25ecc6fafc537c3ac38da75dd3ebcee4a5cfc6d4 Mon Sep 17 00:00:00 2001 From: mpa Date: Tue, 18 Aug 2020 16:10:44 +0400 Subject: [PATCH] tests(storages): improve tests add .cov config report ignores --- .coveragerc | 5 +++++ tests/test_dispatcher/test_state/test_context.py | 10 +++++++++- tests/test_dispatcher/test_storage/test_dict.py | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index e69de29b..40894721 100644 --- a/.coveragerc +++ b/.coveragerc @@ -0,0 +1,5 @@ +[report] +exclude_lines = + pragma: no cover + if TYPE_CHECKING: + raise NotImplementedError diff --git a/tests/test_dispatcher/test_state/test_context.py b/tests/test_dispatcher/test_state/test_context.py index 6f0dc132..412bf73f 100644 --- a/tests/test_dispatcher/test_state/test_context.py +++ b/tests/test_dispatcher/test_state/test_context.py @@ -69,7 +69,7 @@ class TestCurrentUserContext: mocked.assert_awaited() @pytest.mark.asyncio - @pytest.mark.parametrize("getter_method", ("set_state", "set_data")) + @pytest.mark.parametrize("getter_method", ("get_state", "get_data")) async def test_getters(self, storage, getter_method): chat_id, user_id = 1, 2 ctx = CurrentUserContext(storage, chat_id, user_id) @@ -78,6 +78,10 @@ class TestCurrentUserContext: await getattr(ctx, getter_method)() mocked.assert_awaited() + assert await getattr(ctx, getter_method)() == await getattr(storage, getter_method)( + key=ctx.key + ) + @pytest.mark.asyncio @pytest.mark.parametrize("reseter_method", ("reset_data", "reset_state", "finish")) async def test_setters(self, storage, reseter_method): @@ -116,3 +120,7 @@ class TestCurrentUserContext: new_data = LegitMapping() assert await ctx.update_data(data=new_data) is None assert await ctx.get_data() == new_data + + await ctx.reset_data() + assert await ctx.update_data(data=None) is None + assert await ctx.get_data() == {} diff --git a/tests/test_dispatcher/test_storage/test_dict.py b/tests/test_dispatcher/test_storage/test_dict.py index 7961161f..527fcdf8 100644 --- a/tests/test_dispatcher/test_storage/test_dict.py +++ b/tests/test_dispatcher/test_storage/test_dict.py @@ -51,6 +51,11 @@ class TestDictStorage: assert await storage.reset_data(key=key) is None assert await storage.get_data(key=key) == {} # reset_data makes data empty dict + new_data = {"abc": "abc"} + assert await storage.update_data(key=key, data=new_data) is None + assert await storage.update_data(key=key, data=None) is None + assert await storage.get_data(key=key) == new_data + @pytest.mark.asyncio async def test_finish(self): # finish turns data into initial one