时间:2021-07-01 10:21:17 帮助过:9人阅读
1.widget.py文件如下:
class Widget:
def __init__(self, size = (40, 40)):
self.size = size
def getSize(self):
return self.size
def resize(self, width, height):
if width < 0 or height < 0:
raise ValueError, "illegal size"
self.size = (width, height)
def dispose(self):
passDefaultTestCase
2. auto.py文件如下:
3.执行结果如下:
[code]jobin@jobin-desktop:~/work/python/py_unit$ python auto.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
jobin@jobin-desktop:~/work/python/py_unit$ python auto.py
F
======================================================================
FAIL: testSize (__main__.WidgetTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "auto.py", line 15, in testSize
self.assertEqual(self.widget.getSize(), (50, 40))
AssertionError: (40, 40) != (50, 40)
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
jobin@jobin-desktop:~/work/python/py_unit$[/code]
希望本文所述对大家的Python程序设计有所帮助。