摘要: 执行多个测试套件(suites)Chaining together a suite of testsUnittest makes it easy to chain together test cases into a TestSuite. A TestSuite can be runjust like a TestCase, but it also provides additional functionality to add a single test, multipletests, and count them.1. Create a new file named recipe5.py 阅读全文
posted @ 2012-06-24 19:02 绿色的麦田 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 根据不同的命令行参数进行不同代码的单元测试。Running a subset of test case methodsSometimes it's convenient to run only a subset of test methods in a given test case. This recipewill show how to run either the whole test case, or pick a subset from the command line.1. Create a new file named recipe4.py in which to put 阅读全文
posted @ 2012-06-24 18:52 绿色的麦田 阅读(308) 评论(0) 推荐(0) 编辑
摘要: Running test cases from the command line with increased verbosity.It is easy to adjust the test runner to print out every test method as it is run.1. Create a new file called recipe3.py in which to store this recipe's code.2. Pick a class to test. In this case, we will use our Roman numeral conv 阅读全文
posted @ 2012-06-24 18:34 绿色的麦田 阅读(324) 评论(0) 推荐(0) 编辑
摘要: Setting up and tearing down a test harness.With the following steps, we will setup and teardown a test harness for each test method.1. Create a new file called recipe2.py in which to put all our code for this recipe.2. Pick a class to test. In this case, we will use a slightly altered version of our 阅读全文
posted @ 2012-06-24 14:13 绿色的麦田 阅读(373) 评论(0) 推荐(0) 编辑
摘要: 一个非常简单的python的测试用例,取自电子书:《Python Testing Cookbook》第一章内容,里面说的足够简单明了,将之摘出来,对照代码,应该很容易理解。 The basic concept of an automated unittest test case is to instantiate part of our code, subject it to operations... 阅读全文
posted @ 2012-06-24 14:04 绿色的麦田 阅读(444) 评论(0) 推荐(0) 编辑
摘要: 网上看到的计算器程式,再加上一些对于=号的处理,就完美了,例如输入:3+6*8敲回车,立刻就打印出51,如果输入3+6*8=则出错,这儿需处理一下. import os while True: dynamic = input('输入计算表达式:') if dynamic != 'cls': try: r... 阅读全文
posted @ 2012-06-04 23:33 绿色的麦田 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 官方文档:http://docs.python.org/library/os.path.html 转载自:http://www.redicecn.com/html/Python/20110507/273.html os.path.abspath(path) 返回path规范化的绝对路径。 >>> os.path.abspath('test.csv') 'C:\\Python25\\tes... 阅读全文
posted @ 2012-05-22 23:57 绿色的麦田 阅读(9405) 评论(1) 推荐(1) 编辑
摘要: 1.Echo 命令打开回显或关闭请求回显功能,或显示消息。如果没有任何参数,echo 命令将显示当前回显设置。语法echo [{on|off}] [message]Sample篅echo off / echo hello world在实际应用中我们会把这条命令和重定向符号(也称为管道符号,一般用> >> ^)结合来实现输入一些命令到特定格式的文件中.这将在以后的例子中体现出来。2.@ 命令表示不显示@后面的命令,在入侵过程中(例如使用批处理来格式化敌人的硬盘)自然不能让对方看到你使用的命令啦。Sample:@echo off@echo Now initializing the 阅读全文
posted @ 2012-05-16 08:55 绿色的麦田 阅读(374) 评论(0) 推荐(0) 编辑
摘要: python struct模块主要内容来自转自:http://blog.163.com/sywxf@126/blog/static/50671196201011319507710/简单读一个二进制文件:# coding: utf-8import structimport sysbinfile=open('test.bin','rb')buf = binfile.read()unpackIndex = 0a,b,c,d = struct.unpack_from('ifdh', buf, unpackIndex)print a, b, c, dunp 阅读全文
posted @ 2012-05-10 23:03 绿色的麦田 阅读(833) 评论(0) 推荐(0) 编辑
摘要: compile函数允许程序员在运行时刻迅速生成代码对象,然后就可以用exec语句或者内建函数eval 来执行这些对象或者对它们进行求值。一个很重要的观点是:exec和eval者可以执行字符串格式的Python代码。这也是与c++等静态语言最重要的区别。compile的三个参数都是必须的,第一参数代表了要编译的Python代码。第二个字符串,虽然是必须的,但通常被置为空串。最后的参数是个字符串,它用来表明代码对象的类型。有三种可能值:‘eval’ 可求值的表达式,和eval一起使用‘single’ 单一可执行语句,和exec一起使用‘exec’ 可执行语句组,和exec一起使用。1、可求值表达式 阅读全文
posted @ 2012-05-02 00:10 绿色的麦田 阅读(359) 评论(0) 推荐(0) 编辑