The test suite uses pytest and covers 63+ cases across core arithmetic, edge cases, error handling, and GUI behavior. GUI tests run headlessly via tkinter mocks defined inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/WorkTeam01/team-practice/llms.txt
Use this file to discover all available pages before exploring further.
conftest.py, which replace real tkinter components with lightweight Python dummy classes — no display or Tcl/Tk runtime required.
Prerequisites
Install all test dependencies with a single command. The only runtime requirement for testing ispytest>=7.0.0, declared in requirements.txt:
requirements.txt contains:
Running all tests
Run the full test suite from the project root:-v flag enables verbose output, printing each test name and its pass/fail status as it runs.
Running specific modules
Target a single test file to focus on one area of the codebase:Filtering by test name
Use the-k flag to run only tests whose names match a keyword. This is especially useful when iterating on a specific feature, such as parenthesis handling:
test_gui.py whose name contains the word parenthesis — for example, test_parenthesis_basic, test_parenthesis_nested, and test_parenthesis_with_power.
Coverage report
Coverage reporting requires
pytest-cov, which is not included in requirements.txt. Install it separately before running the commands in this section:htmlcov/index.html in your browser to browse line-by-line coverage for every file in the src/ package.
Test structure
The suite is organized across three files in thetests/ directory:
-
tests/test_calculator.py— Unit tests for the 8 core mathematical functions imported directly fromsrc.calculator. These tests exercise pure logic with no GUI dependency. The test functions are:test_add— basic addition with positive, negative, and zero inputstest_subtract— basic subtraction including results that are negativetest_multiply— multiplication with zeros and sign combinationstest_divide— floating-point division with mixed signstest_divide_by_zero— verifies thatdivide(10, 0)raisesZeroDivisionErrortest_power— integer and fractional exponents, including aValueErrorguard for negative bases with fractional powerstest_valor_maximo—valor_maximoreturns the larger of two numberstest_valor_minimo—valor_minimoreturns the smaller of two numberstest_abs_value— absolute value for negative, positive, and zero inputs
-
tests/test_gui.py— Integration-style tests for theCalculatorGUIclass. They instantiate the full GUI object and call its public methods (number_button_click,operation_click,equals_click,scientific_click,open_parenthesis_click, etc.) to simulate user interactions and assert oncalc.current_value. -
tests/conftest.py— Shared pytest configuration. Defines dummy tkinter classes (DummyRoot,DummyEntry,DummyButton,DummyLabel) and anautouse=Truefixture that patches them in before every test, so the GUI can be instantiated without a real display.
Understanding the tkinter mocks
conftest.py makes GUI tests portable by replacing the real tkinter widgets with minimal Python objects that implement just enough of the tkinter API for the CalculatorGUI constructor and methods to work. The four dummy classes are:
DummyRoot— mimicstk.Tk, implementstitle(),geometry(),configure(),grid_rowconfigure(),grid_columnconfigure(),mainloop(),bind(),after(), anddestroy().DummyEntry— mimicstk.Entry, tracks an internal_textstring and exposesdelete(),insert(), andget().DummyButton— mimicstk.Button, accepts constructor arguments and agrid()call but does nothing.DummyLabel— mimicstk.Label, stores a_textvalue and supportsconfig(text=...)updates.
replace_tkinter fixture is marked autouse=True, so pytest applies it to every test automatically — no explicit @pytest.mark.usefixtures decorator is needed:
try / finally block guarantees that the original tkinter classes are always restored after each test, keeping tests fully isolated from one another.
Example tests
The following tests fromtest_calculator.py illustrate the testing style used throughout the suite.
test_divide_by_zero verifies that the divide function raises the correct built-in exception rather than returning an incorrect value or silently swallowing the error:
test_power checks multiple scenarios in a single test function — integer exponents, a zero exponent, a fractional exponent (square root), negative bases, and the guarded case where a negative base with a fractional exponent must raise ValueError:
