listing16-3.py

来自「《Beginning Python--From Novice to Profes」· Python 代码 · 共 30 行

PY
30
字号
import unittest, my_mathfrom subprocess import Popen, PIPEclass ProductTestCase(unittest.TestCase):    def testIntegers(self):        for x in xrange(-10, 10):            for y in xrange(-10, 10):                p = my_math.product(x, y)                self.failUnless(p == x*y, 'Integer multiplication failed')    def testFloats(self):        for x in xrange(-10, 10):            for y in xrange(-10, 10):                x = x/10.0                y = y/10.0                p = my_math.product(x, y)                self.failUnless(p == x*y, 'Float multiplication failed')    def testWithPyChecker(self):        cmd = 'pychecker', '-Q', my_math.__file__.rstrip('c')        pychecker = Popen(cmd, stdout=PIPE, stderr=PIPE)        self.assertEqual(pychecker.stdout.read(), '')    def testWithPyLint(self):        cmd = 'pylint', '-rn', 'my_math'        pylint = Popen(cmd, stdout=PIPE, stderr=PIPE)        self.assertEqual(pylint.stdout.read(), '')if __name__ == '__main__': unittest.main()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?