import TestLib exeName = os.path.realpath(sys.argv[0]) top_srcdir = os.path.join(os.path.dirname(exeName), "..") top_builddir = os.getcwd() sys.path.insert(0,top_srcdir) sys.path.insert(0,"%s/ft-cli/" % top_srcdir) # runs all modules TestCase() classes in files that match test*.py if __name__ == "__main__": testModulePath="%s/test/" % top_srcdir moduleNames = glob.glob( "%s/test*.py" % testModulePath ) moduleNames = [ m[len(testModulePath):-3] for m in moduleNames ] tests = [] for moduleName in moduleNames: if "testAll" in moduleName: continue module = __import__(moduleName, globals(), locals(), []) module.TestCase.top_srcdir=top_srcdir module.TestCase.top_builddir=top_builddir tests.append(module.TestCase) retval = 1 if tests: retval = TestLib.runTests( tests ) sys.exit( not retval )
import TestLib exeName = os.path.realpath(sys.argv[0]) top_srcdir = os.path.join(os.path.dirname(exeName), "..") top_builddir = os.getcwd() sys.path.insert(0, top_srcdir) # runs all modules TestCase() classes in files that match test*.py if __name__ == "__main__": testModulePath = "%s/pyunit/" % top_srcdir moduleNames = glob.glob("%s/test*.py" % testModulePath) moduleNames = [m[len(testModulePath):-3] for m in moduleNames] tests = [] for moduleName in moduleNames: if "testAll" in moduleName: continue module = __import__(moduleName, globals(), locals(), []) module.TestCase.top_srcdir = top_srcdir module.TestCase.top_builddir = top_builddir tests.append(module.TestCase) retval = 1 if tests: retval = TestLib.runTests(tests) sys.exit(not retval)
self.testfile) # a test callback that increments a counter each time it is called def _test_cb(cmosObj, do_update, userdata): i = ctypes.cast(userdata, ctypes.POINTER(ctypes.c_uint16)) i[0] = i[0] + 1 return 1 int = ctypes.c_uint16(0) cObj.registerCallback(_test_cb, ctypes.pointer(int), None) for i in range(26): # index/data ports to 0 for unit testing b = cObj.readByte(0, 0, i) self.assertEqual(ord('a') + i, b) cObj.writeByte(b + ord('A') - ord('a'), 0, 0, i) b = cObj.readByte(0, 0, i) self.assertEqual(ord('A') + i, b) self.assertEqual(int.value, 26) # index port 1 (offset 512 + i) should be '0' for i in range(26): c = cObj.readByte(1, 0, i) self.assertEqual(c, ord('0')) if __name__ == "__main__": import TestLib sys.exit(not TestLib.runTests([TestCase]))
# a test callback that increments a counter each time it is called def _test_cb(cmosObj, do_update, userdata): i = ctypes.cast(userdata, ctypes.POINTER(ctypes.c_uint16)) i[0] = i[0] + 1 return 1 int = ctypes.c_uint16(0) cObj.registerCallback(_test_cb, ctypes.pointer(int), None) for i in xrange(26): # index/data ports to 0 for unit testing b = cObj.readByte(0, 0, i) self.assertEquals( ord('a') + i, b ) cObj.writeByte( b + ord('A') - ord('a'), 0, 0, i ) b = cObj.readByte(0, 0, i) self.assertEquals( ord('A') + i, b ) self.assertEquals(int.value, 26) # index port 1 (offset 512 + i) should be '0' for i in xrange(26): c = cObj.readByte(1, 0, i) self.assertEquals(c, ord('0')) if __name__ == "__main__": import TestLib sys.exit(not TestLib.runTests( [TestCase] ))