# -*- coding: utf-8 -*-
"""
Runner for all tests regarding the plotid project.

Includes starting all tests and measuring the code coverage.
"""

import sys
import unittest
import coverage
import os

path = os.path.abspath('src/plotid')
sys.path.append(path)

cov = coverage.Coverage()
cov.start()

loader = unittest.TestLoader()
tests = loader.discover('.')
testRunner = unittest.runner.TextTestRunner(verbosity=2)
result = testRunner.run(tests)

cov.stop()
cov.save()
cov.report(show_missing=True)

if result.wasSuccessful():
    covered = cov.report()
    assert covered > 90, "Not enough coverage."
    sys.exit(0)
else:
    sys.exit(1)