parameters: (check_files, paths, git_change_years, third_party_files)
docstring: Tests all in-sourcefile legal headers.
docstring_summary: Tests all in-sourcefile legal headers.
docstring_tokens: Tests all in - sourcefile legal headers .
function: def test_headers(check_files, paths, git_change_years, third_party_files):
      """ Tests all in-sourcefile legal headers. """
  
      if not git_change_years:
          print("warning: I won't check if the copyright matches the git history.")
          print("         Run with --test-git-change-years to enable the check.")
  
      # determine all uncommited files from git.
      # those definitely need the current year in the copyright message.
      with Popen(['git', 'diff', '--name-only', 'HEAD'], stdout=PIPE) as proc:
          uncommited = set(proc.communicate()[0].decode('ascii').strip().split('\n'))
  
      current_calendar_year = date.today().year
  
      for filename in findfiles(paths, EXTENSIONS_REQUIRING_LEGAL_HEADERS):
          try:
              file_content = readfile(filename)
              headertype, match = match_legalheader(file_content)
          except ValueError:
              yield (
                  "Legal header missing or invalid",
                  (filename + "\nSee copying.md for a template"),
                  None
              )
              continue
  
          if headertype is THIRDPARTYLEGALHEADER:
              third_party_files.add(filename)
  
          try:
              found_start_year = int(match.group('crstart'))
              found_end_year = int(match.group('crend'))
          except IndexError:
              # this header type has/needs no copyright years
              # (e.g. empty file)
              continue
  
          expected_end_year = None
          if filename in uncommited:
              expected_end_year = current_calendar_year
          elif git_change_years:
              if check_files is None or filename in check_files:
                  expected_end_year = get_git_change_year(filename)
  
          if expected_end_year is None:
              continue
  
          if found_end_year != expected_end_year:
  
              fix = create_year_fix(
                  filename,
                  file_content,
                  expected_end_year,
                  found_start_year,
                  headertype
              )
  
              yield (
                  "Bad copyright year",
                  (filename + "\n" +
                   "\tExpected %d\n" % expected_end_year +
                   "\tFound    %d" % found_end_year),
                  fix
              )
function_tokens: def test_headers ( check_files , paths , git_change_years , third_party_files ) : if not git_change_years : print ( "warning: I won't check if the copyright matches the git history." ) print ( "         Run with --test-git-change-years to enable the check." ) # determine all uncommited files from git. # those definitely need the current year in the copyright message. with Popen ( [ 'git' , 'diff' , '--name-only' , 'HEAD' ] , stdout = PIPE ) as proc : uncommited = set ( proc . communicate ( ) [ 0 ] . decode ( 'ascii' ) . strip ( ) . split ( '\n' ) ) current_calendar_year = date . today ( ) . year for filename in findfiles ( paths , EXTENSIONS_REQUIRING_LEGAL_HEADERS ) : try : file_content = readfile ( filename ) headertype , match = match_legalheader ( file_content ) except ValueError : yield ( "Legal header missing or invalid" , ( filename + "\nSee copying.md for a template" ) , None ) continue if headertype is THIRDPARTYLEGALHEADER : third_party_files . add ( filename ) try : found_start_year = int ( match . group ( 'crstart' ) ) found_end_year = int ( match . group ( 'crend' ) ) except IndexError : # this header type has/needs no copyright years # (e.g. empty file) continue expected_end_year = None if filename in uncommited : expected_end_year = current_calendar_year elif git_change_years : if check_files is None or filename in check_files : expected_end_year = get_git_change_year ( filename ) if expected_end_year is None : continue if found_end_year != expected_end_year : fix = create_year_fix ( filename , file_content , expected_end_year , found_start_year , headertype ) yield ( "Bad copyright year" , ( filename + "\n" + "\tExpected %d\n" % expected_end_year + "\tFound    %d" % found_end_year ) , fix )