def test_greet_no_input(): assert greet() == "Nice to meet you, friend!"
def test_greeting(): assert main.greet() == "Hello"
def test_greet(person, expected): assert greet(person) == expected
def test_greet(): assert greet() == "Hello"
def test_greet(): server = 'http://localhost:8080/greet' res = main.greet(server, api_key) assert 'Hello, World!' in res
""" Python files can accept arguments from the command line. $ python file.py arg1 arg2 arg3 The first argument is always the filename. All arguments are strings. """ import sys from main import greet args = sys.argv print(f'Received {len(args)} arguments:') for arg in args: print(' ' + arg) # ------------------------------------------ # shout = False num = 1 for arg in args[1:]: if arg == '--shout': shout = True else: num = int(arg) name = input("What's your name? ") greet(name, num, shout)
def test_sum(self): self.assertEqual(greet(), "hello world!", "Greet doesn't return hello world!")
def hello(num, name, shout): greet(name, num, shout)
""" Arguments using the built-in argparse module """ import argparse from main import greet parser = argparse.ArgumentParser(description='An example program') parser.add_argument('--shout', action="store_true") parser.add_argument('number', type=int, nargs='?', default=1) args = parser.parse_args() print(f'boolean {args.shout}') print(f'number {args.number}') # ------------------------------------------ # name = input("What's your name? ") greet(name, args.number, args.shout)
def test_greet_with_conventional_names(): assert main.greet("Richard") == "Hello, Richard!" assert main.greet("Esme") == "Hello, Esme!" assert main.greet("Neill") == "Hello, Neill!"
def test_greet_with_no_name(): assert main.greet() == "Hello, world!"
def test_requirement_08(name, expected): assert greet(name) == expected
def test_requirement_01(name): """ Test greeting result """ assert greet(name) == f'Hello, {name}.'
def test_requirement_04(name): assert greet(name) == f'Hello, {name[0]} and {name[1]}.'
def test_requirement_03(name): assert greet(name) == f'HELLO {name}!'
def test_requirement_02(name): """ Test greeting result """ assert greet(name) == 'Hello, my friend.'