Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

[WIP] Python3 #14574

Merged
merged 7 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ MAINTAINER William Budington "[email protected]"
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
4 changes: 2 additions & 2 deletions test/chromium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
4 changes: 2 additions & 2 deletions test/firefox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions test/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion test/selenium/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
8 changes: 4 additions & 4 deletions test/validations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions test/validations/filename/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python2.7
#
#!/usr/bin/env python3.6
#
# Validates and provides a generator for ruleset filenames
#

Expand All @@ -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)

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions test/validations/relaxng/run.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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."
Expand Down
14 changes: 7 additions & 7 deletions test/validations/securecookie/run.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/validations/special/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3.6

import glob
import argparse
Expand Down Expand Up @@ -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):
Expand Down