Daily 9/21
Categories:
学习
python unittest tornado
test_handlers.py 案例代码 selene项目测试案例
request_handler_test.py 案例代码 设置项目根目录、父类构建
tornado.testing —单元测试支持异步代码 支持异步测试
How to use a test tornado server handler that authenticates a user via a secure cookie mock cookie
命令行下执行单个unittest 更多的参数
python -m unittest test_module1 test_module2
python -m unittest test_module.TestClass
python -m unittest test_module.TestClass.test_method
setup 使用,初始化数据 TODO
tornado sample 有接口测试的项目
python unittest执行顺序问题 字母的顺序执行
class MyUT(tornado.testing.AsyncHTTPTestCase):
def get_app(self):
settings = {
"template_path": '../../../templates',
"cookie_secret": 'secret',
"login_url": '/admin/login',
"debug": True
}
return Application([
(r'/admin/create/super', handlers.CreateSuperUserHandler)
], **settings)
def testGet(self):
with mock.patch.object(handlers.CreateSuperUserHandler, 'get_current_user') as m:
m.return_value = {}
response = self.fetch('/admin/create/super')
print(response.body)
self.assertGreater(response.body.index('create'), 0)
mock handler更详细的例子 patch和patch.object 使用
Python
操作dict时避免出现KeyError的几种方法 使用get方法更好
How to get name of exception that was caught in Python? 获取异常的的类名
try:
foo = bar
except Exception as exception:
assert type(exception).__name__ == 'NameError'
assert exception.__class__.__name__ == 'NameError'
删除dict里面的元素 use del
>>> from collections import OrderedDict
>>> dct = OrderedDict()
>>> dct['a'] = 1
>>> dct['b'] = 2
>>> dct['c'] = 3
>>> dct
OrderedDict([('a', 1), ('b', 2), ('c', 3)])
>>> del dct['b']
>>> dct
OrderedDict([('a', 1), ('c', 3)])
>>>
python面向对象 入门级介绍 TODO
python set 集合操做 比如删除某个元素 set.remove(key)
subprocess returncode 什么时候为0
import subprocess as sp
child = sp.Popen(openRTSP + opts.split(), stdout=sp.PIPE)
streamdata = child.communicate()[0]
rc = child.returncode
Tornado
Tornado异步与延迟任务 Tornado异步通俗易懂的教程
协程 官方文档 难懂
tornado.gen源码解析 TODO
GIT
*
!.gitignore
git中如何提交空目录 空文件
git reset HEAD~2
最后修改
February 7, 2021
: doc: 整理daily日记 (0dcc57d)