Coverage for tests/unit/test_kappa.py: 100%
39 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-04 03:33 -0600
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-04 03:33 -0600
1from typing import Mapping
3import pytest
5from muutils.kappa import _BASE_DOC, Kappa
8def test_Kappa_returns_Kappa_instance():
9 func = lambda x: x**2 # noqa: E731
10 result = Kappa(func)
11 assert isinstance(result, Mapping), "Kappa did not return a Mapping instance"
14def test_Kappa_getitem_calls_func():
15 func = lambda x: x**2 # noqa: E731
16 result = Kappa(func)
17 assert result[2] == 4, "__getitem__ did not correctly call the input function"
20def test_Kappa_doc_is_correctly_formatted():
21 func = lambda x: x**2 # noqa: E731
22 result = Kappa(func)
23 expected_doc = _BASE_DOC + "None"
24 assert result.doc == expected_doc, "doc was not correctly formatted"
27def test_Kappa_getitem_works_with_different_functions():
28 func = lambda x: x + 1 # noqa: E731
29 result = Kappa(func)
30 assert result[2] == 3, "__getitem__ did not correctly call the input function"
32 func = lambda x: str(x) # noqa: E731
33 result = Kappa(func)
34 assert result[2] == "2", "__getitem__ did not correctly call the input function"
37def test_Kappa_iter_raises_NotImplementedError():
38 func = lambda x: x**2 # noqa: E731
39 result = Kappa(func)
40 with pytest.raises(NotImplementedError):
41 iter(result)
44def test_Kappa_len_raises_NotImplementedError():
45 func = lambda x: x**2 # noqa: E731
46 result = Kappa(func)
47 with pytest.raises(NotImplementedError):
48 len(result)
51def test_Kappa_doc_works_with_function_with_docstring():
52 func = lambda x: x**2 # noqa: E731
53 func.__doc__ = "This is a test function"
54 result = Kappa(func)
55 expected_doc = _BASE_DOC + "This is a test function"
56 assert (
57 result.doc == expected_doc
58 ), "doc was not correctly formatted with function with docstring"