aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-11-26 20:01:20 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2014-11-26 20:01:22 +0100
commitdcddc10a5032996474e157946b00b8df039eebda (patch)
treec0203ee3349bcae04bab970657e391f4fc255736
parenta1008af412f51aac82c121eaed07f742055d010b (diff)
[test_unicode_literals] Arm unicode_literals check
From now on, the line from __future__ import unicode_literals should be contained in every single Python file lest we run into any more 2.x/3.x issues. Going forward, we're likely to develop on 3.x only and would likely miss subtle bugs otherwise.
-rwxr-xr-xdevscripts/bash-completion.py2
-rw-r--r--devscripts/check-porn.py1
-rwxr-xr-xdevscripts/gh-pages/add-version.py1
-rwxr-xr-xdevscripts/gh-pages/generate-download.py2
-rwxr-xr-xdevscripts/gh-pages/sign-versions.py4
-rwxr-xr-xdevscripts/gh-pages/update-copyright.py4
-rwxr-xr-xdevscripts/gh-pages/update-feed.py1
-rwxr-xr-xdevscripts/gh-pages/update-sites.py1
-rwxr-xr-xdevscripts/make_readme.py2
-rw-r--r--devscripts/prepare_manpage.py1
-rwxr-xr-xdevscripts/zsh-completion.py2
-rw-r--r--test/test_unicode_literals.py13
-rw-r--r--test/test_write_annotations.py1
-rw-r--r--test/test_write_info_json.py7
-rw-r--r--test/test_youtube_lists.py1
-rwxr-xr-xyoutube_dl/__main__.py1
-rw-r--r--youtube_dl/aes.py2
-rw-r--r--youtube_dl/extractor/__init__.py2
-rw-r--r--youtube_dl/extractor/bambuser.py2
-rw-r--r--youtube_dl/postprocessor/__init__.py1
-rw-r--r--youtube_dl/postprocessor/common.py2
-rw-r--r--youtube_dl/postprocessor/xattrpp.py2
-rw-r--r--youtube_dl/version.py1
23 files changed, 42 insertions, 14 deletions
diff --git a/devscripts/bash-completion.py b/devscripts/bash-completion.py
index 70a3f552c..cd26cc089 100755
--- a/devscripts/bash-completion.py
+++ b/devscripts/bash-completion.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python
+from __future__ import unicode_literals
+
import os
from os.path import dirname as dirn
import sys
diff --git a/devscripts/check-porn.py b/devscripts/check-porn.py
index 86aa37b5f..216282712 100644
--- a/devscripts/check-porn.py
+++ b/devscripts/check-porn.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from __future__ import unicode_literals
"""
This script employs a VERY basic heuristic ('porn' in webpage.lower()) to check
diff --git a/devscripts/gh-pages/add-version.py b/devscripts/gh-pages/add-version.py
index 35865b2f3..867ea0048 100755
--- a/devscripts/gh-pages/add-version.py
+++ b/devscripts/gh-pages/add-version.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+from __future__ import unicode_literals
import json
import sys
diff --git a/devscripts/gh-pages/generate-download.py b/devscripts/gh-pages/generate-download.py
index e90c787fd..392e3ba21 100755
--- a/devscripts/gh-pages/generate-download.py
+++ b/devscripts/gh-pages/generate-download.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
+from __future__ import unicode_literals
+
import hashlib
import urllib.request
import json
diff --git a/devscripts/gh-pages/sign-versions.py b/devscripts/gh-pages/sign-versions.py
index 953a5162e..fa389c358 100755
--- a/devscripts/gh-pages/sign-versions.py
+++ b/devscripts/gh-pages/sign-versions.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+from __future__ import unicode_literals, with_statement
import rsa
import json
@@ -29,4 +30,5 @@ signature = hexlify(rsa.pkcs1.sign(json.dumps(versions_info, sort_keys=True).enc
print('signature: ' + signature)
versions_info['signature'] = signature
-json.dump(versions_info, open('update/versions.json', 'w'), indent=4, sort_keys=True)
+with open('update/versions.json', 'w') as versionsf:
+ json.dump(versions_info, versionsf, indent=4, sort_keys=True)
diff --git a/devscripts/gh-pages/update-copyright.py b/devscripts/gh-pages/update-copyright.py
index 5bc5c6514..3663c8afe 100755
--- a/devscripts/gh-pages/update-copyright.py
+++ b/devscripts/gh-pages/update-copyright.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# coding: utf-8
-from __future__ import with_statement
+from __future__ import with_statement, unicode_literals
import datetime
import glob
@@ -13,7 +13,7 @@ year = str(datetime.datetime.now().year)
for fn in glob.glob('*.html*'):
with io.open(fn, encoding='utf-8') as f:
content = f.read()
- newc = re.sub(u'(?P<copyright>Copyright © 2006-)(?P<year>[0-9]{4})', u'Copyright © 2006-' + year, content)
+ newc = re.sub(r'(?P<copyright>Copyright © 2006-)(?P<year>[0-9]{4})', 'Copyright © 2006-' + year, content)
if content != newc:
tmpFn = fn + '.part'
with io.open(tmpFn, 'wt', encoding='utf-8') as outf:
diff --git a/devscripts/gh-pages/update-feed.py b/devscripts/gh-pages/update-feed.py
index 46373a8db..e93eb60fb 100755
--- a/devscripts/gh-pages/update-feed.py
+++ b/devscripts/gh-pages/update-feed.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+from __future__ import unicode_literals
import datetime
import io
diff --git a/devscripts/gh-pages/update-sites.py b/devscripts/gh-pages/update-sites.py
index 4a6bb5e35..f0f0481c7 100755
--- a/devscripts/gh-pages/update-sites.py
+++ b/devscripts/gh-pages/update-sites.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+from __future__ import unicode_literals
import sys
import os
diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py
index 70fa942dd..8fbce0796 100755
--- a/devscripts/make_readme.py
+++ b/devscripts/make_readme.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import io
import sys
import re
diff --git a/devscripts/prepare_manpage.py b/devscripts/prepare_manpage.py
index d9c857015..f66bebfea 100644
--- a/devscripts/prepare_manpage.py
+++ b/devscripts/prepare_manpage.py
@@ -1,3 +1,4 @@
+from __future__ import unicode_literals
import io
import os.path
diff --git a/devscripts/zsh-completion.py b/devscripts/zsh-completion.py
index e8d71928a..f200f2c80 100755
--- a/devscripts/zsh-completion.py
+++ b/devscripts/zsh-completion.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python
+from __future__ import unicode_literals
+
import os
from os.path import dirname as dirn
import sys
diff --git a/test/test_unicode_literals.py b/test/test_unicode_literals.py
index a4ba7bad0..2cc431b0b 100644
--- a/test/test_unicode_literals.py
+++ b/test/test_unicode_literals.py
@@ -9,14 +9,13 @@ rootDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
IGNORED_FILES = [
'setup.py', # http://bugs.python.org/issue13943
+ 'conf.py',
+ 'buildserver.py',
]
class TestUnicodeLiterals(unittest.TestCase):
def test_all_files(self):
- print('Skipping this test (not yet fully implemented)')
- return
-
for dirpath, _, filenames in os.walk(rootDir):
for basename in filenames:
if not basename.endswith('.py'):
@@ -30,10 +29,10 @@ class TestUnicodeLiterals(unittest.TestCase):
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))
+ self.assertRegexpMatches(
+ code,
+ r'(?:#.*\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:
diff --git a/test/test_write_annotations.py b/test/test_write_annotations.py
index 852553ada..780636c77 100644
--- a/test/test_write_annotations.py
+++ b/test/test_write_annotations.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# coding: utf-8
+from __future__ import unicode_literals
# Allow direct execution
import os
diff --git a/test/test_write_info_json.py b/test/test_write_info_json.py
index 90426a559..0396ef262 100644
--- a/test/test_write_info_json.py
+++ b/test/test_write_info_json.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# coding: utf-8
+from __future__ import unicode_literals
# Allow direct execution
import os
@@ -32,7 +33,7 @@ params = get_params({
TEST_ID = 'BaW_jenozKc'
INFO_JSON_FILE = TEST_ID + '.info.json'
DESCRIPTION_FILE = TEST_ID + '.mp4.description'
-EXPECTED_DESCRIPTION = u'''test chars: "'/\ä↭𝕐
+EXPECTED_DESCRIPTION = '''test chars: "'/\ä↭𝕐
test URL: https://github.com/rg3/youtube-dl/issues/1892
This is a test video for youtube-dl.
@@ -53,11 +54,11 @@ class TestInfoJSON(unittest.TestCase):
self.assertTrue(os.path.exists(INFO_JSON_FILE))
with io.open(INFO_JSON_FILE, 'r', encoding='utf-8') as jsonf:
jd = json.load(jsonf)
- self.assertEqual(jd['upload_date'], u'20121002')
+ self.assertEqual(jd['upload_date'], '20121002')
self.assertEqual(jd['description'], EXPECTED_DESCRIPTION)
self.assertEqual(jd['id'], TEST_ID)
self.assertEqual(jd['extractor'], 'youtube')
- self.assertEqual(jd['title'], u'''youtube-dl test video "'/\ä↭𝕐''')
+ self.assertEqual(jd['title'], '''youtube-dl test video "'/\ä↭𝕐''')
self.assertEqual(jd['uploader'], 'Philipp Hagemeister')
self.assertTrue(os.path.exists(DESCRIPTION_FILE))
diff --git a/test/test_youtube_lists.py b/test/test_youtube_lists.py
index 4ceba64ae..c889b6f15 100644
--- a/test/test_youtube_lists.py
+++ b/test/test_youtube_lists.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from __future__ import unicode_literals
# Allow direct execution
import os
diff --git a/youtube_dl/__main__.py b/youtube_dl/__main__.py
index 3fe29c91f..65a0f891c 100755
--- a/youtube_dl/__main__.py
+++ b/youtube_dl/__main__.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+from __future__ import unicode_literals
# Execute with
# $ python youtube_dl/__main__.py (2.6+)
diff --git a/youtube_dl/aes.py b/youtube_dl/aes.py
index 2eeb96a5a..5efd0f836 100644
--- a/youtube_dl/aes.py
+++ b/youtube_dl/aes.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
__all__ = ['aes_encrypt', 'key_expansion', 'aes_ctr_decrypt', 'aes_cbc_decrypt', 'aes_decrypt_text']
import base64
diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py
index 5c096542b..bbac03913 100644
--- a/youtube_dl/extractor/__init__.py
+++ b/youtube_dl/extractor/__init__.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
from .abc import ABCIE
from .academicearth import AcademicEarthCourseIE
from .addanime import AddAnimeIE
diff --git a/youtube_dl/extractor/bambuser.py b/youtube_dl/extractor/bambuser.py
index ea2ba0fe2..1ca0b7cf2 100644
--- a/youtube_dl/extractor/bambuser.py
+++ b/youtube_dl/extractor/bambuser.py
@@ -18,7 +18,7 @@ class BambuserIE(InfoExtractor):
_TEST = {
'url': 'http://bambuser.com/v/4050584',
# MD5 seems to be flaky, see https://travis-ci.org/rg3/youtube-dl/jobs/14051016#L388
- # u'md5': 'fba8f7693e48fd4e8641b3fd5539a641',
+ # 'md5': 'fba8f7693e48fd4e8641b3fd5539a641',
'info_dict': {
'id': '4050584',
'ext': 'flv',
diff --git a/youtube_dl/postprocessor/__init__.py b/youtube_dl/postprocessor/__init__.py
index 6ac67cbae..fb367ebe4 100644
--- a/youtube_dl/postprocessor/__init__.py
+++ b/youtube_dl/postprocessor/__init__.py
@@ -1,3 +1,4 @@
+from __future__ import unicode_literals
from .atomicparsley import AtomicParsleyPP
from .ffmpeg import (
diff --git a/youtube_dl/postprocessor/common.py b/youtube_dl/postprocessor/common.py
index 788f94d02..e54ae678d 100644
--- a/youtube_dl/postprocessor/common.py
+++ b/youtube_dl/postprocessor/common.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
from ..utils import PostProcessingError
diff --git a/youtube_dl/postprocessor/xattrpp.py b/youtube_dl/postprocessor/xattrpp.py
index d1991c4f8..f6c63fe97 100644
--- a/youtube_dl/postprocessor/xattrpp.py
+++ b/youtube_dl/postprocessor/xattrpp.py
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
import os
import subprocess
import sys
diff --git a/youtube_dl/version.py b/youtube_dl/version.py
index 82c204592..131d72a67 100644
--- a/youtube_dl/version.py
+++ b/youtube_dl/version.py
@@ -1,2 +1,3 @@
+from __future__ import unicode_literals
__version__ = '2014.11.26'