Skip to content

Commit

Permalink
SIO-1565 Fix most pylint comments throughtout whole oioioi
Browse files Browse the repository at this point in the history
Change-Id: I54a63453d9f48fa47addfca708d910af03df62d4
  • Loading branch information
mdebski committed Oct 4, 2014
1 parent 445c355 commit 990b174
Show file tree
Hide file tree
Showing 36 changed files with 88 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ignore=migrations
# R0904 = Too many public methods
# R0911 = Too many return statements
# R0912 = Too many branches
# R0913 = Too many arguments
# R0915 = Too many statements
# R0921 = Abstract class not referenced
# R0922 = Abstract class is only referenced %s times
Expand All @@ -47,12 +48,11 @@ ignore=migrations

# similarities = similar code fragments

disable=F0401, E1002,E1101,E1120,E1121,E1123, W0142,W0212,W0232,W0613,W0622,W0614, R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0915,R0921,R0922, C0103,C0111,C0302,C0330, I0011,I0013, similarities
disable=F0401, E1002,E1101,E1120,E1121,E1123, W0142,W0212,W0232,W0613,W0622,W0614, R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0915,R0921,R0922, C0103,C0111,C0302,C0330, I0011,I0013, similarities

[REPORTS]

output-format=colorized
symbols=no
files-output=no
reports=no
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
Expand Down
2 changes: 0 additions & 2 deletions oioioi/base/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import re

from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User
Expand Down
28 changes: 14 additions & 14 deletions oioioi/base/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,15 +953,15 @@ def setUp(self):
def test_message(self):
url_index = reverse('index')

for login in self.invalid_logins:
self.user.username = login
for l in self.invalid_logins:
self.user.username = l
self.user.save()

response = self.client.get(url_index, follow=True)
self.assertIn('contains not allowed characters', response.content)

for login in self.valid_logins:
self.user.username = login
for l in self.valid_logins:
self.user.username = l
self.user.save()

response = self.client.get(url_index, follow=True)
Expand All @@ -972,18 +972,18 @@ def test_login_change(self):
url_index = reverse('index')
url_edit_profile = reverse('edit_profile')

for login in self.invalid_logins:
self.user.username = login
for l in self.invalid_logins:
self.user.username = l
self.user.save()

response = self.client.get(url_edit_profile)
self.assertIn('<input id="id_username" maxlength="30" name='
'"username" type="text" value="%s" />' % (login,),
'"username" type="text" value="%s" />' % l,
response.content)

self.client.post(url_edit_profile, {'username': 'valid_user'},
follow=True)
self.assertEqual(self.user.username, login)
self.assertEqual(self.user.username, l)

response = self.client.post(url_index, follow=True)
self.assertNotIn('contains not allowed characters',
Expand All @@ -994,18 +994,18 @@ def test_login_change(self):
'"username" readonly="True" type="text"'
' value="valid_user" />', response.content)

for login in self.valid_logins:
self.user.username = login
for l in self.valid_logins:
self.user.username = l
self.user.save()

response = self.client.get(url_edit_profile)
self.assertIn('<input id="id_username" maxlength="30" name='
'"username" readonly="True" type="text" value="%s" />'
% (login,), response.content)
% l, response.content)

response = self.client.post(url_edit_profile,
{'username': 'valid_user'}, follow=True)
self.assertEqual(self.user.username, login)
self.assertEqual(self.user.username, l)
self.assertIn('You cannot change your username.', response.content)

response = self.client.get(url_index, follow=True)
Expand All @@ -1021,8 +1021,8 @@ def test_failed_login_change(self):
self.user.username = self.invalid_logins[0]
self.user.save()

for login in self.invalid_logins:
self.client.post(url_edit_profile, {'username': login},
for l in self.invalid_logins:
self.client.post(url_edit_profile, {'username': l},
follow=True)
self.assertEqual(self.user.username, self.invalid_logins[0])

Expand Down
1 change: 1 addition & 0 deletions oioioi/base/utils/cache_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, cache_key, cache_group):
self.cache_key = cache_key
self.cache_group = cache_group
self.name = self.get_instance_name(cache_key, cache_group)
self.lock = None

self._in_context = 0

Expand Down
3 changes: 1 addition & 2 deletions oioioi/base/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# pylint: disable=W0703
# Catching too general exception Exception
import re

from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.exceptions import PermissionDenied
Expand All @@ -12,10 +11,10 @@
from django.views.defaults import page_not_found
from django.utils.translation import ugettext, ugettext_lazy as _
from django.views.decorators.http import require_POST, require_GET
from django.core.exceptions import SuspiciousOperation
from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib.auth.views import logout as auth_logout, \
login as auth_login
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.vary import vary_on_headers, vary_on_cookie
from django.views.decorators.cache import cache_control
from oioioi.base.permissions import enforce_condition, not_anonymous
Expand Down
4 changes: 2 additions & 2 deletions oioioi/contests/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
RoundTimeExtension
from oioioi.contests.scores import ScoreValue
from oioioi.contests.utils import visible_problem_instances, rounds_times, \
is_contest_admin, is_contest_observer, can_see_personal_data, \
last_break_between_rounds, has_any_active_round
is_contest_admin, is_contest_observer, last_break_between_rounds, \
has_any_active_round
from oioioi import evalmgr


