def validate(self, filename, module, classname, ignore): """ Finds all automethod and autoattribute statements in an rst file comparing them to the attributes found in the actual class """ with open(os.path.normpath(os.path.join('docs', 'reference', filename))) as f: docs = f.read() module = module_loading.import_module(module) methods = re.findall(r'^\.\. automethod:: ([^\(\n]+)', docs, flags=re.M) attributes = re.findall(r'^\.\. autoattribute:: ([^\n]+)', docs, flags=re.M) documented = set( filter(lambda x: x.startswith(classname), [a for a in methods] + attributes)) implemented = set(classname + '.' + x for x in dir(getattr(module, classname)) if not x.startswith('_') or x == '__init__') print(implemented) ignored = set(classname + '.' + x for x in ignore) self.assertSetEqual(implemented - documented - ignored, set(), msg='Implemented but not Documented') self.assertSetEqual(documented - implemented - ignored, set(), msg='Documented but not Implemented')
def project_command_dir(): module_name = project_settings_path() if not module_name: return None module = import_module(module_name) return os.path.join(os.path.dirname(module.__file__), 'management', 'commands')
def load_command_class(app_name, name): module = import_module('{}.management.commands.{}'.format(app_name, name)) return module.Command()