#!/usr/bin/env python
#
# This script require coverage.py, see http://nedbatchelder.com/code/modules/coverage.html
#
# Provides coverage testing for LLazy
# Execute like:
#   python runcoverage.py

import sys,os
import runalltest
import coverage

"""The list of files for testing"""
pylst = []

def py_finder(recurse, dir, names):
    """Find all python files"""
    if '__init__.py' in names:
        dirs = [x for x in dir[len(os.curdir):].split(os.sep) if x]
        files = [x for x in names if x.endswith('.py')]
        for file in files:
            pylst.append(dirs[len(dirs)-1] + os.sep + file)            
    else:
        pylst.append([x for x in names if x.endswith('.py')][0])
    pass

def run_coverage():
    """Run the coverage test"""
    coverage.erase()
    print "coverage infomations cleared"
    coverage.start()
    print "coverage started"
    
    runalltest.run_tests()

    coverage.stop()
    coverage.analysis(runalltest)
    
    os.path.walk('../src', py_finder, '-R' in sys.argv)
    coverage.report(pylst)

    print "coverage terminated"
    pass
    
if __name__ == '__main__':
    """The main function"""
    run_coverage()
    
    
