TimerMiddleware的呼叫计数扩展
tmw-callcount的Python项目详细描述
要使用callcount脚本,需要定义自己的runnable python脚本。在该脚本中将设置您的可调用项。
命令行选项
tmu callcount包含一个默认的参数,您将需要在python中使用它 脚本您可以通过运行–help来查看选项。
创建countcase
本例假设您已经为 应用程序,并且您已经设置了stats.sample_rate配置值。 见:http://pythonhosted.org/TimerMiddleware/quickstart.html
我们在count方法之外做额外的设置。这确保了 我们所做的任何设置都不包括在计数中。
from myapp import db from myapp.tests import TestController
- from twm_callcount import (
- default_args, CountRunner, CountCase, )
- class CountAppURL(CountCase):
- def setUp(self):
- self.test = TestController() self.create_test_data()
- def tearDown(self):
- self.test.tearDown()
- def create_test_data(self):
- db.add_page(‘Test Wiki’, ‘content’) db.add_ticket(‘Test Ticket’, ‘content’)
- def count_wiki_page(self):
- self.test.app.get(‘wiki’, extra_environ=self.environ)
- def count_ticket_page(self):
- self.test.app.get(‘ticket’, extra_environ=self.environ)
- def main(args):
- runner = CountRunner(args) runner([CountAppURL])
- if __name__ == ‘__main__’:
- main(default_args())