Expand Down
1 change: 1 addition & 0 deletions oioioi/contests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(self, request, *args, **kwargs):
pis = problem_filter(pis)
pi_choices = [(pi.id, unicode(pi)) for pi in pis]

# pylint: disable=non-parent-init-called
# init form with previously sent data
forms.Form.__init__(self, *args, **kwargs)

Expand Down
4 changes: 2 additions & 2 deletions oioioi/contests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ class Meta(object):
def contest_links_generator(request):
links = ContestLink.objects.filter(contest=request.contest)
for link in links:
# pylint: disable=cell-var-from-loop
# http://docs.python-guide.org/en/latest/writing/gotchas/#late-binding-closures
def url_generator(request, url=link.url):
return url
url_generator = lambda request, url=link.url: url
item = MenuItem(
name='contest_link_%d' % link.id,
text=link.description,
Expand Down
2 changes: 1 addition & 1 deletion oioioi/contests/templatetags/get_user_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _get_name(parser, token, tag_name):
bits = token.split_contents()
if (len(bits) != 4 or bits[2] != 'as') and (len(bits) != 2):
raise TemplateSyntaxError("The tag should look like this: "
"{% %s <user_object>[ as <variable>] %}" % tag_name)
"{%% %s <user_object>[ as <variable>] %%}" % tag_name)
asvar = None
if len(bits) == 4:
asvar = bits[3]
Expand Down
2 changes: 1 addition & 1 deletion oioioi/contests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def user_info_view(request, contest_id, user_id):
if not request.user.is_superuser and (not user in rcontroller
.filter_users_with_accessible_personal_data(User.objects.all())
or user.is_superuser):
raise PermissionDenied
raise PermissionDenied

