注解
tmuxp is usable but still needs your help reporting errors, bugs and usability feedback. If you encounter an error, please post on the Issue tracker.
开发及测试(Developing and Testing)¶
测试用例位于 ./tmuxp/testsuite 中,由 unittest 实现。
./run_tests.py 使用 $ tmux -L test_case 在单独的一个 socket_name 上创建一个tmux服务(server)。
从git获取最新代码并安装(Install the latest code from git)¶
进行开发的第一步就是从git上获取最新代码:
$ git clone git@github.com:tony/tmuxp.git
$ cd tmuxp
接下来创建一个virtualenv环境,如果您尚不了解如何创建virtualenv环境,可以直接使用下面的命令:
$ virtualenv .env
然后在当前终端(tty/terminal)下激活virtualenv环境:
$ source .env/bin/activate
下面就可以安装tmuxp了:
$ pip install -e .
使用pip包管理器可以在当前目录下安装python包, -e 表示 --editable, 意味着你可以修改源代码, 而且修改结果会反映到已安装的包。
$ tmuxp
测试运行器(Test Runner)¶
如上步骤所示,在完成python虚拟环境搭建后并进入该环境后, 当前 PATH 环境就会发生变化,以包含位一个位于 .env 目录下特定版本的自带类库的 python 。 然后就可以运行 tmuxp 命令。
接下来执行:
$ ./run_tests.py
就会看到很多测试信息源源不断地滚屏显示。
如果您发现了问题或是想提交一个测试,你可以在 在github上发起问题(issue on github) 。
测试运行器的参数(Test runner options)¶
注解
截止到v0.0.20, --tests 会默认使用 tmuxp.testsuite 。
$ ./run_tests.py --tests test_config.ImportExportTest
等同于:
$ ./run_tests.py --tests tmuxp.testsuite.test_config.ImportExportTest
对特定的测试套件,测试案例,测试个体进行测试
$ ./run_tests.py --help
上述操作将显示出您可选择的所有测试套件。比如 test_config :
使用 unittest.TestSuite :
$ ./run_tests.py test_config
$ ./run_tests.py --tests test_config.ImportExportTest
单独测试:
$ ./run_tests.py --tests test_config.ImportExportTest.test_export_json
多个测试之间可以用空格间隔开:
$ ./run_tests.py --tests ImportExportTest.test_export_json \
ImportExportTest.test_window
可视化的测试(Visual testing)¶
您可以单独打开一个终端用来观察tmux测试套件如何创建会话(session)。
打开两个终端:
终端 1: $ tmux -L test_case
终端 2: $ cd 进入tmuxp项目目录,并启用 virtualenv 进入虚拟环境 (详见上文所述如何安装tmuxp开发版),然后运行:
$ python ./run_tests.py --tests tests_workspacebuilder
终端1 会闪烁一下然后在您的肉眼查觉之前就已经完成了对会话(session)的创建。 tmuxp对普通用户隐藏了这部分信息。
记录和日志(Verbosity and logging)¶
./run_tests.py supports two options, these are optional flags that may be added to for 测试运行器的参数(Test runner options) and 可视化的测试(Visual testing). ./run_tests.py 支持两个选项,可以添加到 测试运行器的参数(Test runner options) 和 可视化的测试(Visual testing) 。
日志等级: -l 又可以表示为 --log-level, 可以设为 debug, info, warn, error, fatal. 默认为 INFO 。
$ ./run_tests.py --log-level debug
简短形式:
$ ./run_tests.py -l debug
单元测试记录:
--verbosity 可以设置为 0, 1 和 2. 默认为: 2.
$ ./run_tests.py --verbosity 0
保存文件时自动运行测试(Run tests on save)¶
Tmux可以监控文件的改动,在保时时自动运行测试。
注解
这个功能需要从pypi中安装 watching_testrunner 。
从 pypi 中安装 watching_testrunner:
$ pip install watching_testrunner
编辑任何一个 .py 文件都会引发所有测试:
$ watching_testrunner --basepath ./ --pattern="*.py" python run_tests.py
如果只想引发 可视化的测试(Visual testing) :
$ watching_testrunner --basepath ./ --pattern="*.py" python run_tests.py --visual
tmuxp开发者配置(tmuxp developer config)¶

从git获取最新代码并安装(Install the latest code from git) ,签出tmxp之后运行:
$ tmuxp load .
上面的操作会在项目根目录下载入 .tmuxp.yaml 文件。
session_name: tmuxp
start_directory: ./ # load session relative to config location (project root).
windows:
- window_name: tmuxp
layout: main-horizontal
options:
main-pane-height: 35
shell_command_before:
- command -v virtualenv >/dev/null 2>&1 || { pip install virtualenv; }
- '[ -d .env -a -f .env/bin/activate ] && source .env/bin/activate || virtualenv .env'
- '[ ! -d .env/build ] || rm -rf .env/build'
panes:
- shell_command:
- reset
- vim
- :Ex
focus: true
- shell_command:
- echo hi
- shell_command:
- command -v .env/bin/tmuxp >/dev/null 2>&1 || { pip install -e .; }
- command -v watching_testrunner >/dev/null 2>&1 || { pip install watching_testrunner; }
- watching_testrunner --basepath ./ --pattern="*.py" 'python run_tests.py'
- window_name: docs
layout: main-horizontal
options:
main-pane-height: 35
shell_command_before:
- command -v virtualenv >/dev/null 2>&1 || { pip install virtualenv; }
- '[ -d .env -a -f .env/bin/activate ] && source .env/bin/activate || virtualenv .env'
- '[ ! -d .env/build ] || rm -rf .env/build'
- command -v .env/bin/tmuxp >/dev/null 2>&1 || { pip install -e .; }
- cd ./doc
panes:
- shell_command:
- reset
- vim
- :Ex
focus: true
- pwd
- echo 'docs built to <http://0.0.0.0:8000/_build/html>'; python -m SimpleHTTPServer
- shell_command:
- command -v sphinx-quickstart >/dev/null 2>&1 || { pip install -r requirements.pip; }
- command -v watching_testrunner >/dev/null 2>&1 || { pip install watching_testrunner; }
- watching_testrunner --basepath ./ --pattern="*.rst" 'make html'
- python -m SimpleHTTPServer
Travis CI¶
Tmuxp使用 travis-ci 所提供的持续集成/自动化单元测试。
travis支持多种场景下的测试,当前tmuxp已通tmux1.8版本和python2.7下的测试。 travis下tmuxp测试 使用 .travis.yml 配置:
language: python
python:
- 2.6
- 2.7
- 3.3
matrix:
allow_failures:
- python: 2.6
env:
- TMUX_VERSION=master
- TMUX_VERSION=1.8
before_install:
- sudo apt-get update -qq
install:
- "pip install -e ."
before_script:
- sudo apt-get install -qq libevent-dev libncurses-dev
- git clone git://git.code.sf.net/p/tmux/tmux-code tmux
- cd tmux
- git checkout $TMUX_VERSION
- sh autogen.sh
- ./configure && make && sudo make install
- cd ..
- tmux -V
#script: python run_tests.py
script: python setup.py test