Coverage for tests / test_param_meta_empty.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import typer 1abcdefghij

2from typer.testing import CliRunner 1abcdefghij

3 

4runner = CliRunner() 1abcdefghij

5 

6 

7def test_default_with_class_with_custom_eq(): 1abcdefghij

8 app = typer.Typer() 1abcdefghij

9 

10 from typer.models import ParamMeta 1abcdefghij

11 

12 class StupidClass: 1abcdefghij

13 def __init__(self, a): 1abcdefghij

14 self.a = a 1abcdefghij

15 

16 def __eq__(self, other) -> bool: 1abcdefghij

17 if other is ParamMeta.empty: 1abcdefghij

18 return True 1abcdefghij

19 try: 1abcdefghij

20 return self.a == other.a 1abcdefghij

21 except Exception: 1abcdefghij

22 return False 1abcdefghij

23 

24 def __ne__(self, other: object) -> bool: 1abcdefghij

25 return not self.__eq__(other) 1abcdefghij

26 

27 @app.command() 1abcdefghij

28 def cmd(val=StupidClass(42)): 1abcdefghij

29 print(val) 1abcdefghij

30 

31 assert StupidClass(666) == ParamMeta.empty 1abcdefghij

32 assert StupidClass(666) != StupidClass(1) 1abcdefghij

33 

34 result = runner.invoke(app) 1abcdefghij

35 assert result.exit_code == 0, result.output 1abcdefghij

36 assert "StupidClass" in result.output 1abcdefghij