def test_source_files_specify_encoding():
 pattern = re.compile(u'#.*?coding[:=][ \\t]*utf-?8')
 decode_errors = []
 no_specification = []
 for (abs_path, rel_path) in walk_python_files():
  try:
   with io.open(abs_path, encoding=u'utf-8') as f:
    for line in f:
     line = line.strip()
     if pattern.match(line):
      break
     elif (line and (not line.startswith(u'#'))):
      no_specification.append(rel_path)
      break
  except UnicodeDecodeError:
   decode_errors.append(rel_path)
 msgs = []
 if no_specification:
  msgs.append(u'The following files are missing an encoding specification: {}'.format(no_specification))
 if decode_errors:
  msgs.append(u'The following files are not valid UTF-8: {}'.format(decode_errors))
 if msgs:
  assert False, u'\n\n'.join(msgs)

def test_source_files_specify_encoding ( ) : pattern = re . compile ( u'#.*?coding[:=][ \\t]*utf-?8' ) decode_errors = [ ] no_specification = [ ] for ( abs_path , rel_path ) in walk_python_files ( ) : try : with io . open ( abs_path , encoding = u'utf-8' ) as f : for line in f : line = line . strip ( ) if pattern . match ( line ) : break elif ( line and ( not line . startswith ( u'#' ) ) ) : no_specification . append ( rel_path ) break except UnicodeDecodeError : decode_errors . append ( rel_path ) msgs = [ ] if no_specification : msgs . append ( u'The following files are missing an encoding specification: {}' . format ( no_specification ) ) if decode_errors : msgs . append ( u'The following files are not valid UTF-8: {}' . format ( decode_errors ) ) if msgs : assert False , u'\n\n' . join ( msgs )
test that * .