From 64ec62b492cd59010b5114da7463077c0e4471d5 Mon Sep 17 00:00:00 2001 From: Darshan Date: Sat, 2 May 2026 01:59:57 +0530 Subject: [PATCH] Fix hello tests for Windows compatibility and execution --- 01_hello/hello.py | 22 ++++++++++++++++++++++ 01_hello/test.py | 30 +++++++++--------------------- 2 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 01_hello/hello.py diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100644 index 000000000..f08fec3d9 --- /dev/null +++ b/01_hello/hello.py @@ -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() \ No newline at end of file diff --git a/01_hello/test.py b/01_hello/test.py index d0cedd1c2..f41ad79c0 100755 --- a/01_hello/test.py +++ b/01_hello/test.py @@ -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}!' \ No newline at end of file