Coverage for tests/test_param_meta_empty.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1import typer 1abcdefghi

2from typer.testing import CliRunner 1abcdefghi

3 

4runner = CliRunner() 1abcdefghi

5 

6 

7def test_default_with_class_with_custom_eq(): 1abcdefghi

8 app = typer.Typer() 1abcdefghi

9 

10 from typer.models import ParamMeta 1abcdefghi

11 

12 class StupidClass: 1abcdefghi

13 def __init__(self, a): 1abcdefghi

14 self.a = a 1abcdefghi

15 

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

17 if other is ParamMeta.empty: 1abcdefghi

18 return True 1abcdefghi

19 try: 1abcdefghi

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

21 except Exception: 1abcdefghi

22 return False 1abcdefghi

23 

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

25 return not self.__eq__(other) 1abcdefghi

26 

27 @app.command() 1abcdefghi

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

29 print(val) 1abcdefghi

30 

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

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

33 

34 result = runner.invoke(app) 1abcdefghi

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

36 assert "StupidClass" in result.output 1abcdefghi