Beispiel #1
0
 def test_hi(self):
     # arrange
     name = "Jack"
     # act
     result = hi.Hi(name)
     # assert
     self.assertEqual("Hi Jack", result)
Beispiel #2
0
 def test_hi_2(self):
     # arrange
     name = ""
     # act
     result = hi.Hi(name)
     # assert
     self.assertEqual("Hi World", result)
Beispiel #3
0
print "--- hi.SetDebug(false)"
hi.SetDebug(False)
print "--- hi.GetDebug():", hi.GetDebug()

print "--- hi.GetAnon():", hi.GetAnon()
anon = hi.NewPerson('you', 24)
print "--- new anon:", anon
print "--- hi.SetAnon(hi.NewPerson('you', 24))..."
hi.SetAnon(anon)
print "--- hi.GetAnon():", hi.GetAnon()

print "--- doc(hi.Hi)..."
print hi.Hi.__doc__

print "--- hi.Hi()..."
hi.Hi()

print "--- doc(hi.Hello)..."
print hi.Hello.__doc__

print "--- hi.Hello('you')..."
hi.Hello("you")

print "--- doc(hi.Add)..."
print hi.Add.__doc__

print "--- hi.Add(1, 41)..."
print hi.Add(1, 41)

print "--- hi.Concat('4', '2')..."
print hi.Concat("4", "2")
Beispiel #4
0
bart = Student('Bart', Gender.Male)
if bart.gender == Gender.Male:
    print('测试通过!')
else:
    print('测试失败!')

from mypackage import test
# import mypackage as mpkg
a = test.Test('sss')
print(a)
print(a.getTestLength())
a.print()

# 导入相同的模块
import hi as hi
h = hi.Hi()
h.print()

from hi import Hi
h2 = Hi()
print(h2)
h2.print()


# 动态定义类
# 1.class的名称;
# 2.继承的父类集合,注意Python支持多重继承,如果只有一个父类,别忘了tuple的单元素写法;
# 3.class的方法名称与函数绑定,这里我们把函数fn绑定到方法名hello上。
def fn(self, name='world'): # 先定义函数
    print('Hello, %s.' % name)