#!/usr/bin/env python3

'''
Check the results of the sphinx-build coverage check.
'''

import argparse
import pickle
import sys

def main():
    opener = lambda mode: lambda fname: lambda: argparse.FileType(mode)(fname)
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("infile", type=opener("rb"),
                        help="Input undoc.pickle file.")
    args = parser.parse_args()

    with args.infile() as fh:
        undoc = pickle.load(fh)

    if not all(
            len(stuff["funcs"]) == 0
            and all(len(methods) == 0 for _class, methods in stuff["classes"])
            for module, stuff in undoc[0].items()):
       sys.exit("Not 100% coverage!")        

if __name__ == '__main__':
    main()
