1+ """Configuration and fixtures for pytest.
2+
3+ (AI generated docstring)
4+
5+ This module provides shared fixtures and utility functions for the test suite,
6+ including data paths, source code samples, and standardized assertion helpers.
7+
8+ """
19# pyright: standard
210from collections .abc import Callable
311from typing import Any
614import pytest
715
816# SSOT for test data paths and filenames
9- pathDataSamples = pathlib .Path ("hunterMakesPy/tests/dataSamples" )
17+ pathDataSamples : pathlib . Path = pathlib .Path ("hunterMakesPy/tests/dataSamples" )
1018
1119# Fixture to provide a temporary directory for filesystem tests
1220@pytest .fixture
1321def pathTmpTesting (tmp_path : pathlib .Path ) -> pathlib .Path :
22+ """Provide a temporary directory for filesystem tests.
23+
24+ (AI generated docstring)
25+
26+ Parameters
27+ ----------
28+ tmp_path : pathlib.Path
29+ The pytest built-in temporary path fixture.
30+
31+ Returns
32+ -------
33+ pathTmpTesting : pathlib.Path
34+ The path to the temporary directory.
35+
36+ """
1437 return tmp_path
1538
1639# Fixture for predictable Python source code samples
@@ -44,7 +67,27 @@ def listFileContentsFibonacci() -> list[str]:
4467 return ['fibonacci8' , 'fibonacci13' , 'fibonacci21' , 'fibonacci34' ]
4568
4669def uniformTestFailureMessage (expected : Any , actual : Any , functionName : str , * arguments : Any , ** keywordArguments : Any ) -> str :
47- """Format assertion message for any test comparison."""
70+ """Format assertion message for any test comparison.
71+
72+ Parameters
73+ ----------
74+ expected : Any
75+ The expected value or outcome.
76+ actual : Any
77+ The actual value or outcome received.
78+ functionName : str
79+ The name of the function or test case being executed.
80+ *arguments : Any
81+ Positional arguments passed to the function having its return value checked.
82+ **keywordArguments : Any
83+ Keyword arguments passed to the function having its return value checked.
84+
85+ Returns
86+ -------
87+ message : str
88+ A formatted failure message detailing the expectation vs reality.
89+
90+ """
4891 listArgumentComponents : list [str ] = [str (parameter ) for parameter in arguments ]
4992 listKeywordComponents : list [str ] = [f"{ key } ={ value } " for key , value in keywordArguments .items ()]
5093 joinedArguments : str = ', ' .join (listArgumentComponents + listKeywordComponents )
@@ -54,7 +97,22 @@ def uniformTestFailureMessage(expected: Any, actual: Any, functionName: str, *ar
5497 f"Got: { actual } " )
5598
5699def standardizedEqualTo (expected : Any , functionTarget : Callable [..., Any ], * arguments : Any , ** keywordArguments : Any ) -> None :
57- """Template for most tests to compare the actual outcome with the expected outcome, including expected errors."""
100+ """Template for most tests to compare actual outcome with expected outcome.
101+
102+ Includes handling for expected errors/exceptions.
103+
104+ Parameters
105+ ----------
106+ expected : Any
107+ The expected return value, or an Exception type if an error is expected.
108+ functionTarget : Callable[..., Any]
109+ The function to call and test.
110+ *arguments : Any
111+ Positional arguments to pass to `functionTarget`.
112+ **keywordArguments : Any
113+ Keyword arguments to pass to `functionTarget`.
114+
115+ """
58116 if type (expected ) == type [Exception ]: # noqa: E721
59117 messageExpected : str = expected .__name__
60118 else :
@@ -63,7 +121,23 @@ def standardizedEqualTo(expected: Any, functionTarget: Callable[..., Any], *argu
63121 try :
64122 messageActual = actual = functionTarget (* arguments , ** keywordArguments )
65123 except Exception as actualError :
66- messageActual : str = type (actualError ).__name__
124+ messageActual = type (actualError ).__name__
67125 actual = type (actualError )
68126
69- assert actual == expected , uniformTestFailureMessage (messageExpected , messageActual , functionTarget .__name__ , * arguments , ** keywordArguments )
127+ functionName : str = getattr (functionTarget , "__name__" , functionTarget .__class__ .__name__ )
128+ assert actual == expected , uniformTestFailureMessage (messageExpected , messageActual , functionName , * arguments , ** keywordArguments )
129+
130+ # Why I wish I could figure out how to implement standardized* test functions.
131+ # ruff: noqa: ERA001
132+ # standardizedEqualTo(expected, updateExtendPolishDictionaryLists, *value_dictionaryLists, **keywordArguments)
133+ # NOTE one line of code with `standardizedEqualTo` (above) replaced the following ten lines of code. Use `standardizedEqualTo`.
134+ # if isinstance(expected, type) and issubclass(expected, Exception):
135+ # with pytest.raises(expected):
136+ # updateExtendPolishDictionaryLists(*value_dictionaryLists, **keywordArguments)
137+ # else:
138+ # result = updateExtendPolishDictionaryLists(*value_dictionaryLists, **keywordArguments)
139+ # if description == "Set values": # Special handling for unordered sets
140+ # for key in result:
141+ # assert sorted(result[key]) == sorted(expected[key])
142+ # else:
143+ # assert result == expected
0 commit comments