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.

47 lines
1.4 KiB

11 years ago
  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. ]
  10. class TestUnicodeLiterals(unittest.TestCase):
  11. def test_all_files(self):
  12. print('Skipping this test (not yet fully implemented)')
  13. return
  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. imps = 'from __future__ import unicode_literals'
  26. self.assertTrue(
  27. imps in code,
  28. ' %s missing in %s' % (imps, 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()