+class coverage_cmd(Command):
+ description = "generate test coverage data"
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ import trace
+ tracer = trace.Trace(
+ count=True, trace=False,
+ ignoredirs=[sys.prefix, sys.exec_prefix])
+ def run_tests():
+ import bulletml
+ try:
+ reload(bulletml)
+ except NameError:
+ pass
+ self.run_command("test")
+ tracer.runfunc(run_tests)
+ results = tracer.results()
+ coverage = os.path.join(os.path.dirname(__file__), "coverage")
+ results.write_results(show_missing=True, coverdir=coverage)
+ map(os.unlink, glob.glob(os.path.join(coverage, "[!b]*.cover")))
+ try: os.unlink(os.path.join(coverage, "..setup.cover"))
+ except OSError: pass
+
+ total_lines = 0
+ bad_lines = 0
+ for filename in glob.glob(os.path.join(coverage, "*.cover")):
+ lines = open(filename, "rU").readlines()
+ total_lines += len(lines)
+ bad_lines += len(
+ [line for line in lines if
+ (line.startswith(">>>>>>") and
+ "finally:" not in line and '"""' not in line)])
+ pct = 100.0 * (total_lines - bad_lines) / float(total_lines)
+ print("Coverage data written to %s (%d/%d, %0.2f%%)" % (
+ coverage, total_lines - bad_lines, total_lines, pct))
+
+class sdist(distutils_sdist):
+ def run(self):
+ self.run_command("test")
+ distutils_sdist.run(self)
+
+class test_cmd(Command):
+ description = "run automated tests"
+ user_options = [
+ ("to-run=", None, "list of tests to run (default all)"),
+ ]
+
+ def initialize_options(self):
+ self.to_run = []
+ self.quick = False
+
+ def finalize_options(self):
+ if self.to_run:
+ self.to_run = self.to_run.split(",")
+
+ def run(self):
+ import tests
+ if tests.unit(self.to_run):
+ raise SystemExit("Test failures are listed above.")
+