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

22 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 tutorial005_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 config_file = Path(tmpdir) / "config.txt" 1abcdefgh

18 if config_file.exists(): # pragma: no cover 1abcdefgh

19 config_file.unlink() 

20 config_file.write_text("") 

21 result = runner.invoke(app, ["--config", f"{config_file}"]) 1abcdefgh

22 result = runner.invoke(app, ["--config", f"{config_file}"]) 1abcdefgh

23 result = runner.invoke(app, ["--config", f"{config_file}"]) 1abcdefgh

24 text = config_file.read_text() 1abcdefgh

25 config_file.unlink() 1abcdefgh

26 assert result.exit_code == 0 1abcdefgh

27 assert "Config line written" 1abcdefgh

28 assert "This is a single line\nThis is a single line\nThis is a single line" in text 1abcdefgh

29 

30 

31def test_script(): 1abcdefgh

32 result = subprocess.run( 1abcdefgh

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

34 capture_output=True, 

35 encoding="utf-8", 

36 ) 

37 assert "Usage" in result.stdout 1abcdefgh