You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

  1. from __future__ import unicode_literals
  2. import io
  3. import os
  4. import re
  5. import unittest
  6. rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  7. IGNORED_FILES = [
  8. 'setup.py', # http://bugs.python.org/issue13943
  9. 'conf.py',
  10. 'buildserver.py',
  11. ]
  12. class TestUnicodeLiterals(unittest.TestCase):
  13. def test_all_files(self):
  14. for dirpath, _, filenames in os.walk(rootDir):
  15. for basename in filenames:
  16. if not basename.endswith('.py'):
  17. continue
  18. if basename in IGNORED_FILES:
  19. continue
  20. fn = os.path.join(dirpath, basename)
  21. with io.open(fn, encoding='utf-8') as inf:
  22. code = inf.read()
  23. if "'" not in code and '"' not in code:
  24. continue
  25. self.assertRegexpMatches(
  26. code,
  27. r'(?:#.*\n*)?from __future__ import (?:[a-z_]+,\s*)*unicode_literals',
  28. 'unicode_literals import missing in %s' % fn)
  29. m = re.search(r'(?<=\s)u[\'"](?!\)|,|$)', code)
  30. if m is not None:
  31. self.assertTrue(
  32. m is None,
  33. 'u present in %s, around %s' % (
  34. fn, code[m.start() - 10:m.end() + 10]))
  35. if __name__ == '__main__':
  36. unittest.main()