python 开发的目录结构


目录

python
开发的目录结构
Tips

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的一部分

 

你可能感兴趣的:(TDD,unix/linux)