Skip to content

Commit

Permalink
Merge pull request #63 from atlanticwave-sdx/increase-unittests
Browse files Browse the repository at this point in the history
XS✔ ◾ Increase unit test for utils
  • Loading branch information
gretelliz authored Sep 11, 2024
2 parents da9b458 + cab270c commit 4707232
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion topology-conversion/tests/test_unit/utils/test_typing_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import pytest
from unittest import mock
from typing import List, Dict, Generic, TypeVar

from utils.typing_utils import is_generic, is_dict, is_list

# Define type variables for testing
T = TypeVar('T')


@pytest.mark.parametrize("klass, expected", [
(List[int], True), # Test if List[int] is recognized as a generic class
(Dict[str, int], True), # Test if Dict[str, int] is recognized as a generic class
(int, False), # Test if int is not recognized as a generic class
(Generic[T], True), # Test if Generic[T] is recognized as a generic class
])
def test_is_generic_python_3_6(klass, expected):
"""Test `is_generic` function behavior with Python 3.6 (mocked version)"""
with mock.patch('sys.version_info', (3, 6)):
result = is_generic(klass)
assert result == expected

@pytest.mark.parametrize("klass, expected", [
(List[int], True), # Test if List[int] is recognized as a generic class
(Dict[str, int], True), # Test if Dict[str, int] is recognized as a generic class
Expand All @@ -21,6 +35,17 @@ def test_is_generic(klass, expected):
result = is_generic(klass)
assert result == expected

@pytest.mark.parametrize("klass, expected", [
(Dict[str, int], True), # Test if Dict[str, int] is recognized as a dict
(List[int], False), # Test if List[int] is not recognized as a dict
(Dict[str, Dict[str, int]], True), # Test nested dictionary
])
def test_is_dict_python_3_6(klass, expected):
"""Test `is_dict` function behavior with Python 3.6 (mocked version)"""
with mock.patch('sys.version_info', (3, 6)):
result = is_dict(klass)
assert result == expected

@pytest.mark.parametrize("klass, expected", [
(Dict[str, int], True), # Test if Dict[str, int] is recognized as a dict
(List[int], False), # Test if List[int] is not recognized as a dict
Expand All @@ -36,6 +61,17 @@ def test_is_dict(klass, expected):
result = is_dict(klass)
assert result == expected

@pytest.mark.parametrize("klass, expected", [
(List[int], True), # Test if List[int] is recognized as a list
(Dict[str, int], False), # Test if Dict[str, int] is not recognized as a list
(List[List[int]], True), # Test nested list
])
def test_is_list_python_3_6(klass, expected):
"""Test `is_list` function behavior with Python 3.6 (mocked version)"""
with mock.patch('sys.version_info', (3, 6)):
result = is_list(klass)
assert result == expected

@pytest.mark.parametrize("klass, expected", [
(List[int], True), # Test if List[int] is recognized as a list
(Dict[str, int], False), # Test if Dict[str, int] is not recognized as a list
Expand Down

0 comments on commit 4707232

Please sign in to comment.