Question
Problem 1b - greet.py: Greeting [15 points] Write stand-alone program that accepts one command line input value, calls greeting that you previously defined with input
Problem 1b - greet.py: Greeting [15 points] Write stand-alone program that accepts one command line input value, calls greeting that you previously defined with input argument set to whatever was in the command line input value, and finally prints out whatever greeting returned. In other words, your program should have behavior identical to the one you wrote in the previous assignment. However, in order to receive credit here, you must use your library function, hwlib.greeting.
Practice goal: This problem is intended as a short exercise in writing a very simple (almost trivial) text-UI application, which re-uses a function in a library module that you create.
The greeting function previously defined is:
def greeting(msg):
return "Welcome," + msg + "!"
These are the tests for the program:
tests 11 12 class GreetTests (HomeworkTest Case): 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 test_greet.py > ... @gs.tags ("greet.py") @gs.weight (4) def test_imports_hwlib(self): import sys #self.assertNotIn("hwlib", sys.modules.keys (), msg="Internal sanity check failed; please notify an instruct self.runScript("greet.py", "'"') # We dont care about output here... self.assertIn("hwlib", sys.modules.keys (), msg="Your code does not import hwlib!") @gs.tags ("greet.py") @gs.weight (8) def test_calls_greeting (self): import ast # XXX We should really be checking references at runtime, not names in AST... but this'll do here. def is_call_greeting (node): if not isinstance(node, ast.Call): return False if is instance (node.func, ast.Attribute) and node.func.attr return True if is instance (node.func, ast.Name) and node.func.id "greeting": return True @gs. tags ("greet.py") @gs.weight (3) return False script_ast = self.parseScript("greet.py") contains_call_greeting any (is_call_greeting (node) for node in ast.walk(script_ast)) self.assertTrue (contains_call_greeting, msg="Call to hwlib.greeting() not detected in your code") def test_greet (self): output = self.runScript("greet.py", "SammY02") result = output.rstrip(' ') self.assertEqual( 'Welcome, SammY02!', result) if name unittest.main() == = _main__': "greeting" and node.func.value.id == "hwlib"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started