Coverage for tests / test_param_meta_empty.py: 100%
26 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-26 21:46 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-26 21:46 +0000
1import typer 1abcdefg
2from typer.testing import CliRunner 1abcdefg
4runner = CliRunner() 1abcdefg
7def test_default_with_class_with_custom_eq(): 1abcdefg
8 app = typer.Typer() 1abcdefg
10 from typer.models import ParamMeta 1abcdefg
12 class StupidClass: 1abcdefg
13 def __init__(self, a): 1abcdefg
14 self.a = a 1abcdefg
16 def __eq__(self, other) -> bool: 1abcdefg
17 if other is ParamMeta.empty: 1abcdefg
18 return True 1abcdefg
19 try: 1abcdefg
20 return self.a == other.a 1abcdefg
21 except Exception: 1abcdefg
22 return False 1abcdefg
24 def __ne__(self, other: object) -> bool: 1abcdefg
25 return not self.__eq__(other) 1abcdefg
27 @app.command() 1abcdefg
28 def cmd(val=StupidClass(42)): 1abcdefg
29 print(val) 1abcdefg
31 assert StupidClass(666) == ParamMeta.empty 1abcdefg
32 assert StupidClass(666) != StupidClass(1) 1abcdefg
34 result = runner.invoke(app) 1abcdefg
35 assert result.exit_code == 0, result.output 1abcdefg
36 assert "StupidClass" in result.output 1abcdefg