python 开发的目录结构


python

开发的目录结构

学hachoir的

xxx/有
setup.py packet1 packet2...

test放拿呢?? ---放到packet中,并且在setup.py的时候不安装

test有2中,一种是testcase,一种是doctest,可以在xxx目录中放一个alltest.py,测试所有的东西

test_doc的例子,从hachoircopy过来的
#!/usr/bin/env python2.4
import doctest
import sys
import os
import hachoir_core.i18n # import it because it does change the locale
from locale import setlocale, LC_ALL

def testDoc(filename, name=None):
print "--- %s: Run tests" % filename
failure, nb_test = doctest.testfile(
filename, optionflags=doctest.ELLIPSIS, name=name)
if failure:
sys.exit(1)
print "--- %s: End of tests" % filename

def importModule(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod

def testModule(name):
print "--- Test module %s" % name
module = importModule(name)
failure, nb_test = doctest.testmod(module)
if failure:
sys.exit(1)
print "--- End of test"

def main():
setlocale(LC_ALL, "C")
hachoir_dir = os.path.dirname(__file__)
sys.path.append(hachoir_dir)

# Configure Hachoir for tests
import hachoir_core.config as config
config.use_i18n = False

# Test documentation in doc/*.rst files
testDoc('doc/hachoir-api.rst')
testDoc('doc/internals.rst')

# Test documentation of some functions/classes
testModule("hachoir_core.bits")
testModule("hachoir_core.compatibility")
testModule("hachoir_core.dict")
testModule("hachoir_core.text_handler")
testModule("hachoir_core.tools")

if __name__ == "__main__":
main()
#alltest的例子,可以集成doctest
import glob
import os
import sys
import unittest

# This list contains the filenames of test modules that should be
# skipped by IronPython.
CLI_SKIP = [
## 'test_store_client_storage.py',
## 'test_store_storage_server.py',
]

def suite():
"""
Return a test suite containing all test cases in all test modules.
Searches the current directory for any modules matching xxxTest.py.
"""
suite = unittest.TestSuite()
for filename in glob.glob('*Test.py'):
if sys.platform == 'cli' and filename in CLI_SKIP:
print 'NOTICE: Skipping non-CLI file %s' % filename
continue
module = __import__(os.path.splitext(filename)[0])
suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(module))
return suite


if __name__ == '__main__':
unittest.main(defaultTest='suite')

Tips

  • py文件编码的问题

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
  • doctest的用处

    可以作为accept test的一部分

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值