From eb66fd8704b564fd28feeddc26c85b726425e503 Mon Sep 17 00:00:00 2001 From: TheoBrunner Date: Sun, 7 Feb 2021 20:35:07 +0100 Subject: [PATCH] 1. Kaptiel fertig --- .gitignore | 1 + 01_hello/hello.py | 26 ++++++++++++++++++++++++++ 01_hello/test.py | 11 ++++++----- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 01_hello/hello.py diff --git a/.gitignore b/.gitignore index 68ca39690..d6068ff6c 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ tex2pdf* 19_wod/wod.py 20_password/password.py 21_tictactoe/tictactoe.py +venv \ No newline at end of file diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100644 index 000000000..a957a7440 --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +""" +Author: Theo Brunner +Purpose: Say hello +""" + +import argparse + + +def get_args(): + """Get the command-line arguments""" + + parser = argparse.ArgumentParser(description='Say hello') + parser.add_argument('-n', '--name', metavar='name', + default='World', help='Name to great') + return parser.parse_args() + + +def main(): + """Main programm""" + args = get_args() + print('Hello, ' + args.name + '!') + + +if __name__ == '__main__': + main() diff --git a/01_hello/test.py b/01_hello/test.py index d0cedd1c2..a27f244ef 100755 --- a/01_hello/test.py +++ b/01_hello/test.py @@ -4,7 +4,7 @@ import os from subprocess import getstatusoutput, getoutput -prg = './hello.py' +prg = './hello08_formatted.py' # -------------------------------------------------- @@ -18,7 +18,7 @@ def test_exists(): def test_runnable(): """Runs using python3""" - out = getoutput(f'python3 {prg}') + out = getoutput(f'python {prg}') assert out.strip() == 'Hello, World!' @@ -26,7 +26,8 @@ def test_runnable(): def test_executable(): """Says 'Hello, World!' by default""" - out = getoutput(prg) + out = getoutput(f'python {prg}') + print(out) assert out.strip() == 'Hello, World!' @@ -35,7 +36,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f'python {prg} {flag}') assert rv == 0 assert out.lower().startswith('usage') @@ -46,6 +47,6 @@ def test_input(): for val in ['Universe', 'Multiverse']: for option in ['-n', '--name']: - rv, out = getstatusoutput(f'{prg} {option} {val}') + rv, out = getstatusoutput(f'python {prg} {option} {val}') assert rv == 0 assert out.strip() == f'Hello, {val}!'