From f5f875401aa95d8195969ff5ad4e18cc48c03081 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 16 Aug 2019 11:31:36 -0400 Subject: [PATCH] Fix some of the common test collection issues. (#21340) * Remove old performance tests that we haven't been running. As far as I can tell, these tests to capture HAR files were created 5 years ago and not being run as a part of our suite? They capture HAR data that we do nothing with so even if they were running we should remove them until we're ready to care about consuming this kind of information. * Update password test unicode string. * Add ugettext translation helper function. * Fix lambda syntax that is not valid in python 3. * Fix ur raw strings which his not valid in python 3 * Use edx_six.get_gettext instead of ugettext. * Fix a few other encoding issues. * Don't use old form of sorted funciton. This form which uses a 'cmp' method is not available in python 3. --- .../tests/test_password_policy_validators.py | 2 +- common/lib/capa/capa/inputtypes.py | 42 ++++--- common/lib/capa/capa/responsetypes.py | 53 ++++---- common/lib/capa/capa/tests/helpers.py | 5 +- .../lib/capa/capa/tests/test_responsetypes.py | 10 +- common/lib/capa/capa/util.py | 2 +- common/test/acceptance/fixtures/config.py | 6 +- .../acceptance/pages/studio/import_export.py | 2 +- .../test/acceptance/performance/__init__.py | 0 .../performance/test_lms_performance.py | 116 ------------------ .../performance/test_studio_performance.py | 100 --------------- .../tests/discussion/test_discussion.py | 9 +- .../instructor/views/instructor_dashboard.py | 2 +- openedx/core/lib/edx_six.py | 16 +++ 14 files changed, 91 insertions(+), 274 deletions(-) delete mode 100644 common/test/acceptance/performance/__init__.py delete mode 100644 common/test/acceptance/performance/test_lms_performance.py delete mode 100644 common/test/acceptance/performance/test_studio_performance.py create mode 100644 openedx/core/lib/edx_six.py diff --git a/common/djangoapps/util/tests/test_password_policy_validators.py b/common/djangoapps/util/tests/test_password_policy_validators.py index 6b20b587f9..fa17430c01 100644 --- a/common/djangoapps/util/tests/test_password_policy_validators.py +++ b/common/djangoapps/util/tests/test_password_policy_validators.py @@ -48,8 +48,8 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase): def test_unicode_password(self): """ Tests that validate_password enforces unicode """ - byte_str = b'𤭮' unicode_str = u'𤭮' + byte_str = unicode_str.encode('utf-8') # Sanity checks and demonstration of why this test is useful self.assertEqual(len(byte_str), 4) diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 24ec87b620..b0e35139ea 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -59,7 +59,9 @@ from six import text_type from capa.xqueue_interface import XQUEUE_TIMEOUT from chem import chemcalc from openedx.core.djangolib.markup import HTML, Text +from openedx.core.lib import edx_six from xmodule.stringify import stringify_children +from openedx.core.lib import edx_six from . import xqueue_interface from .registry import TagRegistry @@ -256,6 +258,7 @@ class InputTypeBase(object): # Something went wrong: add xml to message, but keep the traceback msg = u"Error in xml '{x}': {err} ".format( x=etree.tostring(xml), err=text_type(err)) + msg = Exception(msg) six.reraise(Exception, msg, sys.exc_info()[2]) @classmethod @@ -326,7 +329,7 @@ class InputTypeBase(object): context = { 'id': self.input_id, 'value': self.value, - 'status': Status(self.status, self.capa_system.i18n.ugettext), + 'status': Status(self.status, edx_six.get_gettext(self.capa_system.i18n)), 'msg': self.msg, 'response_data': self.response_data, 'STATIC_URL': self.capa_system.STATIC_URL, @@ -427,14 +430,21 @@ class OptionInput(InputTypeBase): options = re.sub(r"([a-zA-Z])('|\\')([a-zA-Z])", r"\1'\3", options) options = re.sub(r"\\'", r"'", options) # replace already escaped single quotes # parse the set of possible options - lexer = shlex.shlex(options[1:-1].encode('utf8')) + if six.PY3: + lexer = shlex.shlex(options[1:-1]) + else: + lexer = shlex.shlex(options[1:-1].encode('utf-8')) + lexer.quotes = "'" # Allow options to be separated by whitespace as well as commas lexer.whitespace = ", " # remove quotes # convert escaped single quotes (html encoded string) back to single quotes - tokens = [x[1:-1].decode('utf8').replace("'", "'") for x in lexer] + if six.PY3: + tokens = [x[1:-1].replace("'", "'") for x in lexer] + else: + tokens = [x[1:-1].decode('utf-8').replace("'", "'") for x in lexer] # make list of (option_id, option_description), with description=id return [(t, t) for t in tokens] @@ -451,7 +461,7 @@ class OptionInput(InputTypeBase): """ Return extra context. """ - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) return {'default_option_text': _('Select an option')} #----------------------------------------------------------------------------- @@ -499,7 +509,7 @@ class ChoiceGroup(InputTypeBase): self.html_input_type = "checkbox" self.suffix = '[]' else: - _ = i18n.ugettext + _ = edx_six.get_gettext(i18n) # Translators: 'ChoiceGroup' is an input type and should not be translated. msg = _("ChoiceGroup: unexpected tag {tag_name}").format(tag_name=self.tag) raise Exception(msg) @@ -535,7 +545,7 @@ class ChoiceGroup(InputTypeBase): """ choices = [] - _ = i18n.ugettext + _ = edx_six.get_gettext(i18n) for choice in element: if choice.tag == 'choice': @@ -731,7 +741,7 @@ class FileSubmission(InputTypeBase): Do some magic to handle queueing status (render as "queued" instead of "incomplete"), pull queue_len from the msg field. (TODO: get rid of the queue_len hack). """ - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) submitted_msg = _("Your files have been submitted. As soon as your submission is" " graded, this message will be replaced with the grader's feedback.") self.submitted_msg = submitted_msg @@ -803,7 +813,7 @@ class CodeInput(InputTypeBase): def setup(self): """ setup this input type """ - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) submitted_msg = _("Your answer has been submitted. As soon as your submission is" " graded, this message will be replaced with the grader's feedback.") self.submitted_msg = submitted_msg @@ -814,7 +824,7 @@ class CodeInput(InputTypeBase): """ Define queue_len, arial_label and code mirror exit message context variables """ - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) return { 'queue_len': self.queue_len, 'aria_label': _('{programming_language} editor').format( @@ -844,7 +854,7 @@ class MatlabInput(CodeInput): """ Handle matlab-specific parsing """ - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) submitted_msg = _("Submitted. As soon as a response is returned, " "this message will be replaced by that feedback.") @@ -927,7 +937,7 @@ class MatlabInput(CodeInput): def _extra_context(self): """ Set up additional context variables""" - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) queue_msg = self.queue_msg if len(self.queue_msg) > 0: # An empty string cannot be parsed as XML but is okay to include in the template. @@ -976,7 +986,7 @@ class MatlabInput(CodeInput): dict - 'success' - whether or not we successfully queued this submission - 'message' - message to be rendered in case of error """ - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) # only send data if xqueue exists if self.capa_system.xqueue is None: return {'success': False, 'message': _('Cannot connect to the queue')} @@ -1203,7 +1213,7 @@ class ChemicalEquationInput(InputTypeBase): } """ - _ = self.capa_system.i18n.ugettext + _ = edx_six.get_gettext(self.capa_system.i18n) result = {'preview': '', 'error': ''} try: @@ -1287,7 +1297,7 @@ class FormulaEquationInput(InputTypeBase): 'request_start' :