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.

40 lines
1.2 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. class TestUnicodeLiterals(unittest.TestCase):
  8. def test_all_files(self):
  9. print('Skipping this test (not yet fully implemtned)')
  10. return
  11. for dirpath, _, filenames in os.walk(rootDir):
  12. for basename in filenames:
  13. if not basename.endswith('.py'):
  14. continue
  15. fn = os.path.join(dirpath, basename)
  16. with io.open(fn, encoding='utf-8') as inf:
  17. code = inf.read()
  18. if "'" not in code and '"' not in code:
  19. continue
  20. imps = 'from __future__ import unicode_literals'
  21. self.assertTrue(
  22. imps in code,
  23. ' %s missing in %s' % (imps, fn))
  24. m = re.search(r'(?<=\s)u[\'"](?!\)|,|$)', code)
  25. if m is not None:
  26. self.assertTrue(
  27. m is None,
  28. 'u present in %s, around %s' % (
  29. fn, code[m.start() - 10:m.end() + 10]))
  30. if __name__ == '__main__':
  31. unittest.main()