Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
hub-client / dockerhub / test / common.py
Size: Mime:
import fnmatch
import os
import re
import unittest

import pep8
from django.conf import settings


class CodeFormat(unittest.TestCase):
    """
    common implementation for testing pep8 compliance of a project
    """
    def get_files_to_pep8(self):
        project_root = getattr(settings, 'PROJECT_ROOT')
        exclude_pep8 = getattr(settings, 'EXCLUDE_PEP8', [])

        matches = []
        if project_root is not None:
            for root, dirnames, filenames in os.walk(project_root):
                for filename in fnmatch.filter(filenames, '*.py'):
                    if exclude_pep8:
                        for exclude_pattern in exclude_pep8:
                            pattern = re.compile(exclude_pattern)
                            if not pattern.findall(os.path.join(root, filename)):
                                matches.append(os.path.join(root, filename))
                    else:
                        matches.append(os.path.join(root, filename))
        return matches

    def pep8_conformance(self):
        """add this to your test to check for comformance"""
        pep8style = pep8.StyleGuide(
            quiet=False,
            config_file=os.path.join(settings.PROJECT_ROOT, 'pep8')
        )
        files = self.get_files_to_pep8()
        result = pep8style.check_files(files)
        self.assertEqual(result.total_errors, 0,
                         "Found code style errors (and warnings).")