X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=test%2Ftest_unicode_literals.py;h=19813e034cb533c58a75d1a1be330e6781296657;hb=8acb83d9937211abe7194161be863194ae445d95;hp=5f88ac2f87393f2adddf2416689fdfb510b056b6;hpb=6febd1c1df02870bf8b529ca758d7155cf65ab35;p=youtube-dl.git diff --git a/test/test_unicode_literals.py b/test/test_unicode_literals.py index 5f88ac2f8..19813e034 100644 --- a/test/test_unicode_literals.py +++ b/test/test_unicode_literals.py @@ -1,5 +1,11 @@ from __future__ import unicode_literals +# Allow direct execution +import os +import sys +import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + import io import os import re @@ -7,26 +13,36 @@ import unittest rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +IGNORED_FILES = [ + 'setup.py', # http://bugs.python.org/issue13943 + 'conf.py', + 'buildserver.py', +] + + +from test.helper import assertRegexpMatches + class TestUnicodeLiterals(unittest.TestCase): def test_all_files(self): - print('Skipping this test (not yet fully implemtned)') - return - for dirpath, _, filenames in os.walk(rootDir): for basename in filenames: if not basename.endswith('.py'): continue + if basename in IGNORED_FILES: + continue + fn = os.path.join(dirpath, basename) with io.open(fn, encoding='utf-8') as inf: code = inf.read() if "'" not in code and '"' not in code: continue - imps = 'from __future__ import unicode_literals' - self.assertTrue( - imps in code, - ' %s missing in %s' % (imps, fn)) + assertRegexpMatches( + self, + code, + r'(?:(?:#.*?|\s*)\n)*from __future__ import (?:[a-z_]+,\s*)*unicode_literals', + 'unicode_literals import missing in %s' % fn) m = re.search(r'(?<=\s)u[\'"](?!\)|,|$)', code) if m is not None: