def _find_git_status()

in testinggame/__init__.py [0:0]


def _find_git_status(directory, xctestsuperclasses):
    """
    Finds the number of tests per user within a given directory. Note that this
    will only work on the root git subdirectory, submodules will not be
    counted.

    Args:
        directory: The path to the directory to scan.
        xctestsuperclasses: An array of strings containing names for xctest
        superclasses.
    Returns:
        A dictionary built off the names argument containing the usernames as a
        key and the number of tests as a value.

    >>> _find_git_status('tests', 'SPTTestCase')
    {'Will Sackfield': 6}
    """
    names = {}
    objc_extensions = ['.m', '.mm']
    java_extensions = ['.java', '.kt']
    cpp_extensions = ['.cpp', '.mm']
    python_extensions = ['.py']
    cs_extensions = ['.cs']
    php_extensions = ['.php']
    valid_extensions = objc_extensions
    valid_extensions.extend(java_extensions)
    valid_extensions.extend(cpp_extensions)
    valid_extensions.extend(python_extensions)
    valid_extensions.extend(cs_extensions)
    valid_extensions.extend(php_extensions)
    for root, dirs, files in os.walk(directory):
        for name in files:
            filename, fileextension = os.path.splitext(name)
            absfile = os.path.join(root, name)
            if fileextension in valid_extensions:
                try:
                    with open(absfile) as sourcefile:
                        source = sourcefile.read()
                        p = subprocess.Popen(['git', 'blame', absfile],
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.PIPE)
                        out, err = p.communicate()
                        blame_lines = out.splitlines()
                        if fileextension in objc_extensions:
                            names = _find_xctest_tests(blame_lines,
                                                       names,
                                                       source,
                                                       xctestsuperclasses)
                        if fileextension in java_extensions:
                            names = _find_java_tests(blame_lines,
                                                     names)
                        if fileextension in cpp_extensions:
                            names = _find_boost_tests(blame_lines,
                                                      names)
                        if fileextension in python_extensions:
                            names = _find_python_tests(blame_lines,
                                                       names,
                                                       source)
                        if fileextension in cs_extensions:
                            names = _find_cs_tests(blame_lines,
                                                   names)
                        if fileextension in php_extensions:
                           names = _find_php_tests(blame_lines,
                                                      names)
                except:
                    'Could not open file: ' + absfile
    return names