#!/usr/bin/env python

MINIMUM_TEST_COVERAGE = 76.7

# coverprofile.out (see Makefile for how this is generated) will look something like this:
#
# github.com/aws/amazon-ecs-agent/agent/wsclient/error.go:66:						Retry						0.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/errors.go:23:						Error						0.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/errors.go:28:						Retry						0.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/errors.go:41:						Retry						0.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/errors.go:46:						Error						0.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/errors.go:59:						Error						0.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/types.go:40:						BuildTypeDecoder				100.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/types.go:49:						NewOfType					0.0%
# github.com/aws/amazon-ecs-agent/agent/wsclient/types.go:57:						GetRecognizedTypes				100.0%
# total:													(statements)					73.8%

with open("coverprofile.out") as f:
    for line in f:
        if line.startswith("total:"):
            splitline = line.split()
            print("Total unit test coverage: " + splitline[2])
            coverage = float(splitline[2].rstrip("%"))
            if coverage < MINIMUM_TEST_COVERAGE:
                raise BaseException(
                    "Unit test coverage ({0}%) is below the minimum ({1}%)".
                    format(coverage, MINIMUM_TEST_COVERAGE))
