| 1 | """Tests of running a program that uses command line arguments. |
| 2 | """ |
| 3 | |
| 4 | import sys |
| 5 | import subprocess |
| 6 | |
| 7 | |
| 8 | def run(*args): |
| 9 | proc = subprocess.run( |
| 10 | [ |
| 11 | sys.executable, |
| 12 | "-m", |
| 13 | "friendly_traceback", |
| 14 | "tests/adder.py", |
| 15 | "--", |
| 16 | *args, |
| 17 | ], |
| 18 | stdout=subprocess.PIPE, |
| 19 | stderr=subprocess.PIPE, |
| 20 | universal_newlines=True, |
| 21 | check=False, |
| 22 | ) |
| 23 | return proc.stdout |
| 24 | |
| 25 | |
| 26 | def test_args_float(): |
| 27 | result = run("1", "2.5", "3") |
| 28 | assert "The sum is 6.5." in result |
| 29 | |
| 30 | |
| 31 | def test_args_to_int(): |
| 32 | result = run("1", "2.5", "3", "--to_int") |
| 33 | assert "The sum is 6." in result |