extend doctring test for public wc imports of modules
from unittest import TestCase
import importlib
-MAX_UNDOC_FRAC = 0.25 # Max fraction of undocumented wildcard imports
+MAX_UNDOC_FRAC = 0.25 # Acceptable fraction of undocumented wildcard imports
def get_undocumented_wildcards(modulename):
@@ -16,10 +16,31 @@ def get_undocumented_wildcards(modulename):
return undocumented, len(loc.items())
-class TestFlow(TestCase):
+class TestWildcardImportDocs(TestCase):
- def test_phi_flow(self):
- modulename = "phi.flow"
+ def assert_less_undocumented_wc(self, modulename, max_undoc_frac):
+ """assert that the frac of undocumented public wildcard imports is less than limit
+
+ :param modulename: Module to be checked
+ :type modulename: str
+ :param max_undoc_frac: Limit - Frac. below which undocumented public wildcard imports are okay
+ :type max_undoc_frac: float [0, 1]
+ """
undocumented, loc_len = get_undocumented_wildcards(modulename)
undocumented_fraction = len(undocumented) / loc_len
- self.assertLess(undocumented_fraction, MAX_UNDOC_FRAC, f"{len(undocumented)/loc_len:.2%} of {modulename} imports undocumented. Missing Docstrings in {len(undocumented)}/{loc_len}:\n- " + "\n- ".join(undocumented))
+ self.assertLess(undocumented_fraction, max_undoc_frac, f"{len(undocumented)/loc_len:.2%} of {modulename} imports undocumented. Missing Docstrings in {len(undocumented)}/{loc_len}:\n- " + "\n- ".join(undocumented))
+
+ def test_phi_flow(self):
+ self.assert_less_undocumented_wc("phi.flow", MAX_UNDOC_FRAC)
+
+ def test_phi_math(self):
+ self.assert_less_undocumented_wc("phi.math", MAX_UNDOC_FRAC * 3)
+
+ def test_phi_physics(self):
+ self.assert_less_undocumented_wc("phi.physics", MAX_UNDOC_FRAC)
+
+ def test_phi_field(self):
+ self.assert_less_undocumented_wc("phi.field", MAX_UNDOC_FRAC * 2)
+
+ def test_phi_struct(self):
+ self.assert_less_undocumented_wc("phi.struct", MAX_UNDOC_FRAC * 2)
