def test(): marks = 0; name = "Question 3" input = "Bob" expected = "Hello Bob" actual = hello.greet(input) if expected == actual: marks = marks+1 input = "" expected = "Hello " actual = hello.greet(input) if expected == actual: marks = marks+1 input = "Bob" expected = "Hello Bob" actual = "This-is-rigged" if expected == actual: marks = marks+1 if marks == 3: status = "pass" else: status = "fail" return printResults(name, status)
def main(args): parser = OptionParser() parser.add_option('--ui', dest='ui', default='console', help="Sets the UI to use to greet the user. One of: %s" % ", ".join("'%s'" % ui for ui in hello.list_uis())) parser.add_option('--lang', dest='lang', default='en', help="Sets the language to use") options, args = parser.parse_args(args) if len(args) < 2: print "Sorry, I can't greet you if you don't say your name" return 1 try: hello.greet(args[1], options.lang, options.ui) except hello.LanguageNotSupportedException: print "Sorry, I don't speak '%s'" % options.lang return 1 except hello.UINotSupportedExeption: print "Invalid UI name\n" print "Valid UIs:\n\n" + "\n".join(' * ' + ui for ui in hello.list_uis()) return 1
def testGreet(): name = "World" expect = "Hello World!" result = greet(name) assert expect == result assert greet('John') == 'Hello John!' assert greet('Jen') == 'Hello Jen!' print('all test cases passed for greet()...')
def test_1(): name = "Normal Hello" input = "Bob" expected = "Hello Bob" actual = hello.greet(input) if actual == expected: status = "pass" else: status = "false" return printResults(name, input, status)
def test_2(): name = "Empty Hello" input = "" expected = "Hello " actual = hello.greet(input) if actual == expected: status = "pass" else: status = "false" return printResults(name, input, status)
def test_2(): name = "Empty Hello" input = "" expected = "Hello " actual = hello.greet(input) if actual == expected: marks = 2 status = "pass" else: marks = 0 status = "fail" return printResults(name, input, expected, actual, marks, status)
def test_1(): name = "Normal Hello" input = "Bob" expected = "Hello Bob" actual = hello.greet(input) if actual == expected: marks = 1 status = "pass" else: marks = 0 status = "fail" return printResults(name, input, expected, actual, marks, status)
def test_greet_2(): with raises(AttributeError): greet('')
""" import sys, os if __name__ == "__main__": dir_path = os.path.dirname(os.path.realpath(__file__)) project_path = os.path.split(dir_path)[0] cpp_hello_world_code = os.path.join(project_path, 'src/core/cpp_build/HelloWorld') cpp_hello_box_code = os.path.join(project_path, 'src/core/cpp_build/HelloBox') sys.path.insert(0, cpp_hello_world_code) sys.path.insert(0, cpp_hello_box_code) import hello import hello_box print 'This "' + hello.greet() + '" is from a C++ piece of code, build in the folder \n' + cpp_hello_world_code my_box = hello_box.Box() my_box.height = 0.5 my_box.width = 1.5 my_box.length = 2.5 my_box.file_path = os.path.join(project_path, 'data', 'box_info.txt') my_box.save_info() print "Check the file box_info.txt to see if everything works."
def test_greet(self): self.assertEqual("Hello, Alice!", greet("Alice")) self.assertEqual("Hello, Bob!", greet("Bob"))
def std_task(value): import hello hello.greet("FROM PYTHON TO C") return value + 1
import hello print(hello.greet("good"))
from fib import fib from hello import greet print greet("Samarjit") for i in range(5): print(fib(i))
def test_greet_1(): assert greet('Mike') == 'Hello my dear Mike!'
import hello #renamed module greetings as hello hello.greet("bhalaji") import greetings.greet as gr gr.hello('bhalaji') gr.bye('bhalaji')
import hello from hello import greet as gr def addNumbers(*numbers): total = 0 for each in numbers: total += each return total print(addNumbers(1,2,3,4,5)) hello.greet() gr()
def greet(): print(hello.greet())
def test_020_greet(self): self.assertEqual(greet('Alice'), 'Hello, Alice!', 'greet someone')
#!/usr/bin/env python import hello myname = "Joe" myname = taint(myname) ans1 = hello.greet(myname) print(ans1) def taint(val): return val
import hello for x in range(3): print hello.greet(x)
#!/usr/bin/env python # -*- coding: UTF-8 -*- import hello print(hello.greet())
import transmute transmute.require([ 'hello' ], sources=[ 'dist' ]) transmute.update() import hello hello.greet()
def testGreet(self): name = "World" expect = "Hello World!" result = hello.greet(name) self.assertEqual(expect, result)
def test_030_greet_another(self): self.assertEqual(greet('Bob'), 'Hello, Bob!', 'greet someone else')
import sys import transmute transmute.require([ 'hello' ], sources=[ '../../hello/dist' ]) transmute.update() import hello hello.greet('test')
def runTest(self): what = "World" greeting = hello.greet(what) self.assertEqual(greeting, "Hello, %s" % what)
# test.py import hello print(hello.greet("world")) print("named:", hello.greet(name="world"))
#!/usr/bin/env python import hello print (hello.greet())
""" 测试打包是否成功 将build里的so文件移到同级目录下,将hell.py删除掉 运行python demo.py输出"hello Tom",说明调用的是so文件里的greet """ from hello import greet print(greet("Tom"))
def test_hello(): hello.inp = [] hello.greet("Karole") assert hello.inp == ['Hello', 'Karole']
def test_hello_elena(): hello.inp = [] hello.greet("Elena") assert hello.inp == ['Hello', 'Elena']
#!/usr/bin/env python import hello print hello.greet()
#!/usr/bin/env python # Use of hello module - Module Aliasing from hello import SayHello as greet , SayBye as bye greet('name') bye()
import hello print hello.greet("World")
def test_greet(who): greeting = hello.greet(who) assert greeting == "{}, good evening!".format(who)