diff --git a/Dockerfile b/Dockerfile index 6ffee8e42419..eaf31bb4a93d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,4 +3,6 @@ MAINTAINER William Budington "bill@eff.org" WORKDIR /opt COPY test/rules/requirements.txt /tmp/ -RUN pip install -r /tmp/requirements.txt && rm /tmp/requirements.txt +RUN pip install -r /tmp/requirements.txt +RUN pip3 install -r /tmp/requirements.txt +RUN rm /tmp/requirements.txt diff --git a/test/chromium.sh b/test/chromium.sh index 7724dcbc865a..efc134dba48d 100755 --- a/test/chromium.sh +++ b/test/chromium.sh @@ -25,7 +25,7 @@ if [ "$1" == "--justrun" ]; then PROFILE_DIRECTORY="$(mktemp -d)" trap 'rm -r "$PROFILE_DIRECTORY"' EXIT - + # Chromium package name is 'chromium' in Debian 7 (wheezy) and other distros like Arch BROWSER="chromium-browser" which $BROWSER || BROWSER="chromium" @@ -37,5 +37,5 @@ else ./make.sh echo "running tests" CRX_NAME="`ls -tr pkg/*.crx | tail -1`" - $XVFB_RUN python2.7 test/script.py Chrome $CRX_NAME + $XVFB_RUN python3.6 test/script.py Chrome $CRX_NAME fi diff --git a/test/firefox.sh b/test/firefox.sh index de60bfb4b376..56ec5720ef59 100755 --- a/test/firefox.sh +++ b/test/firefox.sh @@ -58,8 +58,8 @@ else PATH=/home/user/geckodriver:$PATH if [ -n "$FIREFOX" ]; then - $XVFB_RUN python2.7 test/script.py Firefox "$PROFILE_DIRECTORY" $FIREFOX + $XVFB_RUN python3.6 test/script.py Firefox "$PROFILE_DIRECTORY" $FIREFOX else - $XVFB_RUN python2.7 test/script.py Firefox "$PROFILE_DIRECTORY" + $XVFB_RUN python3.6 test/script.py Firefox "$PROFILE_DIRECTORY" fi fi diff --git a/test/script.py b/test/script.py index ec53abd71554..219e3c7945ae 100644 --- a/test/script.py +++ b/test/script.py @@ -49,8 +49,8 @@ class bcolors: error = e.__str__() if "executable needs to be in PATH" in e.__str__(): - print "ChromeDriver isn't installed. Check test/chromium/README.md " \ - "for instructions on how to install ChromeDriver" + print("ChromeDriver isn't installed. Check test/chromium/README.md " \ + "for instructions on how to install ChromeDriver") sys.exit(2) else: @@ -68,8 +68,8 @@ class bcolors: error = e.__str__() if "executable needs to be in PATH" in e.__str__(): - print "GeckoDriver isn't installed. Check test/firefox/README.md " \ - "for instructions on how to install GeckoDriver" + print("GeckoDriver isn't installed. Check test/firefox/README.md " \ + "for instructions on how to install GeckoDriver") sys.exit(2) else: @@ -78,18 +78,18 @@ class bcolors: # Allow the extension time to load time.sleep(1) -print '' +print('') driver.get('http://freerangekitten.com') test_failed = False if driver.current_url.startswith('https'): - print bcolors.OKGREEN + sys.argv[1] + ": HTTP to HTTPS redirection successful" + bcolors.ENDC + print(bcolors.OKGREEN + sys.argv[1] + ": HTTP to HTTPS redirection successful" + bcolors.ENDC) elif driver.current_url.startswith('http'): - print bcolors.FAIL + sys.argv[1] + ": HTTP to HTTPS redirection failed" + bcolors.ENDC + print(bcolors.FAIL + sys.argv[1] + ": HTTP to HTTPS redirection failed" + bcolors.ENDC) test_failed = True -print '' +print('') driver.quit() diff --git a/test/selenium/util.py b/test/selenium/util.py index ba5cd448fb8c..35c1618f1289 100644 --- a/test/selenium/util.py +++ b/test/selenium/util.py @@ -81,7 +81,7 @@ def load_popup_for(self, url='about:blank'): chrome.tabs.create({url: '%s'}, function(tab) { setTimeout( () => chrome.tabs.create({url: '%s' + '?tabId=' + String(tab.id)}, done), - 250 + 500 ); }); })(arguments[0]); diff --git a/test/validations.sh b/test/validations.sh index c13a127c5e9f..50d328a6155c 100755 --- a/test/validations.sh +++ b/test/validations.sh @@ -4,7 +4,7 @@ utils/remove-obsolete-references.sh test/validations/path/run.sh test/validations/test-coverage/run.sh -python2.7 test/validations/securecookie/run.py -python2.7 test/validations/filename/run.py -python2.7 test/validations/relaxng/run.py -python2.7 test/validations/special/run.py --quiet +python3.6 test/validations/securecookie/run.py +python3.6 test/validations/filename/run.py +python3.6 test/validations/relaxng/run.py +python3.6 test/validations/special/run.py --quiet diff --git a/test/validations/filename/run.py b/test/validations/filename/run.py index 0f288e3a126e..37c0bdaedd3c 100755 --- a/test/validations/filename/run.py +++ b/test/validations/filename/run.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python2.7 -# +#!/usr/bin/env python3.6 +# # Validates and provides a generator for ruleset filenames # @@ -18,7 +18,7 @@ def validate_filenames(): most_common_entry = counted_lowercase_names.most_common(1)[0] if most_common_entry[1] > 1: dupe_filename = re.compile(re.escape(most_common_entry[0]), re.IGNORECASE) - print("%s failed case-insensitivity testing." % filter(dupe_filename.match, filenames)) + print("{} failed case-insensitivity testing.".format(list(filter(dupe_filename.match, filenames)))) print("Rules exist with identical case-insensitive names, which breaks some filesystems.") sys.exit(1) @@ -28,10 +28,10 @@ def validate_filenames(): continue if " " in fi: - print("%s failed validity: Rule filenames cannot contain spaces" % (fi)) + print("{} failed validity: Rule filenames cannot contain spaces".format(fi)) sys.exit(1) if not fi.endswith('.xml'): - print("%s failed validity: Rule filenames must end in .xml" % (fi)) + print("{} failed validity: Rule filenames must end in .xml".format(fi)) sys.exit(1) yield fi diff --git a/test/validations/relaxng/run.py b/test/validations/relaxng/run.py index 32503a58c22f..97e730934c35 100644 --- a/test/validations/relaxng/run.py +++ b/test/validations/relaxng/run.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3.6 # -*- encoding: utf-8 -*- import argparse import glob import os -import unicodedata from lxml import etree @@ -31,7 +30,7 @@ if not relaxng.validate(tree): exit_code = 1 e = relaxng.error_log.last_error - print(("%s %s:%s:%s: %s" % (e.level_name, e.filename, e.line, e.column, e.message))) + print("{} {}:{}:{}: {}".format(e.level_name, e.filename, e.line, e.column, e.message)) if exit_code == 0: message = "Validation of rulesets against relaxng schema.xml succeeded." diff --git a/test/validations/securecookie/run.py b/test/validations/securecookie/run.py index cad8361a3094..da315dd52428 100644 --- a/test/validations/securecookie/run.py +++ b/test/validations/securecookie/run.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3.6 # This python utility check for wildcard securecookies which -# can be normalized, warn and exit with non-zero when such -# rulesets exist. +# can be normalized, warn and exit with non-zero when such +# rulesets exist. # This is create in attempt to fix the issues on # https://github.com/EFForg/https-everywhere/pull/13840 @@ -16,10 +16,10 @@ def normalize_fn(fn): """ - OSX and Linux filesystems encode composite characters differently in + OSX and Linux filesystems encode composite characters differently in filenames. We should normalize to NFC: https://unicode.org/reports/tr15/ """ - fn = unicodedata.normalize("NFC", unicode(fn, "utf-8")).encode() + fn = unicodedata.normalize("NFC", fn) return fn def should_normalize_securecookie(host, name): @@ -50,8 +50,8 @@ def should_normalize_securecookie(host, name): name = branch.attrib["name"] if should_normalize_securecookie(host, name): - print ("ERROR %s: contains wildcard securecookies "\ - "which can be normalized." % filename) + print ("ERROR {}: contains wildcard securecookies "\ + "which can be normalized.".format(filename)) exit_with_non_zero = True break diff --git a/test/validations/special/run.py b/test/validations/special/run.py index b9733b42a13d..737fea1001ba 100755 --- a/test/validations/special/run.py +++ b/test/validations/special/run.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3.6 import glob import argparse @@ -163,7 +163,7 @@ def nomes_all(where=sys.argv[1:]): try: tree = etree.parse(filename, xml_parser) except Exception as oops: - print("%s failed XML validity: %s\n" % (filename, oops)) + print("{} failed XML validity: {}\n".format(filename, oops)) sys.exit(1) if not xpath_ruleset(tree):