2015-02-01 22:44:37 +11:00
# -*- coding: utf-8 -*-
""" QGIS Unit tests for API documentation coverage.
. . note : : This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
"""
__author__ = ' Nyall Dawson '
__date__ = ' 01/02/2015 '
2016-03-18 09:32:08 +01:00
__copyright__ = ' Copyright 2016, The QGIS Project '
2015-02-01 22:44:37 +11:00
import os
2016-08-10 19:44:30 +02:00
import sys
2017-05-31 17:17:30 +02:00
try :
from qgis . static_testing import unittest
except ImportError :
2017-11-05 22:51:13 +01:00
import unittest
2017-05-31 17:17:30 +02:00
2016-08-10 19:44:30 +02:00
from termcolor import colored
2015-02-01 22:44:37 +11:00
2017-05-31 17:17:30 +02:00
from doxygen_parser import DoxygenParser
2016-07-10 22:58:35 +10:00
from acceptable_missing_doc import ACCEPTABLE_MISSING_DOCS , ACCEPTABLE_MISSING_ADDED_NOTE , ACCEPTABLE_MISSING_BRIEF
2015-02-01 22:44:37 +11:00
2016-03-21 09:10:43 +01:00
# TO regenerate the list:
# uncomment the lines under the `# GEN LIST`
# $ export PYTHONPATH=build/output/python
# $ export QGIS_PREFIX_PATH=build/output
# $ python tests/src/python/test_qgsdoccoverage.py
# copy the output to the file:
# tests/src/python/acceptable_missing_doc.py
# in `ACCEPTABLE_MISSING_DOCS = { <past> }`.
2015-08-22 14:29:41 +02:00
2016-01-06 13:44:29 +01:00
class TestQgsDocCoverage ( unittest . TestCase ) :
2015-02-01 22:44:37 +11:00
def testCoverage ( self ) :
2016-03-18 09:32:08 +01:00
print ( ' CTEST_FULL_OUTPUT ' )
2015-02-01 22:44:37 +11:00
prefixPath = os . environ [ ' QGIS_PREFIX_PATH ' ]
2015-08-22 14:29:41 +02:00
docPath = os . path . join ( prefixPath , ' .. ' , ' doc ' , ' api ' , ' xml ' )
2016-07-10 22:58:35 +10:00
parser = DoxygenParser ( docPath , ACCEPTABLE_MISSING_DOCS , ACCEPTABLE_MISSING_ADDED_NOTE , ACCEPTABLE_MISSING_BRIEF )
2015-02-01 22:44:37 +11:00
2015-10-15 18:31:17 +11:00
coverage = 100.0 * parser . documented_members / parser . documentable_members
missing = parser . documentable_members - parser . documented_members
2015-02-01 22:44:37 +11:00
2016-03-18 09:32:08 +01:00
print ( " --------------------------------- " )
2016-09-20 08:56:57 +10:00
print ( ( " {} total documentable members " . format ( parser . documentable_members ) ) )
print ( ( " {} total contain valid documentation " . format ( parser . documented_members ) ) )
print ( ( " Total documentation coverage {} % " . format ( coverage ) ) )
2016-08-10 19:44:30 +02:00
print ( " --------------------------------- " )
2016-09-20 08:56:57 +10:00
print ( ( " {} members missing documentation " . format ( missing ) ) )
2016-03-18 09:32:08 +01:00
print ( " --------------------------------- " )
print ( " Unacceptable missing documentation: " )
2015-02-01 22:44:37 +11:00
2016-08-10 19:44:30 +02:00
if parser . undocumented_members :
2016-09-20 08:56:57 +10:00
for cls , props in list ( parser . undocumented_members . items ( ) ) :
print ( ( ' \n \n Class {} , {} / {} members documented \n ' . format ( colored ( cls , ' yellow ' ) , props [ ' documented ' ] , props [ ' members ' ] ) ) )
2016-08-10 19:44:30 +02:00
for mem in props [ ' missing_members ' ] :
2018-05-23 08:51:17 +10:00
print ( ( colored ( ' " ' + mem + ' " ' , ' yellow ' , attrs = [ ' bold ' ] ) ) )
2016-08-10 19:44:30 +02:00
2018-05-23 08:21:39 +10:00
if parser . noncompliant_members :
for cls , props in list ( parser . noncompliant_members . items ( ) ) :
print ( ( ' \n \n Class {} , non-compliant members found \n ' . format ( colored ( cls , ' yellow ' ) ) ) )
for p in props :
for mem , error in p . items ( ) :
print ( ( colored ( ' ' + mem + ' : ' + error , ' yellow ' , attrs = [ ' bold ' ] ) ) )
2018-05-24 14:21:24 +10:00
if parser . broken_links :
for cls , props in list ( parser . broken_links . items ( ) ) :
print ( ( ' \n \n Class {} , broken see also links found \n ' . format ( colored ( cls , ' yellow ' ) ) ) )
for member , links in props . items ( ) :
for l in links :
print ( ( colored ( ' ' + member + ' : ' + l , ' yellow ' , attrs = [ ' bold ' ] ) ) )
2016-08-10 19:44:30 +02:00
# self.assertEquals(len(parser.undocumented_string), 0, 'FAIL: new undocumented members have been introduced, please add documentation for these members')
if parser . classes_missing_group :
print ( " --------------------------------- " )
print ( ' \n ' )
2020-05-05 22:55:44 +02:00
print ( ( colored ( ' {} classes have been added without Doxygen group tag ( " \\ ingroup " ): ' . format ( len ( parser . classes_missing_group ) ) , ' yellow ' ) ) )
2016-08-10 19:44:30 +02:00
print ( ' ' )
2016-09-20 08:56:57 +10:00
print ( ( ' ' + ' \n ' . join ( [ colored ( cls , ' yellow ' , attrs = [ ' bold ' ] ) for cls in parser . classes_missing_group ] ) ) )
2015-02-01 22:44:37 +11:00
2016-08-10 19:44:30 +02:00
if parser . classes_missing_version_added :
print ( " --------------------------------- " )
print ( ' \n ' )
2020-05-05 22:55:44 +02:00
print ( ( colored ( ' {} classes have been added without a version added doxygen note ( " \\ since QGIS x.xx " ): ' . format ( len ( parser . classes_missing_version_added ) ) , ' yellow ' ) ) )
2016-08-10 19:44:30 +02:00
print ( ' ' )
2016-09-20 08:56:57 +10:00
print ( ( ' ' + ' \n ' . join ( [ colored ( cls , ' yellow ' , attrs = [ ' bold ' ] ) for cls in parser . classes_missing_version_added ] ) ) )
2016-07-04 18:48:58 +10:00
2016-08-10 19:44:30 +02:00
if parser . classes_missing_brief :
print ( " --------------------------------- " )
print ( ' \n ' )
2016-09-20 08:56:57 +10:00
print ( ( colored ( ' {} classes have been added without at least a brief description: ' . format ( len ( parser . classes_missing_brief ) ) , ' yellow ' ) ) )
2016-08-10 19:44:30 +02:00
print ( ' ' )
2016-09-20 08:56:57 +10:00
print ( ( ' ' + ' \n ' . join ( [ colored ( cls , ' yellow ' , attrs = [ ' bold ' ] ) for cls in parser . classes_missing_brief ] ) ) )
2016-07-04 20:29:46 +10:00
2016-08-10 19:44:30 +02:00
sys . stdout . flush ( )
self . assertTrue ( not parser . undocumented_members , ' Undocumented members found ' )
2017-04-03 00:32:59 +02:00
self . assertTrue ( not parser . classes_missing_group , ' Classes without \\ group tag found ' )
self . assertTrue ( not parser . classes_missing_version_added , ' Classes without \\ since version tag found ' )
self . assertTrue ( not parser . classes_missing_brief , ' Classes without \\ brief description found ' )
2018-05-23 08:21:39 +10:00
self . assertTrue ( not parser . noncompliant_members , ' Non compliant members found ' )
2018-05-24 14:33:59 +10:00
self . assertTrue ( not parser . broken_links , ' Broken links found ' )
2016-07-10 22:58:35 +10:00
2016-07-04 20:29:46 +10:00
2015-02-01 22:44:37 +11:00
if __name__ == ' __main__ ' :
unittest . main ( )