Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests run on py3 #398

Merged
merged 48 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
bcf95ae
Cleanup: remove gettext functions override
julen Jan 13, 2020
571d3e1
py3: make sure to compare integers to integers
julen Jan 14, 2020
6216567
py3: __unicode__ -> __str__
julen Jan 14, 2020
da8df5c
py3: use `except ... as ...`
julen Jan 14, 2020
ee05d35
py3: use print function
julen Jan 14, 2020
b05729a
py3: unicode -> str
julen Jan 14, 2020
db856cd
py3: force_unicode -> force_text
julen Jan 14, 2020
22ded4e
py3: hashlib.md5 requires encoded bytes
julen Jan 14, 2020
619b93a
py3: compare bytes to bytes
julen Jan 14, 2020
471863a
py3: encode str to bytes when writing
julen Jan 14, 2020
e8f663d
py3: argparse changed its output
julen Jan 14, 2020
00a32ae
py3: e.message doesn't exist, use str(e) instead
julen Jan 15, 2020
6a2fb00
py3: `int` is the only integer type
julen Jan 16, 2020
753e575
url_trim: encoding name is 'unicode' as a string
julen Jan 16, 2020
a938dea
py3: iterkeys() -> iter(...keys())
julen Jan 16, 2020
75654c9
py3: itervalues() -> iter(...values())
julen Jan 16, 2020
2c9ccbb
py3: iteritems() -> iter(...items())
julen Jan 16, 2020
1c39237
py3: .next() -> next(...)
julen Jan 16, 2020
8ae732f
py3: no need to shim `input` anymore
julen Jan 16, 2020
de492dc
py3: string type is now 'str'
julen Jan 16, 2020
9716203
py3: xrange -> range
julen Jan 16, 2020
415c2b3
py3: absolute_import is now default behavior
julen Jan 16, 2020
f873c1e
py3: use explicit relative imports
julen Jan 16, 2020
900238c
update_tmserver: be explicit on used configuration
julen Jan 16, 2020
297fecb
py3: `reduce` moved to the functools package
julen Jan 16, 2020
e9e5d02
py3: `execfile` was removed
julen Jan 16, 2020
816a784
py3: func_code -> __code__
julen Jan 16, 2020
57e1db5
py3: L suffix is not allowed in numeric literals
julen Jan 16, 2020
bb92c96
py: octal literals must be prefixed by `0o`
julen Jan 16, 2020
002d6ce
py3: integer literals that start with 0 are illegal
julen Jan 16, 2020
b7a2f3a
py3: adjust urllib/urlparse imports to urllib.parse
julen Jan 19, 2020
81051c5
py3: drop redundant `re.U` flag for `re.compile`
julen Jan 19, 2020
7451f09
py3: make sure serialization returns bytes
julen Jan 19, 2020
3e01065
py3: open test files in binary mode
julen Jan 19, 2020
b374028
py3: make sure to compare numbers against numbers
julen Jan 19, 2020
3e9c8f4
py3: redis-py now returns bytes, convert to str
julen Jan 21, 2020
1b2c7e9
py3: filter/map now return iterators
julen Jan 21, 2020
9394906
py3: convert `keys()` and `items()` to list
julen Jan 21, 2020
7e7b4fa
py3: use text strings consistently in migration files
julen Jan 21, 2020
0a7a333
py3: fix bytes/str API mismatches in MathCaptchaForm
julen Jan 21, 2020
54f80d0
py3: convert QuerySet result to list
julen Jan 21, 2020
af3b279
py3: the `cmp` argument to `sorted()` was removed
julen Jan 21, 2020
9977130
Travis: switch to python 3.7
julen Jan 21, 2020
5522e69
Reqs: use pylint 2.4.4
julen Jan 21, 2020
ce94dc8
py3: `logging.warn` is deprecated
julen Jan 21, 2020
54bc7fd
py3: fix file io in runner
julen Jan 21, 2020
d47a758
Fix SQLite test
julen Jan 21, 2020
6637ada
py3: use raw strings for regexes
julen Jan 22, 2020
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
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sudo: false
language: python
python: 2.7
python: 3.7
env:
- TOXENV=py27-django111-sqlite
- TOXENV=py27-django111-mysql
- TOXENV=py27-django111-postgres
- TOXENV=py37-django111-sqlite
- TOXENV=py37-django111-mysql
- TOXENV=py37-django111-postgres
# Meta
- TOXENV=project
cache:
Expand Down
4 changes: 2 additions & 2 deletions pootle/apps/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')),
('username', models.CharField(help_text='Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters', unique=True, max_length=30, verbose_name='Username', validators=[django.core.validators.RegexValidator(re.compile(b'^[\\w.@+-]+$'), 'Enter a valid username.', b'invalid')])),
('username', models.CharField(help_text='Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters', unique=True, max_length=30, verbose_name='Username', validators=[django.core.validators.RegexValidator(re.compile('^[\\w.@+-]+$'), 'Enter a valid username.', 'invalid')])),
('email', models.EmailField(max_length=255, verbose_name='Email Address')),
('full_name', models.CharField(max_length=255, verbose_name='Full Name', blank=True)),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='Active')),
Expand All @@ -30,7 +30,7 @@ class Migration(migrations.Migration):
('review_rate', models.FloatField(default=0, verbose_name='Review Rate')),
('hourly_rate', models.FloatField(default=0, verbose_name='Hourly Rate')),
('score', models.FloatField(default=0, verbose_name='Score')),
('currency', models.CharField(blank=True, max_length=3, null=True, verbose_name='Currency', choices=[(b'USD', b'USD'), (b'EUR', b'EUR'), (b'CNY', b'CNY'), (b'JPY', b'JPY')])),
('currency', models.CharField(blank=True, max_length=3, null=True, verbose_name='Currency', choices=[('USD', 'USD'), ('EUR', 'EUR'), ('CNY', 'CNY'), ('JPY', 'JPY')])),
('is_employee', models.BooleanField(default=False, verbose_name='Is employee?')),
('twitter', models.CharField(max_length=15, null=True, verbose_name='Twitter', blank=True)),
('website', models.URLField(null=True, verbose_name='Website', blank=True)),
Expand Down
2 changes: 1 addition & 1 deletion pootle/apps/accounts/migrations/0006_auto_add_gbp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='user',
name='currency',
field=models.CharField(blank=True, choices=[(b'USD', b'USD'), (b'EUR', b'EUR'), (b'CNY', b'CNY'), (b'JPY', b'JPY'), (b'GBP', b'GBP')], max_length=3, null=True, verbose_name='Currency'),
field=models.CharField(blank=True, choices=[('USD', 'USD'), ('EUR', 'EUR'), ('CNY', 'CNY'), ('JPY', 'JPY'), ('GBP', 'GBP')], max_length=3, null=True, verbose_name='Currency'),
),
]
8 changes: 4 additions & 4 deletions pootle/apps/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class User(AbstractBaseUser):
help_text=_('Required. 30 characters or fewer. Letters, numbers and '
'@/./+/-/_ characters'),
validators=[
RegexValidator(re.compile('^[\w.@+-]+$'),
RegexValidator(re.compile(r'^[\w.@+-]+$'),
_('Enter a valid username.'),
'invalid')
],
Expand Down Expand Up @@ -145,7 +145,7 @@ def is_meta(self):
@cached_property
def email_hash(self):
try:
return md5(self.email).hexdigest()
return md5(self.email.encode('utf-8')).hexdigest()
except UnicodeEncodeError:
return None

Expand Down Expand Up @@ -236,7 +236,7 @@ def top_scorers(cls, days=30, language=None, project=None, limit=5,
),
).order_by('-total_score')[offset:]

