From d9a8b7e89fd345508fc05328324682b928a400ef Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 28 Oct 2018 15:40:39 -0500 Subject: [PATCH] Placate flake8 3.6 --- course/auth.py | 7 +- course/content.py | 2 +- course/enrollment.py | 6 +- course/exam.py | 36 +++-- course/grades.py | 25 ++-- course/models.py | 7 +- course/page/choice.py | 18 +-- course/page/code.py | 9 +- course/page/code_feedback.py | 2 +- course/page/text.py | 15 +- course/sandbox.py | 3 +- course/utils.py | 12 +- course/validation.py | 14 +- course/versioning.py | 9 +- relate/checks.py | 12 +- relate/urls.py | 248 ++++++++++++++++---------------- tests/test_auth.py | 2 +- tests/test_content.py | 2 +- tests/test_pages/test_base.py | 8 +- tests/test_pages/test_inline.py | 10 +- tests/test_pages/test_text.py | 10 +- 21 files changed, 218 insertions(+), 239 deletions(-) diff --git a/course/auth.py b/course/auth.py index c228db9d..1ab1ae74 100644 --- a/course/auth.py +++ b/course/auth.py @@ -114,8 +114,7 @@ def get_impersonable_user_qset(impersonator): # only when rendering ImpersonateForm impersonable_user_qset = ( impersonable_user_qset - | - User.objects.filter(pk__in=q.values_list("user__pk", flat=True)) + | User.objects.filter(pk__in=q.values_list("user__pk", flat=True)) ) return impersonable_user_qset @@ -1016,8 +1015,8 @@ def user_profile(request): "form_description": _("User Profile"), "is_requesting_inst_id": is_requesting_inst_id(), "enable_profile_form_js": ( - not is_inst_id_locked(request.user) and - getattr(settings, "RELATE_SHOW_INST_ID_FORM", True)) + not is_inst_id_locked(request.user) + and getattr(settings, "RELATE_SHOW_INST_ID_FORM", True)) }) # }}} diff --git a/course/content.py b/course/content.py index 13e7f080..39accd6e 100644 --- a/course/content.py +++ b/course/content.py @@ -583,7 +583,7 @@ def get_raw_yaml_from_repo(repo, full_name, commit_sha): return result -LINE_HAS_INDENTING_TABS_RE = re.compile("^\s*\t\s*", re.MULTILINE) +LINE_HAS_INDENTING_TABS_RE = re.compile(r"^\s*\t\s*", re.MULTILINE) def get_yaml_from_repo(repo, full_name, commit_sha, cached=True): diff --git a/course/enrollment.py b/course/enrollment.py index 54642986..abd43b14 100644 --- a/course/enrollment.py +++ b/course/enrollment.py @@ -840,9 +840,9 @@ class ParticipationQueryForm(StyledForm): @transaction.atomic @course_view def query_participations(pctx): - if (not pctx.has_permission(pperm.query_participation) - or - pctx.has_permission(pperm.view_participant_masked_profile)): + if ( + not pctx.has_permission(pperm.query_participation) + or pctx.has_permission(pperm.view_participant_masked_profile)): raise PermissionDenied(_("may not query participations")) request = pctx.request diff --git a/course/exam.py b/course/exam.py index 4fa9cefc..328d63c8 100644 --- a/course/exam.py +++ b/course/exam.py @@ -471,8 +471,7 @@ def check_exam_ticket( return (False, _("Exam has not started yet.")) if ( ticket.exam.no_exams_after is not None - and - ticket.exam.no_exams_after <= now_datetime): + and ticket.exam.no_exams_after <= now_datetime): return (False, _("Exam has ended.")) if (ticket.restrict_to_facility @@ -484,13 +483,11 @@ def check_exam_ticket( % ticket.restrict_to_facility) if ( ticket.valid_start_time is not None - and - now_datetime < ticket.valid_start_time): + and now_datetime < ticket.valid_start_time): return (False, _("Exam ticket is not yet valid.")) if ( ticket.valid_end_time is not None - and - ticket.valid_end_time < now_datetime): + and ticket.valid_end_time < now_datetime): return (False, _("Exam ticket has expired.")) return True, _("Ticket is valid.") @@ -636,8 +633,10 @@ class ExamFacilityMiddleware(object): if not exams_only: return self.get_response(request) - if (exams_only and - "relate_session_locked_to_exam_flow_session_pk" in request.session): + if (exams_only + and ( + "relate_session_locked_to_exam_flow_session_pk" + in request.session)): # ExamLockdownMiddleware is in control. return self.get_response(request) @@ -676,10 +675,8 @@ class ExamFacilityMiddleware(object): elif ( (request.user.is_staff - or - request.user.has_perm("course.can_issue_exam_tickets")) - and - resolver_match.func == issue_exam_ticket): + or request.user.has_perm("course.can_issue_exam_tickets")) + and resolver_match.func == issue_exam_ticket): ok = True if not ok: @@ -760,16 +757,16 @@ class ExamLockdownMiddleware(object): update_expiration_mode, update_page_bookmark_state, finish_flow_session_view] - and - int(resolver_match.kwargs["flow_session_id"]) - == exam_flow_session_pk): + and ( + int(resolver_match.kwargs["flow_session_id"]) + == exam_flow_session_pk)): ok = True elif ( resolver_match.func == view_start_flow - and - resolver_match.kwargs["flow_id"] - == exam_flow_session.flow_id): + and ( + resolver_match.kwargs["flow_id"] + == exam_flow_session.flow_id)): ok = True if not ok: @@ -810,8 +807,7 @@ def list_available_exams(request): no_exams_before__lt=now_datetime) .filter( Q(no_exams_after__isnull=True) - | - Q(no_exams_after__gt=now_datetime)) + | Q(no_exams_after__gt=now_datetime)) .order_by("no_exams_before", "course__number")) return render(request, "course/list-exams.html", { diff --git a/course/grades.py b/course/grades.py index 97338b0a..3f6040b6 100644 --- a/course/grades.py +++ b/course/grades.py @@ -591,17 +591,22 @@ def view_grades_by_opportunity(pctx, opp_id): flow_session=None))) else: while ( - fsess_idx < len(flow_sessions) and ( - flow_sessions[fsess_idx].participation is None or - flow_sessions[fsess_idx].participation.pk < participation.pk)): + fsess_idx < len(flow_sessions) + and ( + flow_sessions[fsess_idx].participation is None + or ( + flow_sessions[fsess_idx].participation.pk + < participation.pk))): fsess_idx += 1 my_flow_sessions = [] while ( - fsess_idx < len(flow_sessions) and - flow_sessions[fsess_idx].participation is not None and - flow_sessions[fsess_idx].participation.pk == participation.pk): + fsess_idx < len(flow_sessions) + and flow_sessions[fsess_idx].participation is not None + and ( + flow_sessions[fsess_idx].participation.pk + == participation.pk)): my_flow_sessions.append(flow_sessions[fsess_idx]) fsess_idx += 1 @@ -1020,13 +1025,13 @@ def view_single_grade(pctx, participation_id, opportunity_id): # {{{ filter out pre-public grade changes - if (not show_privileged_info and - opportunity.hide_superseded_grade_history_before is not None): + if (not show_privileged_info + and opportunity.hide_superseded_grade_history_before is not None): grade_changes = [gchange for gchange in grade_changes if not gchange.is_superseded - or gchange.grade_time >= - opportunity.hide_superseded_grade_history_before] + or gchange.grade_time + >= opportunity.hide_superseded_grade_history_before] # }}} diff --git a/course/models.py b/course/models.py index 9f7f7840..1c8caf8c 100644 --- a/course/models.py +++ b/course/models.py @@ -587,8 +587,7 @@ class Participation(models.Model): role__course=self.course, role__participation=self) .values_list("permission", "argument")) - + - list( + + list( ParticipationPermission.objects.filter( participation=self) .values_list("permission", "argument"))) @@ -1716,8 +1715,8 @@ class GradeStateMachine(object): self.state = gchange.state if gchange.attempt_id is not None: - if (set_is_superseded and - gchange.attempt_id in self.attempt_id_to_gchange): + if (set_is_superseded + and gchange.attempt_id in self.attempt_id_to_gchange): self.attempt_id_to_gchange[gchange.attempt_id] \ .is_superseded = True self.attempt_id_to_gchange[gchange.attempt_id] \ diff --git a/course/page/choice.py b/course/page/choice.py index 3a10623c..8925c737 100644 --- a/course/page/choice.py +++ b/course/page/choice.py @@ -505,8 +505,7 @@ class MultipleChoiceQuestion(ChoiceQuestionBase): if ( hasattr(pd, "allow_partial_credit") - or - hasattr(pd, "allow_partial_credit_subset_only")): + or hasattr(pd, "allow_partial_credit_subset_only")): raise ValidationError( string_concat( "%(location)s: ", @@ -617,11 +616,9 @@ class MultipleChoiceQuestion(ChoiceQuestionBase): correctness = ( ( num_choices - - - len(unpermed_idx_set + - len(unpermed_idx_set .symmetric_difference(correct_idx_set))) - / - num_choices) + / num_choices) else: assert self.credit_mode == "proportional_correct" @@ -629,13 +626,10 @@ class MultipleChoiceQuestion(ChoiceQuestionBase): correctness = ( ( len(unpermed_idx_set & correct_idx_set) - + - len(always_correct_idx_set)) - / - ( + + len(always_correct_idx_set)) + / ( len(correct_idx_set) - + - len(always_correct_idx_set))) + + len(always_correct_idx_set))) if not (unpermed_idx_set <= correct_idx_set): correctness = 0 diff --git a/course/page/code.py b/course/page/code.py index 777d33ea..cf4013f4 100644 --- a/course/page/code.py +++ b/course/page/code.py @@ -701,8 +701,7 @@ class PythonCodeQuestion(PageBaseWithTitle, PageBaseWithValue): if ( not page_context.in_sandbox - and - not is_nuisance_failure(response_dict)): + and not is_nuisance_failure(response_dict)): try: from django.core.mail import EmailMessage msg = EmailMessage("".join(["[%s:%s] ", @@ -1034,9 +1033,9 @@ class PythonCodeQuestionWithHumanTextFeedback( vctx, location, page_desc) if vctx is not None: - if (hasattr(self.page_desc, "human_feedback_value") - and - hasattr(self.page_desc, "human_feedback_percentage")): + if ( + hasattr(self.page_desc, "human_feedback_value") + and hasattr(self.page_desc, "human_feedback_percentage")): raise ValidationError( string_concat( "%(location)s: ", diff --git a/course/page/code_feedback.py b/course/page/code_feedback.py index 3e5d65d8..416d7b5f 100644 --- a/course/page/code_feedback.py +++ b/course/page/code_feedback.py @@ -169,7 +169,7 @@ class Feedback: def call_user(self, f, *args, **kwargs): try: return f(*args, **kwargs) - except Exception as e: + except Exception: if callable(f): try: callable_name = f.__name__ diff --git a/course/page/text.py b/course/page/text.py index 95f900c5..1a682360 100644 --- a/course/page/text.py +++ b/course/page/text.py @@ -253,8 +253,7 @@ class CaseSensitivePlainMatcher(TextAnswerMatcher): def grade(self, s): return int( multiple_to_single_spaces(self.pattern) - == - multiple_to_single_spaces(s)) + == multiple_to_single_spaces(s)) def correct_answer_text(self): return self.pattern @@ -268,8 +267,7 @@ class PlainMatcher(CaseSensitivePlainMatcher): def grade(self, s): return int( multiple_to_single_spaces(self.pattern.lower()) - == - multiple_to_single_spaces(s.lower())) + == multiple_to_single_spaces(s.lower())) class RegexMatcher(TextAnswerMatcher): @@ -480,12 +478,9 @@ class FloatMatcher(TextAnswerMatcher): if ( not matcher_desc.value == 0 - and - not hasattr(matcher_desc, "atol") - and - not hasattr(matcher_desc, "rtol") - and - vctx is not None): + and not hasattr(matcher_desc, "atol") + and not hasattr(matcher_desc, "rtol") + and vctx is not None): vctx.add_warning(location, _("Float match should have either rtol or atol--" "otherwise it will match any number")) diff --git a/course/sandbox.py b/course/sandbox.py index 8a76be36..134de6f3 100644 --- a/course/sandbox.py +++ b/course/sandbox.py @@ -169,8 +169,7 @@ def get_sandbox_data_for_page(pctx, page_desc, key): if ( stored_data_page_type == page_desc.type - and - stored_data_page_id == page_desc.id): + and stored_data_page_id == page_desc.id): return stored_data return None diff --git a/course/utils.py b/course/utils.py index 38532f81..837af3db 100644 --- a/course/utils.py +++ b/course/utils.py @@ -230,13 +230,13 @@ def _eval_participation_tags_conditions( ptag_set = set(participation.tags.all().values_list("name", flat=True)) if not ptag_set: return False - if (participation_tags_any_set - and - not participation_tags_any_set & ptag_set): + if ( + participation_tags_any_set + and not participation_tags_any_set & ptag_set): return False - if (participation_tags_all_set - and - not participation_tags_all_set <= ptag_set): + if ( + participation_tags_all_set + and not participation_tags_all_set <= ptag_set): return False return True diff --git a/course/validation.py b/course/validation.py index df9d585f..c0a64634 100644 --- a/course/validation.py +++ b/course/validation.py @@ -419,8 +419,7 @@ def validate_staticpage_desc(vctx, location, page_desc): if ( (not hasattr(page_desc, "chunks") and not hasattr(page_desc, "content")) - or - (hasattr(page_desc, "chunks") and hasattr(page_desc, "content"))): + or (hasattr(page_desc, "chunks") and hasattr(page_desc, "content"))): raise ValidationError( string_concat("%(location)s: ", _("must have either 'chunks' or 'content'")) @@ -960,9 +959,8 @@ def validate_flow_rules(vctx, location, rules): from course.constants import GRADE_AGGREGATION_STRATEGY_CHOICES if ( hasattr(rules, "grade_aggregation_strategy") - and - rules.grade_aggregation_strategy not in - dict(GRADE_AGGREGATION_STRATEGY_CHOICES)): + and rules.grade_aggregation_strategy + not in dict(GRADE_AGGREGATION_STRATEGY_CHOICES)): raise ValidationError( string_concat("%s: ", _("invalid grade aggregation strategy"), @@ -1064,8 +1062,7 @@ def validate_flow_desc(vctx, location, flow_desc): if ( (not hasattr(flow_desc, "groups") and not hasattr(flow_desc, "pages")) - or - (hasattr(flow_desc, "groups") and hasattr(flow_desc, "pages"))): + or (hasattr(flow_desc, "groups") and hasattr(flow_desc, "pages"))): raise ValidationError( string_concat("%(location)s: ", _("must have either 'groups' or 'pages'")) @@ -1547,8 +1544,7 @@ def validate_course_content(repo, course_file, events_file, if ( flow_grade_identifier is not None - and - set([flow_grade_identifier]) & used_grade_identifiers): + and set([flow_grade_identifier]) & used_grade_identifiers): raise ValidationError( string_concat("%s: ", _("flow uses the same grade_identifier " diff --git a/course/versioning.py b/course/versioning.py index c28247f8..876387ca 100644 --- a/course/versioning.py +++ b/course/versioning.py @@ -336,8 +336,7 @@ def run_course_update_command( remote_head = remote_refs[b"HEAD"] if ( prevent_discarding_revisions - and - is_parent_commit(repo, repo[remote_head], repo[b"HEAD"], + and is_parent_commit(repo, repo[remote_head], repo[b"HEAD"], max_history_check_size=20)): raise RuntimeError(_("fetch would discard commits, refusing")) @@ -437,8 +436,7 @@ class GitUpdateForm(StyledForm): ref.decode("utf-8", errors="replace"), format_sha(repo_refs[ref]))) for ref in repo_refs - ] + - [ + ] + [ (entry.commit.id.decode(), format_commit(entry.commit)) for entry in commit_iter ]), @@ -491,8 +489,7 @@ def _get_commit_message_as_html(repo, commit_sha): def update_course(pctx): if not ( pctx.has_permission(pperm.update_content) - or - pctx.has_permission(pperm.preview_content)): + or pctx.has_permission(pperm.preview_content)): raise PermissionDenied() course = pctx.course diff --git a/relate/checks.py b/relate/checks.py index 54a6b183..d040c2a1 100644 --- a/relate/checks.py +++ b/relate/checks.py @@ -383,8 +383,8 @@ def check_relate_settings(app_configs, **kwargs): from django.utils.itercompat import is_iterable - if (isinstance(languages, six.string_types) or - not is_iterable(languages)): + if (isinstance(languages, six.string_types) + or not is_iterable(languages)): errors.append(RelateCriticalCheckMessage( msg=(INSTANCE_ERROR_PATTERN % {"location": LANGUAGES, @@ -392,8 +392,8 @@ def check_relate_settings(app_configs, **kwargs): id="relate_languages.E001") ) else: - if any(isinstance(choice, six.string_types) or - not is_iterable(choice) or len(choice) != 2 + if any(isinstance(choice, six.string_types) + or not is_iterable(choice) or len(choice) != 2 for choice in languages): errors.append(RelateCriticalCheckMessage( msg=("'%s' must be an iterable containing " @@ -457,8 +457,8 @@ def check_relate_settings(app_configs, **kwargs): relate_override_templates_dirs = getattr(settings, RELATE_OVERRIDE_TEMPLATES_DIRS, None) if relate_override_templates_dirs is not None: - if (isinstance(relate_override_templates_dirs, six.string_types) or - not is_iterable(relate_override_templates_dirs)): + if (isinstance(relate_override_templates_dirs, six.string_types) + or not is_iterable(relate_override_templates_dirs)): errors.append(RelateCriticalCheckMessage( msg=(INSTANCE_ERROR_PATTERN % {"location": RELATE_OVERRIDE_TEMPLATES_DIRS, diff --git a/relate/urls.py b/relate/urls.py index a369add5..0e084ced 100644 --- a/relate/urls.py +++ b/relate/urls.py @@ -83,8 +83,8 @@ urlpatterns = [ name="relate-user_profile"), url( r"^course" - "/" + COURSE_ID_REGEX + - "/auth-tokens/$", + "/" + COURSE_ID_REGEX + + "/auth-tokens/$", course.auth.manage_authentication_tokens, name="relate-manage_authentication_tokens"), @@ -122,37 +122,37 @@ urlpatterns = [ url(r'^$', course.views.home, name='relate-home'), url(r"^course" - "/" + COURSE_ID_REGEX + - "/$", + "/" + COURSE_ID_REGEX + + "/$", course.views.course_page, name="relate-course_page"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/edit/$", + "/" + COURSE_ID_REGEX + + "/edit/$", course.views.edit_course, name="relate-edit_course"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/page" - "/" + STATICPAGE_PATH_REGEX + - "/$", + "/" + COURSE_ID_REGEX + + "/page" + "/" + STATICPAGE_PATH_REGEX + + "/$", course.views.static_page, name="relate-content_page"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/instant-message/$", + "/" + COURSE_ID_REGEX + + "/instant-message/$", course.im.send_instant_message, name="relate-send_instant_message"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/sandbox/markup/$", + "/" + COURSE_ID_REGEX + + "/sandbox/markup/$", course.sandbox.view_markup_sandbox, name="relate-view_markup_sandbox"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/sandbox/page/$", + "/" + COURSE_ID_REGEX + + "/sandbox/page/$", course.sandbox.view_page_sandbox, name="relate-view_page_sandbox"), @@ -165,55 +165,55 @@ urlpatterns = [ # {{{ grading url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/my/$", + "/" + COURSE_ID_REGEX + + "/grading/my/$", course.grades.view_participant_grades, name="relate-view_participant_grades"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/participant" + "/" + COURSE_ID_REGEX + + "/grading/participant" "/(?P[0-9]+)" "/$", course.grades.view_participant_grades, name="relate-view_participant_grades"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/participants/$", + "/" + COURSE_ID_REGEX + + "/grading/participants/$", course.grades.view_participant_list, name="relate-view_participant_list"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/opportunities/$", + "/" + COURSE_ID_REGEX + + "/grading/opportunities/$", course.grades.view_grading_opportunity_list, name="relate-view_grading_opportunity_list"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/overview/$", + "/" + COURSE_ID_REGEX + + "/grading/overview/$", course.grades.view_gradebook, name="relate-view_gradebook"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/overview/csv/$", + "/" + COURSE_ID_REGEX + + "/grading/overview/csv/$", course.grades.export_gradebook_csv, name="relate-export_gradebook_csv"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/by-opportunity" + "/" + COURSE_ID_REGEX + + "/grading/by-opportunity" "/(?P[0-9]+)" "/$", course.grades.view_grades_by_opportunity, name="relate-view_grades_by_opportunity"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/single-grade" + "/" + COURSE_ID_REGEX + + "/grading/single-grade" "/(?P[0-9]+)" "/(?P[0-9]+)" "/$", course.grades.view_single_grade, name="relate-view_single_grade"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/reopen-session" + "/" + COURSE_ID_REGEX + + "/grading/reopen-session" "/(?P[0-9]+)" "/(?P[0-9]+)" "/$", @@ -221,16 +221,16 @@ urlpatterns = [ name="relate-view_reopen_session"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading" + "/" + COURSE_ID_REGEX + + "/grading" "/csv-import" "/$", course.grades.import_grades, name="relate-import_grades"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading" + "/" + COURSE_ID_REGEX + + "/grading" "/flow-page" "/(?P[0-9]+)" "/(?P[0-9]+)" @@ -239,8 +239,8 @@ urlpatterns = [ name="relate-grade_flow_page"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/prev_grades" + "/" + COURSE_ID_REGEX + + "/prev-grades" "/flow-page" "/(?P[0-9]+)" "/(?P[0-9]+)" @@ -249,24 +249,24 @@ urlpatterns = [ name="relate-get_prev_grades_dropdown_content"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/statistics" - "/" + FLOW_ID_REGEX + - "/$", + "/" + COURSE_ID_REGEX + + "/grading/statistics" + "/" + FLOW_ID_REGEX + + "/$", course.grading.show_grader_statistics, name="relate-show_grader_statistics"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grading/download-submissions" - "/" + FLOW_ID_REGEX + - "/$", + "/" + COURSE_ID_REGEX + + "/grading/download-submissions" + "/" + FLOW_ID_REGEX + + "/$", course.grades.download_all_submissions, name="relate-download_all_submissions"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/edit-grading-opportunity" + "/" + COURSE_ID_REGEX + + "/edit-grading-opportunity" "/(?P[-0-9]+)" "/$", course.grades.edit_grading_opportunity, @@ -277,25 +277,25 @@ urlpatterns = [ # {{{ enrollment url(r"^course" - "/" + COURSE_ID_REGEX + - "/enroll/$", + "/" + COURSE_ID_REGEX + + "/enroll/$", course.enrollment.enroll_view, name="relate-enroll"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/preapprove" + "/" + COURSE_ID_REGEX + + "/preapprove" "/$", course.enrollment.create_preapprovals, name="relate-create_preapprovals"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/query-participations" + "/" + COURSE_ID_REGEX + + "/query-participations" "/$", course.enrollment.query_participations, name="relate-query_participations"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/edit-participation" + "/" + COURSE_ID_REGEX + + "/edit-participation" "/(?P[-0-9]+)" "/$", course.enrollment.edit_participation, @@ -306,22 +306,22 @@ urlpatterns = [ # {{{ media url(r"^course" - "/" + COURSE_ID_REGEX + - "/media/(?P[a-f0-9]+)" + "/" + COURSE_ID_REGEX + + "/media/(?P[a-f0-9]+)" "/(?P.*)$", course.views.get_media, name="relate-get_media"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/file-version/(?P[a-f0-9]+)" + "/" + COURSE_ID_REGEX + + "/file-version/(?P[a-f0-9]+)" "/(?P.*)$", course.views.get_repo_file, name="relate-get_repo_file"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/f" + "/" + COURSE_ID_REGEX + + "/f" "/(?P.*)$", course.views.get_current_repo_file, name="relate-get_current_repo_file"), @@ -331,18 +331,18 @@ urlpatterns = [ # {{{ calendar url(r"^course" - "/" + COURSE_ID_REGEX + - "/create-recurring-events/$", + "/" + COURSE_ID_REGEX + + "/create-recurring-events/$", course.calendar.create_recurring_events, name="relate-create_recurring_events"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/renumber-events/$", + "/" + COURSE_ID_REGEX + + "/renumber-events/$", course.calendar.renumber_events, name="relate-renumber_events"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/calendar/$", + "/" + COURSE_ID_REGEX + + "/calendar/$", course.calendar.view_calendar, name="relate-view_calendar"), @@ -354,8 +354,8 @@ urlpatterns = [ course.versioning.set_up_new_course, name="relate-set_up_new_course"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/update/$", + "/" + COURSE_ID_REGEX + + "/update/$", course.versioning.update_course, name="relate-update_course"), @@ -364,32 +364,32 @@ urlpatterns = [ # {{{ flow-related url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow" - "/" + FLOW_ID_REGEX + - "/start" + "/" + COURSE_ID_REGEX + + "/flow" + "/" + FLOW_ID_REGEX + + "/start" "/$", course.flow.view_start_flow, name="relate-view_start_flow"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-session" + "/" + COURSE_ID_REGEX + + "/flow-session" "/(?P[-0-9]+)" "/resume" "/$", course.flow.view_resume_flow, name="relate-view_resume_flow"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-session" + "/" + COURSE_ID_REGEX + + "/flow-session" "/(?P[0-9]+)" "/(?P[0-9]+)" "/$", course.flow.view_flow_page, name="relate-view_flow_page"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/prev_answers" + "/" + COURSE_ID_REGEX + + "/prev_answers" "/flow-page" "/(?P[0-9]+)" "/(?P[0-9]+)" @@ -397,16 +397,16 @@ urlpatterns = [ course.flow.get_prev_answer_visits_dropdown_content, name="relate-get_prev_answer_visits_dropdown_content"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-session" + "/" + COURSE_ID_REGEX + + "/flow-session" "/(?P[-0-9]+)" "/update-expiration-mode" "/$", course.flow.update_expiration_mode, name="relate-update_expiration_mode"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-session" + "/" + COURSE_ID_REGEX + + "/flow-session" "/(?P[-0-9]+)" "/(?P[0-9]+)" "/update-bookmark-state" @@ -414,16 +414,16 @@ urlpatterns = [ course.flow.update_page_bookmark_state, name="relate-update_page_bookmark_state"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-session" + "/" + COURSE_ID_REGEX + + "/flow-session" "/(?P[0-9]+)" "/finish" "/$", course.flow.finish_flow_session_view, name="relate-finish_flow_session_view"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-session" + "/" + COURSE_ID_REGEX + + "/flow-session" "/(?P[0-9]+)" "/(?P[0-9]+)" "/flow-page-interaction-email" @@ -431,8 +431,8 @@ urlpatterns = [ course.flow.send_email_about_flow_page, name="relate-flow_page_interaction_email"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-session" + "/" + COURSE_ID_REGEX + + "/flow-session" "/(?P[0-9]+)" "/(?P[0-9]+)" "/unsubmit/$", @@ -440,45 +440,45 @@ urlpatterns = [ name="relate-unsubmit_flow_page"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/test-flow" + "/" + COURSE_ID_REGEX + + "/test-flow" "/$", course.views.test_flow, name="relate-test_flow"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/instant-flow" + "/" + COURSE_ID_REGEX + + "/instant-flow" "/$", course.views.manage_instant_flow_requests, name="relate-manage_instant_flow_requests"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/regrade-flows" + "/" + COURSE_ID_REGEX + + "/regrade-flows" "/$", course.flow.regrade_flows_view, name="relate-regrade_flows_view"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grant-exception" + "/" + COURSE_ID_REGEX + + "/grant-exception" "/$", course.views.grant_exception, name="relate-grant_exception"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grant-exception" + "/" + COURSE_ID_REGEX + + "/grant-exception" "/(?P[0-9]+)" - "/" + FLOW_ID_REGEX + - "/$", + "/" + FLOW_ID_REGEX + + "/$", course.views.grant_exception_stage_2, name="relate-grant_exception_stage_2"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/grant-exception" + "/" + COURSE_ID_REGEX + + "/grant-exception" "/(?P[0-9]+)" - "/" + FLOW_ID_REGEX + - "/(?P[0-9]+)" + "/" + FLOW_ID_REGEX + + "/(?P[0-9]+)" "/$", course.views.grant_exception_stage_3, name="relate-grant_exception_stage_3"), @@ -488,23 +488,23 @@ urlpatterns = [ # {{{ analytics url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-analytics" + "/" + COURSE_ID_REGEX + + "/flow-analytics" "/$", course.analytics.flow_list, name="relate-flow_list"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-analytics" - "/" + FLOW_ID_REGEX + - "/$", + "/" + COURSE_ID_REGEX + + "/flow-analytics" + "/" + FLOW_ID_REGEX + + "/$", course.analytics.flow_analytics, name="relate-flow_analytics"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/flow-analytics" - "/" + FLOW_ID_REGEX + - "/page" + "/" + COURSE_ID_REGEX + + "/flow-analytics" + "/" + FLOW_ID_REGEX + + "/page" "/(?P[-_a-zA-Z0-9]+)" "/(?P[-_a-zA-Z0-9]+)" "/$", @@ -520,8 +520,8 @@ urlpatterns = [ course.exam.issue_exam_ticket, name="relate-issue_exam_ticket"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/batch-issue-exam-tickets" + "/" + COURSE_ID_REGEX + + "/batch-issue-exam-tickets" "/$", course.exam.batch_issue_exam_tickets, name="relate-batch_issue_exam_tickets"), @@ -541,14 +541,14 @@ urlpatterns = [ #}}} url(r"^course" - "/" + COURSE_ID_REGEX + - "/api/v1/get-flow-sessions$", + "/" + COURSE_ID_REGEX + + "/api/v1/get-flow-sessions$", course.api.get_flow_sessions, name="relate-course_get_flow_session"), url(r"^course" - "/" + COURSE_ID_REGEX + - "/api/v1/get-flow-session-content$", + "/" + COURSE_ID_REGEX + + "/api/v1/get-flow-session-content$", course.api.get_flow_session_content, name="relate-course_get_flow_session_content"), diff --git a/tests/test_auth.py b/tests/test_auth.py index 8997dfde..3705a84b 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1514,7 +1514,7 @@ class UserProfileTest(CoursesTestMixinBase, AuthTestMixin, for specific field """ field_div_with_id_pattern = ( - ".*(]*id\s*=\s*['\"]div_id_%s['\"][^>]*\/?>).*") + r".*(]*id\s*=\s*['\"]div_id_%s['\"][^>]*\/?>).*") def assertFieldDiv(field_name, exist=True): # noqa resp = self.get_profile_by_request_factory() diff --git a/tests/test_content.py b/tests/test_content.py index d08fc0a3..bdb1818a 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -372,7 +372,7 @@ class NbconvertRenderTest(NbconvertRenderTestMixin, TestCase): # code highlight functions (in terms of rendered ipynb notebook cells only) if six.PY3: - self.assertRegex(resp.context["body"], 'class="\w*\s*highlight[^\w]') + self.assertRegex(resp.context["body"], r'class="\w*\s*highlight[^\w]') self.assertContains(resp, " highlight hl-ipython3") self.assertContains(resp, 'print' diff --git a/tests/test_pages/test_base.py b/tests/test_pages/test_base.py index edc0d88d..e3dbc2b5 100644 --- a/tests/test_pages/test_base.py +++ b/tests/test_pages/test_base.py @@ -43,7 +43,7 @@ from tests.utils import mock SANDBOX_TITLE_PATTERN = "[SB] %s - RELATE " -TEXT_QUESTION_MARKDOWN = """ +TEXT_QUESTION_MARKDOWN = r""" type: TextQuestion id: eigvec title: Eigenvectors @@ -63,7 +63,7 @@ answers: """ -TEXT_QUESTION_WITH_NEGATIVE_VALUE_MARKDOWN = """ +TEXT_QUESTION_WITH_NEGATIVE_VALUE_MARKDOWN = r""" type: TextQuestion id: eigvec title: Eigenvectors @@ -83,7 +83,7 @@ answers: """ -OPTIONAL_PAGE_WITH_VALUE_ATTR = """ +OPTIONAL_PAGE_WITH_VALUE_ATTR = r""" type: TextQuestion id: eigvec is_optional_page: True @@ -117,7 +117,7 @@ content: | """ -TEST_ANSWER_MARKDOWN = """ +TEST_ANSWER_MARKDOWN = r""" type: ChoiceQuestion id: myquestion shuffle: True diff --git a/tests/test_pages/test_inline.py b/tests/test_pages/test_inline.py index 6b42f797..f18ec716 100644 --- a/tests/test_pages/test_inline.py +++ b/tests/test_pages/test_inline.py @@ -62,7 +62,7 @@ answers: - bar """ -INLINE_MULTI_MARKDOWN_TWO_NOT_REQUIRED = """ +INLINE_MULTI_MARKDOWN_TWO_NOT_REQUIRED = r""" type: InlineMultiQuestion id: inlinemulti value: 10 @@ -270,7 +270,7 @@ answers: """ -INLINE_MULTI_MARKDOWN_EMBEDDED_TEXT_Q_NO_STRINGIFIABLE_CORRECT_ANSWER = """ +INLINE_MULTI_MARKDOWN_EMBEDDED_TEXT_Q_NO_STRINGIFIABLE_CORRECT_ANSWER = r""" type: InlineMultiQuestion id: inlinemulti value: 10 @@ -343,7 +343,7 @@ answers: """ -INLINE_MULTI_MARKDOWN_EMBEDDED_NAMING_ERROR = """ +INLINE_MULTI_MARKDOWN_EMBEDDED_NAMING_ERROR = r""" type: InlineMultiQuestion id: inlinemulti value: 10 @@ -381,7 +381,7 @@ answers: - [0.25] """ -INLINE_MULTI_MARKDOWN_ANSWERS_NAMING_ERROR = """ +INLINE_MULTI_MARKDOWN_ANSWERS_NAMING_ERROR = r""" type: InlineMultiQuestion id: inlinemulti value: 10 @@ -429,7 +429,7 @@ answers: """ -INLINE_MULTI_MARKDOWN_EMBEDDED_NAMING_DUPLICATED = """ +INLINE_MULTI_MARKDOWN_EMBEDDED_NAMING_DUPLICATED = r""" type: InlineMultiQuestion id: inlinemulti value: 10 diff --git a/tests/test_pages/test_text.py b/tests/test_pages/test_text.py index fe514245..0da1847c 100644 --- a/tests/test_pages/test_text.py +++ b/tests/test_pages/test_text.py @@ -45,7 +45,7 @@ from tests.test_sandbox import ( from tests.constants import PAGE_ERRORS from tests.utils import mock -TEXT_QUESTION_WITH_ANSWER_EXPLANATION_MARKDOWN = """ +TEXT_QUESTION_WITH_ANSWER_EXPLANATION_MARKDOWN = r""" type: TextQuestion id: eigvec title: Eigenvectors @@ -69,7 +69,7 @@ answer_explanation: | """ -TEXT_QUESTION_WITH_UNKNOWN_WIDGET_MARKDOWN = """ +TEXT_QUESTION_WITH_UNKNOWN_WIDGET_MARKDOWN = r""" type: TextQuestion id: eigvec title: Eigenvectors @@ -105,7 +105,7 @@ answers: [] """ -TEXT_QUESTION_WITH_NONE_STRINGIFIABLE_ANSWER_MARKDOWN = """ +TEXT_QUESTION_WITH_NONE_STRINGIFIABLE_ANSWER_MARKDOWN = r""" type: TextQuestion id: eigvec title: Eigenvectors @@ -223,7 +223,7 @@ class MatcherTest(unittest.TestCase): RegexMatcher(None, "", failed_pattern) self.assertIn(expected_error_msg, str(cm.exception)) - pattern = "(?:linear\s+)?\s*map" + pattern = r"(?:linear\s+)?\s*map" matcher = RegexMatcher(None, "", pattern) self.assertEqual(matcher.grade("Linear map"), 1) self.assertEqual(matcher.grade("linear MAP "), 1) @@ -246,7 +246,7 @@ class MatcherTest(unittest.TestCase): CaseSensitiveRegexMatcher(None, "", failed_pattern) self.assertIn(expected_error_msg, str(cm.exception)) - pattern = "(?:linear\s+)?\s*map" + pattern = r"(?:linear\s+)?\s*map" matcher = CaseSensitiveRegexMatcher(None, "", pattern) self.assertEqual(matcher.grade("linear map"), 1) self.assertEqual(matcher.grade("Linear map"), 0) -- GitLab