Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 01_hello/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import argparse


def get_args():
parser = argparse.ArgumentParser(
description="Say hello"
)
parser.add_argument(
"-n", "--name",
default="World",
help="Name to greet"
)
return parser.parse_args()


def main():
args = get_args()
print(f"Hello, {args.name}!")


if __name__ == "__main__":
main()
30 changes: 9 additions & 21 deletions 01_hello/test.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,39 @@
#!/usr/bin/env python3
"""tests for hello.py"""

import os
from subprocess import getstatusoutput, getoutput
from subprocess import getoutput, getstatusoutput

prg = './hello.py'
prg = 'hello.py'
cmd = f'python {prg}'


# --------------------------------------------------
def test_exists():
"""exists"""

assert os.path.isfile(prg)


# --------------------------------------------------
def test_runnable():
"""Runs using python3"""

out = getoutput(f'python3 {prg}')
"""Runs using python"""
out = getoutput(cmd)
assert out.strip() == 'Hello, World!'


# --------------------------------------------------
def test_executable():
"""Says 'Hello, World!' by default"""

out = getoutput(prg)
out = getoutput(cmd)
assert out.strip() == 'Hello, World!'


# --------------------------------------------------
def test_usage():
"""usage"""

for flag in ['-h', '--help']:
rv, out = getstatusoutput(f'{prg} {flag}')
rv, out = getstatusoutput(f'{cmd} {flag}')
assert rv == 0
assert out.lower().startswith('usage')


# --------------------------------------------------
def test_input():
"""test for input"""

for val in ['Universe', 'Multiverse']:
for option in ['-n', '--name']:
rv, out = getstatusoutput(f'{prg} {option} {val}')
rv, out = getstatusoutput(f'{cmd} {option} {val}')
assert rv == 0
assert out.strip() == f'Hello, {val}!'
assert out.strip() == f'Hello, {val}!'