if isinstance(limit, (int, long)) and limit > 0:
if isinstance(limit, int) and limit > 0:
top_scores = top_scores[:limit]

users = dict(
Expand All @@ -255,7 +255,7 @@ def top_scorers(cls, days=30, language=None, project=None, limit=5,
cache.set(cache_key, top_scorers, 60)
return top_scorers

def __unicode__(self):
def __str__(self):
return self.username

def save(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pootle/apps/accounts/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def display_name(self):

@property
def email_hash(self):
return md5(self.email).hexdigest()
return md5(self.email.encode('utf-8')).hexdigest()

def get_absolute_url(self):
return reverse(
Expand Down
4 changes: 2 additions & 2 deletions pootle/apps/accounts/social_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def authentication_error(self, request, provider_id, error=None,
exception=None, extra_context=None):
provider = providers.registry.by_id(provider_id)
retry_url = provider.get_login_url(request,
**dict(request.GET.iteritems()))
**dict(iter(request.GET.items())))

tb = traceback.format_exc()
log_exception(request, exception, tb)
Expand All @@ -82,7 +82,7 @@ def authentication_error(self, request, provider_id, error=None,
'error': error,
'exception': {
'name': exception.__class__.__name__,
'msg': unicode(exception),
'msg': str(exception),
},
'provider': provider.name,
'retry_url': retry_url,
Expand Down
4 changes: 2 additions & 2 deletions pootle/apps/pootle_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# AUTHORS file for copyright and authorship information.

import re
import urlparse
import urllib.parse
from collections import OrderedDict

from django import forms
Expand Down Expand Up @@ -79,7 +79,7 @@ def clean_linkedin(self):
if url is None or url == '':
return None

parsed = urlparse.urlparse(url)
parsed = urllib.parse.urlparse(url)
if (not parsed.netloc.endswith('linkedin.com') or
(not parsed.path.startswith('/in/') or len(parsed.path) < 5)):
raise forms.ValidationError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def get_unit_data(self, unit):

email_md5 = None
if unit['submitted_by__email']:
email_md5 = md5(unit['submitted_by__email']).hexdigest()
email_md5 = md5(
unit['submitted_by__email'].encode('utf-8')
).hexdigest()

mtime = None
if unit['submitted_on']:
Expand Down
4 changes: 2 additions & 2 deletions pootle/apps/pootle_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('directory', models.ForeignKey(related_name='permission_sets', to='pootle_app.Directory')),
('negative_permissions', models.ManyToManyField(related_name='permission_sets_negative', to=b'auth.Permission', db_index=True)),
('positive_permissions', models.ManyToManyField(related_name='permission_sets_positive', to=b'auth.Permission', db_index=True)),
('negative_permissions', models.ManyToManyField(related_name='permission_sets_negative', to='auth.Permission', db_index=True)),
('positive_permissions', models.ManyToManyField(related_name='permission_sets_positive', to='auth.Permission', db_index=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='directory',
name='pootle_path',
field=models.CharField(default=b'/', unique=True, max_length=255, db_index=True),
field=models.CharField(default='/', unique=True, max_length=255, db_index=True),
),
]
4 changes: 2 additions & 2 deletions pootle/apps/pootle_app/models/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def translation_project(self):

# # # # # # # # # # # # # # Methods # # # # # # # # # # # # # # # # # # #

def __unicode__(self):
def __str__(self):
return self.pootle_path

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -221,7 +221,7 @@ def trail(self):
parents = []
start = 1

for i in xrange(start, len(path_parts)):
for i in range(start, len(path_parts)):
path = '/'.join(path_parts[:i]) + '/'
parents.append(path)

Expand Down
12 changes: 8 additions & 4 deletions pootle/apps/pootle_app/models/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_pootle_permission(codename):

def get_permissions_by_username(username, directory):
pootle_path = directory.pootle_path
path_parts = filter(None, pootle_path.split('/'))
path_parts = [_f for _f in pootle_path.split('/') if _f]
key = iri_to_uri('Permissions:%s' % username)
permissions_cache = cache.get(key, {})

Expand All @@ -45,8 +45,12 @@ def get_permissions_by_username(username, directory):
permissionset = None

if (len(path_parts) > 1 and path_parts[0] != 'projects' and
(permissionset is None or
len(filter(None, permissionset.directory.pootle_path.split('/'))) < 2)):
(permissionset is None or
len([
_f
for _f in permissionset.directory.pootle_path.split('/')
if _f
]) < 2)):
# Active permission at language level or higher, check project
# level permission
try:
Expand Down Expand Up @@ -135,7 +139,7 @@ class Meta(object):
negative_permissions = models.ManyToManyField(
Permission, db_index=True, related_name='permission_sets_negative')

def __unicode__(self):
def __str__(self):
return "%s : %s" % (self.user.username,
self.directory.pootle_path)

Expand Down
2 changes: 1 addition & 1 deletion pootle/apps/pootle_app/project_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def translation_project_dir_exists(language, project):
"""
# find directory with the language name in the project dir
try:
dirpath_, dirnames, filename = os.walk(project.get_real_path()).next()
dirpath_, dirnames, filename = next(os.walk(project.get_real_path()))
if language.code in dirnames:
return True
except StopIteration:
Expand Down
2 changes: 1 addition & 1 deletion pootle/apps/pootle_app/views/admin/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from rq.registry import FailedJobRegistry

from django.shortcuts import render
from django.utils.translation import ugettext as _, ungettext

from django_rq.queues import get_queue
from django_rq.workers import Worker

from pootle.core.decorators import admin_required
from pootle.i18n.gettext import ugettext as _, ungettext


def rq_stats():
Expand Down
4 changes: 2 additions & 2 deletions pootle/apps/pootle_app/views/admin/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from django import forms
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext as _

from pootle.i18n.gettext import ugettext as _
from pootle_app.models import Directory
from pootle_app.models.permissions import (PermissionSet,
get_permission_contenttype)
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self, *args, **kwargs):
if language is not None:
del self.fields['negative_permissions']

link = lambda instance: unicode(instance.user)
link = lambda instance: str(instance.user)
directory_permissions = current_directory.permission_sets \
.order_by('user').all()

Expand Down
2 changes: 1 addition & 1 deletion pootle/apps/pootle_app/views/admin/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProjectAdminView(SuperuserRequiredMixin, TemplateView):

def get_context_data(self, **kwargs):
languages = Language.objects.all()
language_choices = [(lang.id, unicode(lang)) for lang in languages]
language_choices = [(lang.id, str(lang)) for lang in languages]
try:
english = Language.objects.get(code='en')
default_language = english.id
Expand Down
6 changes: 3 additions & 3 deletions pootle/apps/pootle_app/views/admin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from django.forms.utils import ErrorList
from django.shortcuts import render
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _

from pootle.core.paginator import paginate
from pootle.i18n.gettext import ugettext as _


def form_set_as_table(formset, link=None, linkfield='code'):
Expand Down Expand Up @@ -42,7 +42,7 @@ def add_header(result, fields, form):
result.append(form[field].as_widget())
result.append(form[field].label_tag())
elif form.fields[field].label is not None and not widget.is_hidden:
result.append(unicode(form.fields[field].label))
result.append(str(form.fields[field].label))

result.append('</th>\n')
result.append('</tr>\n')
Expand All @@ -54,7 +54,7 @@ def add_footer(result, fields, form):
result.append('<td>')

if field_obj.label is not None and not field_obj.widget.is_hidden:
result.append(unicode(field_obj.label))
result.append(str(field_obj.label))

result.append('</td>\n')
result.append('</tr>\n')
Expand Down
14 changes: 8 additions & 6 deletions pootle/apps/pootle_language/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import locale
from collections import OrderedDict
from operator import itemgetter

from django.core.cache import cache
from django.db import models
Expand Down Expand Up @@ -65,10 +66,11 @@ def cached_dict(self, locale_code='en-us', show_all=False):
if languages is None:
qs = self.get_all_queryset() if show_all else self.get_queryset()
languages = OrderedDict(
sorted([(lang[0], tr_lang(lang[1]))
for lang in qs.values_list('code', 'fullname')],
cmp=locale.strcoll,
key=lambda x: x[1])
sorted(
[(locale.strxfrm(lang[0]), tr_lang(lang[1]))
for lang in qs.values_list('code', 'fullname')],
key=itemgetter(0)
)
)
cache.set(key, languages, CACHE_TIMEOUT)

Expand Down Expand Up @@ -161,8 +163,8 @@ def get_canonical(cls, language_code):
except cls.DoesNotExist:
return None

def __unicode__(self):
return u"%s - %s" % (self.name, self.code)
def __str__(self):
return "%s - %s" % (self.name, self.code)

def __init__(self, *args, **kwargs):
super(Language, self).__init__(*args, **kwargs)
Expand Down
Loading