-
- 2013-11-14
- 技术  源代码阅读
目录文件说明
README
如何运行测试文件,包含全部测试及分模块测试
调用
$ python test/alltests.py
运行全部测试
调用
$ python test/db.py
运行db模块测试
alltest.py
运行全部测试入口,调用
webtest
模块完成测试# alltest.py if __name__ == "__main__": webtest.main()
webtest.py
我们发现 webtest.py 中并没有 main 函数,而是从
web.test
中导入,# webtest.py from web.test import *
也就是说,如果
web.test
中有main函数的话,webtest.main()
其实是调用web.test
中的main函数。感觉~ 好神奇
web.test
看web目录下的test.py文件,果然发现了main函数,终于找到入口啦~
def main(suite=None): if not suite: main_module = __import__('__main__') # allow command line switches args = [a for a in sys.argv[1:] if not a.startswith('-')] suite = module_suite(main_module, args or None) result = runTests(suite) sys.exit(not result.wasSuccessful())
把这个main函数改掉,再运行一下:
$ python test/alltests.py
果然是运行修改后的函数,所以这里确定是入口。
在进入下一步之前,我们需要学习一下Python自动单元测试框架,即
Read More ...unittest
模块。关于unittest
,可以参考这篇文章: Python自动单元测试框架 -
- 2013-11-01
- 技术
Python包管理不同方式的区别
学习Python已经有一段时间,经常会遇到安装各种包的问题,一会
setup.py
, 一会easy_install
,一会又是pip
,还有一些概念比如distutils
,setuptools
等等,搞不清楚谁是谁,什么时候应该用什么,今天就把这些概念 澄清一下。distutils
distutils是Python标准库的一部分,其初衷是为开发者提供一种方便的打包方式, 同时为使用者提供方便的安装方式。
Read More ... -
- 2013-10-26
- 技术  数据结构
-
- 2013-10-25
- 技术  计算机系统
字符指针与字符数组真正的区别
问题缘起
先看一个示例
示例1
#include <stdio.h> int main() { char *p = "hello"; char q[] = "hello"; printf ("p: %s\n", p); printf ("q: %s\n", q); return 0; }
上面的例子会给出这样的输出
p: hello q: hello
这样看,
char *p
和 ` char q[] ` 好像没什么区别, 那么我们再看一个例子示例2
#include <stdio.h> int main() { char *p = "hello"; char q[] = "hello"; p[0] = 's'; q[0] = 's'; return 0; }
如果你在Linux下,运行时可能得到这样的结果
Segmentation fault (core dumped)
这时候你看到了区别,出现了段错误, 你一定想明白,到底发生了什么, 经过几个小实验,你可能会发现使用
char *p
定义时,p指向的数据是无法改变的。 然后你Google, 别人可能会告诉你- char 指针指向的数据不能修改
- char 指针指向的数据没有分配
- …
你听了还是一头雾水,不能修改是什么意思,没有分配?没有分配为什么能输出?
作为一个好奇心很重的人,你是绝对不能容忍这些问题的困扰的,且听我慢慢道来
Read More ... -
- 2013-10-24
- 技术  markdown
-
- 2010-09-17
- 技术  操作系统