Coverage for tests/test_tutorial/test_parameter_types/test_file/test_tutorial003_an.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3from pathlib import Path 1abcdefgh

4 

5import typer 1abcdefgh

6from typer.testing import CliRunner 1abcdefgh

7 

8from docs_src.parameter_types.file import tutorial003_an as mod 1abcdefgh

9 

10runner = CliRunner() 1abcdefgh

11 

12app = typer.Typer() 1abcdefgh

13app.command()(mod.main) 1abcdefgh

14 

15 

16def test_main(tmpdir): 1abcdefgh

17 binary_file = Path(tmpdir) / "config.txt" 1abcdefgh

18 binary_file.write_bytes(b"la cig\xc3\xbce\xc3\xb1a trae al ni\xc3\xb1o") 1abcdefgh

19 result = runner.invoke(app, ["--file", f"{binary_file}"]) 1abcdefgh

20 binary_file.unlink() 1abcdefgh

21 assert result.exit_code == 0 1abcdefgh

22 assert "Processed bytes total:" in result.output 1abcdefgh

23 

24 

25def test_script(): 1abcdefgh

26 result = subprocess.run( 1abcdefgh

27 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

28 capture_output=True, 

29 encoding="utf-8", 

30 ) 

31 assert "Usage" in result.stdout 1abcdefgh