This commit is contained in:
@@ -30,14 +30,49 @@ def test_singleton_identity():
|
||||
|
||||
# Test: typename()
|
||||
|
||||
@pytest.mark.parametrize("obj,expected", [
|
||||
import pytest
|
||||
import types
|
||||
import math
|
||||
import sys
|
||||
|
||||
# Une classe un peu plus complexe
|
||||
|
||||
def sample_function(x):
|
||||
def nested(y):
|
||||
return y + x
|
||||
return nested
|
||||
|
||||
@pytest.mark.parametrize("obj, expected", [
|
||||
|
||||
(None, "NoneType"),
|
||||
(True, "bool"),
|
||||
(42, "int"),
|
||||
("hello", "str"),
|
||||
(test_singleton_class, "test_singleton_class"),
|
||||
(3.14, "float"),
|
||||
("text", "str"),
|
||||
({1, 2, 3}, "set"),
|
||||
([[1], [2, 3]], "list"),
|
||||
([{"a": [1, 2]}, {"b": (3, 4)}], "list"),
|
||||
({"key": [{"nested": 1}, (2, 3)]}, "dict"),
|
||||
|
||||
# Fonctions
|
||||
(lambda x: x, "<lambda>"),
|
||||
(sample_function, "sample_function"),
|
||||
(sample_function(10), "nested"),
|
||||
(len, "len"),
|
||||
(sum, "sum"),
|
||||
|
||||
# Modules
|
||||
(math, "math"),
|
||||
(sys, "sys"),
|
||||
(types.FunctionType, "FunctionType"),
|
||||
((i for i in range(3)), "generator"),
|
||||
(iter([1, 2, 3]), "list_iterator"),
|
||||
])
|
||||
|
||||
def test_typename(obj, expected):
|
||||
assert typename(obj) == expected
|
||||
|
||||
|
||||
# Test: next_int()
|
||||
|
||||
@pytest.mark.parametrize("nums,expected", [
|
||||
|
||||
Reference in New Issue
Block a user