From 476da01f367d56bbb942e5729eb5031ddcf9cd61 Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Thu, 26 Sep 2019 15:22:22 +0500 Subject: [PATCH] BOM-612 python3 compatibility --- common/lib/capa/capa/tests/test_inputtypes.py | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/common/lib/capa/capa/tests/test_inputtypes.py b/common/lib/capa/capa/tests/test_inputtypes.py index 87369d1548..85cdbfa88c 100644 --- a/common/lib/capa/capa/tests/test_inputtypes.py +++ b/common/lib/capa/capa/tests/test_inputtypes.py @@ -747,17 +747,28 @@ class MatlabTest(unittest.TestCase): def test_get_html(self): # usual output output = self.the_input.get_html() - self.assertEqual( - etree.tostring(output), - textwrap.dedent(""" -
{\'status\': Status(\'queued\'), \'button_enabled\': True, \'rows\': \'10\', \'queue_len\': \'3\', - \'mode\': \'\', \'tabsize\': 4, \'cols\': \'80\', \'STATIC_URL\': \'/dummy-static/\', \'linenumbers\': - \'true\', \'queue_msg\': \'\', \'value\': \'print "good evening"\', + if six.PY2: + expected_string = """ +
{\'status\': Status(\'queued\'), \'button_enabled\': True, \'rows\': \'10\', + \'queue_len\': \'3\', \'mode\': \'\', \'tabsize\': 4, \'cols\': \'80\', \'STATIC_URL\': \'/dummy-static/\', + \'linenumbers\': \'true\', \'queue_msg\': \'\', \'value\': \'print "good evening"\', \'msg\': u\'Submitted. As soon as a response is returned, this message will be replaced by that feedback.\', \'matlab_editor_js\': \'/dummy-static/js/vendor/CodeMirror/octave.js\', \'hidden\': \'\', \'id\': \'prob_1_2\', \'describedby_html\': Markup(u\'aria-describedby="status_prob_1_2"\'), \'response_data\': {}}
- """).replace('\n', ' ').strip() + """ + else: + expected_string = """ +
{\'matlab_editor_js\': \'/dummy-static/js/vendor/CodeMirror/octave.js\', + \'value\': \'print "good evening"\', \'hidden\': \'\', + \'msg\': \'Submitted. As soon as a response is returned, this message will be replaced by that feedback.\', + \'status\': Status(\'queued\'), \'response_data\': {}, \'queue_msg\': \'\', \'mode\': \'\', + \'id\': \'prob_1_2\', \'queue_len\': \'3\', \'tabsize\': 4, \'STATIC_URL\': \'/dummy-static/\', + \'linenumbers\': \'true\', \'cols\': \'80\', \'button_enabled\': True, \'rows\': \'10\', + \'describedby_html\': Markup(\'aria-describedby="status_prob_1_2"\')}
""" + self.assertEqual( + etree.tostring(output).decode('utf-8'), + textwrap.dedent(expected_string).replace('\n', ' ').strip(), ) # test html, that is correct HTML5 html, but is not parsable by XML parser. @@ -768,15 +779,25 @@ class MatlabTest(unittest.TestCase):
Right click here and click \"Save As\" to download the file
""").replace('\n', '') + output = self.the_input.get_html() - self.assertEqual( - etree.tostring(output), - textwrap.dedent(""" + if six.PY2: + expected_string = """
Right click here and click \"Save As\" to download the file
    - """).replace('\n', '').replace('\'', '\"') + """ + else: + expected_string = """ +
    + +
    Right click here and click \"Save As\" to download the file
    +
      + """ + self.assertEqual( + etree.tostring(output).decode('utf-8'), + textwrap.dedent(expected_string).replace('\n', '').replace('\'', '\"') ) # check that exception is raised during parsing for html.