From 33daf43e3dc295d4f4e174e0e69a1786368a041e Mon Sep 17 00:00:00 2001 From: treff7es Date: Tue, 18 Oct 2022 17:17:27 +0200 Subject: [PATCH 1/2] Adding fix for python8 Adding missing tests --- .../src/datahub/utilities/memory_footprint.py | 5 ++-- .../unit/utilities/test_memory_footprint.py | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 metadata-ingestion/tests/unit/utilities/test_memory_footprint.py diff --git a/metadata-ingestion/src/datahub/utilities/memory_footprint.py b/metadata-ingestion/src/datahub/utilities/memory_footprint.py index 9fc1900441426a..fa9e64cbf47380 100644 --- a/metadata-ingestion/src/datahub/utilities/memory_footprint.py +++ b/metadata-ingestion/src/datahub/utilities/memory_footprint.py @@ -1,7 +1,7 @@ from collections import deque from itertools import chain from sys import getsizeof -from typing import Any, Dict +from typing import Any, Callable def total_size(o: Any, handlers: Any = {}) -> int: @@ -15,8 +15,7 @@ def total_size(o: Any, handlers: Any = {}) -> int: Based on https://github.com/ActiveState/recipe-577504-compute-mem-footprint/blob/master/recipe.py """ - def dict_handler(d: Dict) -> chain[Any]: - return chain.from_iterable(d.items()) + dict_handler: Callable[[Any], chain[Any]] = lambda d: chain.from_iterable(d.items()) all_handlers = { tuple: iter, diff --git a/metadata-ingestion/tests/unit/utilities/test_memory_footprint.py b/metadata-ingestion/tests/unit/utilities/test_memory_footprint.py new file mode 100644 index 00000000000000..0b8891c09ca107 --- /dev/null +++ b/metadata-ingestion/tests/unit/utilities/test_memory_footprint.py @@ -0,0 +1,23 @@ +from collections import defaultdict + +from datahub.utilities import memory_footprint + + +def test_total_size_with_empty_dict(): + size = memory_footprint.total_size({}) + assert size == 64 + + +def test_total_size_with_list(): + size = memory_footprint.total_size({"1": [1, 2, 3, 4]}) + assert size == 482 + + +def test_total_size_with_none(): + size = memory_footprint.total_size(None) + assert size == 16 + + +def test_total_size_with_defaultdict(): + size = memory_footprint.total_size(defaultdict) + assert size == 416 From 0501b5a93c632c6424d68dfe20a4d514f0380444 Mon Sep 17 00:00:00 2001 From: treff7es Date: Tue, 18 Oct 2022 17:41:06 +0200 Subject: [PATCH 2/2] Simplifying tests --- .../tests/unit/utilities/test_memory_footprint.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/metadata-ingestion/tests/unit/utilities/test_memory_footprint.py b/metadata-ingestion/tests/unit/utilities/test_memory_footprint.py index 0b8891c09ca107..703cb55f55686e 100644 --- a/metadata-ingestion/tests/unit/utilities/test_memory_footprint.py +++ b/metadata-ingestion/tests/unit/utilities/test_memory_footprint.py @@ -5,19 +5,23 @@ def test_total_size_with_empty_dict(): size = memory_footprint.total_size({}) - assert size == 64 + # Only asserting if it is bigger than 0 because the actual sizes differs per python version + assert size > 0 def test_total_size_with_list(): size = memory_footprint.total_size({"1": [1, 2, 3, 4]}) - assert size == 482 + # Only asserting if it is bigger than 0 because the actual sizes differs per python version + assert size > 0 def test_total_size_with_none(): size = memory_footprint.total_size(None) - assert size == 16 + # Only asserting if it is bigger than 0 because the actual sizes differs per python version + assert size > 0 def test_total_size_with_defaultdict(): size = memory_footprint.total_size(defaultdict) - assert size == 416 + # Only asserting if it is bigger than 0 because the actual sizes differs per python version + assert size > 0