首先在 PowerShell 里面建立骨架目录结构
mkdir projects
cd projects
mkdir skeleton
cd skeleton
mkdir bin
mkdir NAME
mkdir tests
mkdir docs
书里的 cd projects 有个斜杠 / 不知道什么意思。
然后设置初始文件
new-item -type file NAME/__init__.py
new-item -type file tests/__init__.py
然后创立一个 setup.py 文件如下:(这个文件应该放在 skeleton 文件夹里面)
try:
from setuptools import setup
except ImportError:
form distutils.core import setup
config = {
'description':'My Project',
'author':'My Name',
'url':'URL to get it at.',
'download_url':'Where to download it.',
'author_email':"My email.",
'version':'0.1',
'install_requires':['nose'],
'scripts':[],
'name':'projectname'
}
setup(**config)
然后写一个测试专用的骨架文件,放在 tests 里面:
from nose.tools import *
import NAME
def setup():
print "SETUP!"
def teardown():
print "TEAR DOWN!"
def test_basic():
print "I RAN!"
在 PowerShell里面输入
nosetests
有结果如下:
======================================================================================================
使用这个骨架
以后要新建一个项目,只要做这些事情就可以了:
1.复制这份骨架目录,把名字改成新项目的名字。
2.再把 NAME 模块更名为你需要的名字。
3.编辑 setup.py ,让它包含新项目相关信息。
4.重命名 test/NAME_tests.py ,让它的名字匹配到你的模块的名字。
5.使用 nosetests 检查有无错误。
6.开始写代码。