2012-09-01 1 views

답변

1

에서

TNX

내가 한 번 Pyflakes를 사용하는 시험 발생기를 썼다. 그것은 코 플러그인은 아니지만, 내 필요에 충분히 가까이 : your_application를 포함하는 디렉토리 내의 각 파이썬 파일

import os 
import _ast 

from pyflakes import checker 

import your_application 

TOP = os.path.dirname(os.path.dirname(your_application.__file__)) 

class PyflakesError(AssertionError): 
    def __str__(self): 
     path = self.args[0] 
     messages = self.args[1] 
     messages.sort(key=lambda m: m.lineno) 
     return 'checking %s\n' % path + '\n'.join(map(str, messages)) 

def check(path): 
    code = open(os.path.join(TOP, path)).read() 
    tree = compile(code, path, "exec", _ast.PyCF_ONLY_AST) 
    w = checker.Checker(tree, path) 
    if w.messages: 
     raise PyflakesError(path, w.messages) 

def test(): 
    for root, dirs, files in os.walk(TOP): 
     for name in files: 
      if not name.endswith('.py'): 
       continue 
      yield check, os.path.relpath(os.path.join(root, name), TOP) 

     def is_package(d): 
      return os.path.exists(os.path.join(root, d, '__init__.py')) 
     dirs[:] = filter(is_package, dirs) 

test 기능 수율 테스트 케이스. 필요에 따라 TOP을 조정하여 다른 디렉토리를 테스트 할 수 있습니다.

관련 문제