infolist = sorted(
controller.get_contest_participant_info_list(request, user) +
Expand Down
2 changes: 2 additions & 0 deletions oioioi/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@

BROKER_URL = 'django://'

# pylint: disable=undefined-variable

CELERY_IMPORTS += [
'oioioi.evalmgr',
'oioioi.problems.unpackmgr',
Expand Down
1 change: 1 addition & 0 deletions oioioi/evalmgr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def handler_fun(``env``, ``\*\*kwargs``):
Returns environment (a processed copy of given environment).
"""

# pylint: disable=global-statement
global loaded_controllers

# load controllers to avoid late mix-ins to them
Expand Down
3 changes: 2 additions & 1 deletion oioioi/notifications/management/commands/notify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import string
from optparse import make_option

from django.contrib.auth.models import User
from django.core.management.base import BaseCommand, CommandError

from oioioi.base.notification import NotificationHandler
from oioioi.contests.models import Contest

Expand Down
3 changes: 2 additions & 1 deletion oioioi/notifications/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def notification_processor(request):
return {}

def generator():
notifications_session_id = get_notifications_session(request.session).uid
notifications_session_id = get_notifications_session(
request.session).uid
return render_to_string('notifications/notifications.html',
dict(notif_server_url=
settings.NOTIFICATIONS_SERVER_URL,
Expand Down
1 change: 1 addition & 0 deletions oioioi/oi/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def registration_view(self, request):
participant = self._get_participant_for_form(request)

if 'oi_oiregistrationformdata' in request.session:
# pylint: disable=not-callable
form = self.form_class(request.session[
'oi_oiregistrationformdata'])
del request.session['oi_oiregistrationformdata']
Expand Down
3 changes: 0 additions & 3 deletions oioioi/oi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,14 +720,11 @@ def test_user_info_page(self):
('test_personal_data_user', True)]

for (username, can_see) in can_see_list:
print("Testing " + username)
print()
self.client.login(username=username)
response = self.client.get(url)
self.client.logout()

for k in reg_data:
print(reg_data[k])
if can_see:
self.assertIn(reg_data[k], response.content)
else:
Expand Down
1 change: 1 addition & 0 deletions oioioi/pa/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def registration_view(self, request):
participant = self._get_participant_for_form(request)

if 'pa_paregistrationformdata' in request.session:
# pylint: disable=not-callable
form = self.form_class(request.session[
'pa_paregistrationformdata'])
del request.session['pa_paregistrationformdata']
Expand Down
3 changes: 2 additions & 1 deletion oioioi/participants/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ def contribute_to_class(self, cls, name):
arg,
rule
)],
[r'^oioioi\.participants\.fields\.OneToOneBothHandsCascadingParticipantField']
[r'^oioioi\.participants\.fields\.'
'OneToOneBothHandsCascadingParticipantField']
)
2 changes: 1 addition & 1 deletion oioioi/participants/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def register(user):
kwargs={'contest_id': contest.id})
self.client.login(username=user.username)

response = self.client.get(reg_url)
self.client.get(reg_url)
reg_data = {
'address': 'The Castle',
'postal_code': '31-337',
Expand Down
3 changes: 2 additions & 1 deletion oioioi/participants/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
url(r'^register/$', 'registration_view', name='participants_register'),
url(r'^unregister/$', 'unregistration_view',
name='participants_unregister'),
url(r'^participants_data/$', 'participants_data', name='participants_data'),
url(r'^participants_data/$', 'participants_data',
name='participants_data'),
url(r'^participants_data_csv/$', 'participants_data_csv',
name='participants_data_csv'),
)
Expand Down
9 changes: 5 additions & 4 deletions oioioi/participants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def _fold_registration_models_tree(object):
current = objs.pop(0)
objects_used.append(current)
for field in current._meta.fields:
if field.rel is not None and \
getattr(current, field.name) not in objects_used:
objs.append(getattr(current, field.name))
if field.rel is not None and \
getattr(current, field.name) not in objects_used:
objs.append(getattr(current, field.name))

for obj in objects_used:
for field in obj._meta.fields:
Expand Down Expand Up @@ -116,7 +116,8 @@ def key_value((obj, field)):

data = []
for participant in participants:
values = dict(map(key_value, _fold_registration_models_tree(participant)))
values = dict(map(key_value,
_fold_registration_models_tree(participant)))
values['username'] = participant.user.username
values['first name'] = participant.user.first_name
values['last name'] = participant.user.last_name
Expand Down
39 changes: 19 additions & 20 deletions oioioi/programs/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
from django.contrib.auth.models import User

from oioioi.contests.utils import is_contest_admin, is_contest_observer
Expand All @@ -23,7 +22,7 @@
from oioioi.contests.models import SubmissionReport, ScoreReport
from oioioi.programs.models import ProgramSubmission, OutputChecker, \
CompilationReport, TestReport, GroupReport, ModelProgramSubmission, \
Submission, ReportActionsConfig, UserOutGenStatus
Submission, UserOutGenStatus
from oioioi.programs.utils import has_report_actions_config
from oioioi.filetracker.utils import django_to_filetracker_path
from oioioi.evalmgr import recipe_placeholder, add_before_placeholder, \
Expand Down Expand Up @@ -508,12 +507,12 @@ def can_generate_user_out(self, request, submission_report):
return False
config = submission.problem_instance.problem.report_actions_config

return config.can_user_generate_outs and \
submission.user == request.user and \
self.can_see_problem(request, submission.problem_instance) and \
return (config.can_user_generate_outs and
submission.user == request.user and
self.can_see_problem(request, submission.problem_instance) and
self.filter_visible_reports(request, submission,
SubmissionReport.objects.filter(id=submission_report.id)) \
.exists()
SubmissionReport.objects.filter(id=submission_report.id))
.exists())

def can_see_source(self, request, submission):
"""Determines if the current user is allowed to see source
Expand Down Expand Up @@ -548,19 +547,19 @@ def render_submission(self, request, submission):
self.get_supported_extra_args(submission)}))

def _out_generate_status(self, request, testreport):
try:
if is_contest_admin(request) or \
testreport.userout_status.visible_for_user:
# making sure, that output really exists or is processing
if bool(testreport.output_file) or \
testreport.userout_status.status == '?':
return testreport.userout_status.status

except UserOutGenStatus.DoesNotExist:
if bool(testreport.output_file):
return 'OK'

return None
try:
if is_contest_admin(request) or \
testreport.userout_status.visible_for_user:
# making sure, that output really exists or is processing
if bool(testreport.output_file) or \
testreport.userout_status.status == '?':
return testreport.userout_status.status

except UserOutGenStatus.DoesNotExist:
if testreport.output_file:
return 'OK'

return None

def render_report(self, request, report):
if report.kind == 'FAILURE':
Expand Down
6 changes: 3 additions & 3 deletions oioioi/programs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ def fill_outfile_in_existing_test_reports(env, **kwargs):
test_name)
continue

if bool(testreport.output_file):
logger.warn('Output for test report %s exists. Deleting old one.'
% (testreport.id))
if testreport.output_file:
logger.warn('Output for test report %s exists. Deleting old one.',
testreport.id)
get_client().delete_file(testreport.output_file)

testreport.output_file = filetracker_to_django_file(result['out_file'])
Expand Down
1 change: 0 additions & 1 deletion oioioi/programs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.utils.translation import ugettext_lazy as _
from django.dispatch import receiver
from django.db.models.signals import pre_save, post_save
from django.contrib.auth.models import User
from oioioi.base.fields import EnumRegistry, EnumField
from oioioi.problems.models import Problem, make_problem_filename
from oioioi.filetracker.fields import FileField
Expand Down
Loading

0 comments on commit 990b174

Please sign in to comment.