Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
graft Cython
recursive-exclude Cython *
recursive-include Cython *.py *.pyx *.pxd
''')
sys.path.insert(0, cy3_dir)
elif sys.version_info[0] >= 3:
# make sure we do not import (or run) Cython itself
options.with_cython = False
options.doctests = False
options.unittests = False
options.pyregr = False
if options.coverage:
import coverage
coverage.erase()
coverage.start()
WITH_CYTHON = options.with_cython
if WITH_CYTHON:
from Cython.Compiler.Main import \
CompilationOptions, \
default_options as pyrex_default_options, \
compile as cython_compile
from Cython.Compiler import Errors
Errors.LEVEL = 0 # show all warnings
from Cython.Compiler import Options
Options.generate_cleanup_code = 3 # complete cleanup code
from Cython.Compiler import DebugFlags
DebugFlags.debug_temp_code_comments = 1
# RUN ALL TESTS!
def _iter_covered_files():
import sqlalchemy
for rec in os.walk(os.path.dirname(sqlalchemy.__file__)):
for x in rec[2]:
if x.endswith('.py'):
yield os.path.join(rec[0], x)
def _stop():
coverage.stop()
true_out.write("\nPreparing coverage report...\n")
coverage.report(list(_iter_covered_files()),
show_missing=False, ignore_errors=False,
file=true_out)
atexit.register(_stop)
coverage.erase()
coverage.start()
def test_runner_with_coverage(test_labels, verbosity=1, interactive=True, extra_tests=[]):
"""
Custom test runner. Follows the django.test.simple.run_tests() interface.
"""
# Start code coverage before anything else if necessary
if hasattr(settings, 'COVERAGE_MODULES'):
coverage.use_cache(0) # Do not cache any of the coverage.py stuff
coverage.start()
test_results = django_test_runner(test_labels, verbosity, interactive, extra_tests)
# Stop code coverage after tests have completed
if hasattr(settings, 'COVERAGE_MODULES'):
coverage.stop()
# Print code metrics header
print ''
print '----------------------------------------------------------------------'
print ' Unit Test Code Coverage Results'
print '----------------------------------------------------------------------'
# Report code coverage metrics
if hasattr(settings, 'COVERAGE_MODULES'):
coverage_modules = []
def _run_with_coverage(self):
import coverage
coverage.use_cache(False)
coverage.start()
try:
self._run_tests()
finally:
coverage.stop()
modules = [m for _, m in sys.modules.items()
if m is not None and hasattr(m, '__file__')
and os.path.splitext(m.__file__)[-1] in ('.py', '.pyc')]
# Generate summary file
buf = StringIO()
coverage.report(modules, file=buf)
buf.seek(0)
fileobj = open(self.coverage_summary, 'w')
try:
filter_coverage(buf, fileobj)
def main_coverage(TESTS):
modulenames = MODULE_NAMES
coverage.erase()
coverage.start()
coverage.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')
modules = []
for modulename in modulenames:
mod = my_import(modulename)
modules.append(mod)
if 'unittest' in TESTS:
print "***** Unittest *****"
test_args = {'verbosity': 1}
suite = unittest.TestLoader().loadTestsFromNames(TEST_NAMES)
unittest.TextTestRunner(**test_args).run(suite)
if 'doctest' in TESTS:
t0 = time.time()
print "\n***** Doctest *****"
def start(clean, packages, target):
'''Start the coverage'''
# Set the coverage data storing path
os.environ['COVERAGE_FILE'] = os.path.join(target, nconst.COVER_OUTPUT_BASE)
# Check if clean
if clean: ntools.clean(target, nconst.COVER_OUTPUT_BASE)
# Start
coverage.start()
# Load packages
for package in packages:
# Try to get it
try: __import__(package)
# Unable to get it, don't care
except: pass
dummy_SOAPpy= self.mocker.replace('SOAPpy')
dummy_SOAPpy.SOAPProxy (ANY)
self.mocker.count (1)
self.mocker.result (True)
self.mocker.replay ()
argv = ['smstool_event_handler', 'REPORT', './sms_test_files/GSM1.M1h8yB', '1JyoAT']
event_handler = smstool_event_handler.SmsToolEventHandler (argv, './smstool_event_handler.conf')
event_handler.dispatch ()
self.mocker.verify()
if __name__ == '__main__':
try:
coverage.use_cache(False)
coverage.erase()
coverage.start()
reload(smstool_event_handler)
try:
unittest.main()
finally:
coverage.stop()
coverage.report(smstool_event_handler)
except ImportError:
unittest.main()
def run(self):
try:
import coverage
use_coverage = True
except:
# Use system 'coverage' if available
use_coverage = False
tests = TestLoader().loadTestsFromNames(self._testfiles)
t = TextTestRunner(verbosity=1)
if use_coverage:
coverage.erase()
coverage.start()
result = t.run(tests)
if use_coverage:
coverage.stop()
if len(result.failures) > 0 or len(result.errors) > 0:
sys.exit(1)
else:
sys.exit(0)
def run(self):
print("Starting Gaphor...")
if self.model:
print("Starting with model file", self.model)
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
# if self.build_lib not in sys.path:
# sys.path.insert(0, self.build_lib)
# os.environ['GAPHOR_DATADIR'] = os.path.abspath('data')
if self.coverage:
import coverage
coverage.start()
if self.command:
print("Executing command: %s..." % self.command)
exec(self.command)
elif self.doctest:
print("Running doctest cases in module: %s..." % self.doctest)
import imp
# use zope's one since it handles coverage right
from zope.testing import doctest
# Figure out the file:
f = os.path.join(*self.doctest.split(".")) + ".py"
fp = open(f)
# Prepend module's package path to sys.path
def begin(self):
"""
Begin recording coverage information.
"""
log.debug("Coverage begin")
import coverage
self.skipModules = sys.modules.keys()[:]
if self.coverErase:
log.debug("Clearing previously collected coverage statistics")
coverage.erase()
coverage.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')
coverage.start()