chore: remove some usages of six (Python2 compat) (#32554)
* get rid of six.text_type(s) * get rid of six.b() * get rid of six.string_types * get rid of six.PY2/six.PY3 * get rid of six.iteritems() and six.viewvalues()
This commit is contained in:
@@ -8,7 +8,6 @@ import os.path
|
||||
import xml.sax.saxutils as saxutils
|
||||
|
||||
import fs.osfs
|
||||
import six
|
||||
from mako.lookup import TemplateLookup
|
||||
from mock import MagicMock, Mock
|
||||
from path import Path
|
||||
@@ -94,10 +93,7 @@ def mock_capa_block():
|
||||
return 'i4x://Foo/bar/mock/abc'
|
||||
|
||||
capa_block = Mock()
|
||||
if six.PY2:
|
||||
capa_block.location.__unicode__ = mock_location_text
|
||||
else:
|
||||
capa_block.location.__str__ = mock_location_text
|
||||
capa_block.location.__str__ = mock_location_text
|
||||
# The following comes into existence by virtue of being called
|
||||
# capa_block.runtime.publish
|
||||
return capa_block
|
||||
|
||||
@@ -730,7 +730,7 @@ class StringResponseXMLFactory(ResponseXMLFactory):
|
||||
response_element = etree.Element("stringresponse")
|
||||
|
||||
# Set the answer attribute
|
||||
response_element.set("answer", six.text_type(answer))
|
||||
response_element.set("answer", str(answer))
|
||||
|
||||
# Set the case sensitivity and regexp:
|
||||
type_value = ''
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
"""
|
||||
Test capa problem.
|
||||
"""
|
||||
|
||||
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
import ddt
|
||||
import six
|
||||
from lxml import etree
|
||||
from markupsafe import Markup
|
||||
from mock import patch
|
||||
@@ -430,7 +428,7 @@ class CAPAMultiInputProblemTest(unittest.TestCase):
|
||||
|
||||
def assert_problem_data(self, problem_data):
|
||||
"""Verify problem data is in expected state"""
|
||||
for problem_value in six.viewvalues(problem_data):
|
||||
for problem_value in problem_data.values():
|
||||
assert isinstance(problem_value['label'], Markup)
|
||||
|
||||
def assert_problem_html(self, problem_html, group_label, *input_labels):
|
||||
@@ -733,4 +731,4 @@ class CAPAProblemReportHelpersTest(unittest.TestCase):
|
||||
|
||||
# Ensure that the answer is a string so that the dict returned from this
|
||||
# function can eventualy be serialized to json without issues.
|
||||
assert isinstance(problem.get_question_answers()['1_solution_1'], six.text_type)
|
||||
assert isinstance(problem.get_question_answers()['1_solution_1'], str)
|
||||
|
||||
@@ -1632,7 +1632,6 @@ class TestStatus(unittest.TestCase):
|
||||
"""
|
||||
statobj = inputtypes.Status('test')
|
||||
assert str(statobj) == 'test'
|
||||
assert six.text_type(statobj) == 'test'
|
||||
|
||||
def test_classes(self):
|
||||
"""
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
"""
|
||||
Tests of responsetypes
|
||||
"""
|
||||
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
@@ -18,9 +16,7 @@ import mock
|
||||
import pyparsing
|
||||
import random2 as random
|
||||
import requests
|
||||
import six
|
||||
from pytz import UTC
|
||||
from six import text_type
|
||||
|
||||
from xmodule.capa.correctmap import CorrectMap
|
||||
from xmodule.capa.responsetypes import LoncapaProblemError, ResponseError, StudentInputError
|
||||
@@ -798,7 +794,7 @@ class StringResponseTest(ResponseTest): # pylint: disable=missing-class-docstri
|
||||
problem = self.build_problem(answer="a2", case_sensitive=False, regexp=True, additional_answers=['?\\d?'])
|
||||
with pytest.raises(Exception) as cm:
|
||||
self.assert_grade(problem, "a3", "correct")
|
||||
exception_message = text_type(cm.value)
|
||||
exception_message = str(cm.value)
|
||||
assert 'nothing to repeat' in exception_message
|
||||
|
||||
def test_hints(self):
|
||||
@@ -2728,7 +2724,7 @@ class ChoiceTextResponseTest(ResponseTest):
|
||||
radiotextgroup.
|
||||
"""
|
||||
|
||||
for name, inputs in six.iteritems(self.TEST_INPUTS):
|
||||
for name, inputs in self.TEST_INPUTS.items():
|
||||
# Turn submission into the form expected when grading this problem.
|
||||
submission = self._make_answer_dict(inputs)
|
||||
# Lookup the problem_name, and the whether this test problem
|
||||
@@ -2808,7 +2804,7 @@ class ChoiceTextResponseTest(ResponseTest):
|
||||
"checkbox_2_choices_2_inputs": checkbox_two_choices_two_inputs
|
||||
}
|
||||
|
||||
for name, inputs in six.iteritems(inputs):
|
||||
for name, inputs in inputs.items():
|
||||
submission = self._make_answer_dict(inputs)
|
||||
# Load the test problem's name and desired correctness
|
||||
problem_name, correctness = scenarios[name]
|
||||
|
||||
Reference in New Issue
Block a user