Commit cc5c1001 by Ned Batchelder

Fix simplifiable-range pylint warnings.

parent 5b6294fe
......@@ -273,11 +273,11 @@ class TestCourseListing(ModuleStoreTestCase):
num_courses_to_create = 3
courses = [
self._create_course_with_access_groups(CourseLocator('Org', 'CreatedCourse' + str(num), 'Run'), self.user)
for num in range(0, num_courses_to_create)
for num in range(num_courses_to_create)
]
courses_in_progress = [
self._create_course_with_access_groups(CourseLocator('Org', 'InProgressCourse' + str(num), 'Run'), self.user)
for num in range(0, num_courses_to_create)
for num in range(num_courses_to_create)
]
# simulate initiation of course actions
......
......@@ -58,7 +58,7 @@ COURSE_CHILD_STRUCTURE = {
def create_children(store, parent, category, load_factor):
""" create load_factor children within the given parent; recursively call to insert children when appropriate """
created_count = 0
for child_index in range(0, load_factor):
for child_index in range(load_factor):
child_object = ItemFactory.create(
parent_location=parent.location,
category=category,
......
......@@ -144,7 +144,7 @@ class TestLibraries(LibraryTestCase):
"""
Test the 'max_count' property of LibraryContent blocks.
"""
for _ in range(0, num_to_create):
for _ in range(num_to_create):
self._add_simple_content_block()
with modulestore().default_store(ModuleStoreEnum.Type.split):
......@@ -168,7 +168,7 @@ class TestLibraries(LibraryTestCase):
Test that the same student will always see the same selected child block
"""
# Create many blocks in the library and add them to a course:
for num in range(0, 8):
for num in range(8):
ItemFactory.create(
data="This is #{}".format(num + 1),
category="html", parent_location=self.library.location, user_id=self.user.id, publish_item=False
......@@ -202,7 +202,7 @@ class TestLibraries(LibraryTestCase):
"""
Confirm that chosen_child is still the child seen by the test student
"""
for _ in range(0, 6): # Repeat many times b/c blocks are randomized
for _ in range(6): # Repeat many times b/c blocks are randomized
lc_block = modulestore().get_item(lc_block_key) # Reload block from the database
self._bind_module(lc_block)
current_child = get_child_of_lc_block(lc_block)
......
......@@ -124,7 +124,7 @@ class HelperMethods(object):
i, 'Name ' + str(i), 'Description ' + str(i),
[Group(0, 'Group A'), Group(1, 'Group B'), Group(2, 'Group C')],
scheme=None, scheme_id=scheme_id
) for i in xrange(0, count)
) for i in xrange(count)
]
self.course.user_partitions = partitions
self.save_course()
......
......@@ -51,7 +51,7 @@ class UnitTestLibraries(ModuleStoreTestCase):
Test that we can GET /library/ to list all libraries visible to the current user.
"""
# Create some more libraries
libraries = [LibraryFactory.create() for _ in range(0, 3)]
libraries = [LibraryFactory.create() for _ in range(3)]
lib_dict = dict([(lib.location.library_key, lib) for lib in libraries])
response = self.client.get_json(LIBRARY_REST_URL)
......
......@@ -13,7 +13,7 @@ class MemcacheTest(TestCase):
"""
# Test whitespace, control characters, and some non-ASCII UTF-16
UNICODE_CHAR_CODES = ([c for c in range(0, 30)] + [127] +
UNICODE_CHAR_CODES = (range(30) + [127] +
[129, 500, 2 ** 8 - 1, 2 ** 8 + 1, 2 ** 16 - 1])
def setUp(self):
......
......@@ -73,12 +73,12 @@ class ResponseXMLFactory(object):
question.text = question_text
# Add the response(s)
for i in range(0, int(num_responses)):
for __ in range(int(num_responses)):
response_element = self.create_response_element(**kwargs)
root.append(response_element)
# Add input elements
for j in range(0, int(num_inputs)):
for __ in range(int(num_inputs)):
input_element = self.create_input_element(**kwargs)
if not (None == input_element):
response_element.append(input_element)
......
......@@ -553,14 +553,14 @@ class AnnotationInputTemplateTest(TemplateTestCase):
{'id': id_num,
'choice': 'correct',
'description': '<p>Unescaped <b>HTML {0}</b></p>'.format(id_num)}
for id_num in range(0, 5)]
for id_num in range(5)]
xml = self.render_to_xml(self.context)
# Expect that each option description is visible
# with unescaped HTML.
# Since the HTML is unescaped, we can traverse the XML tree
for id_num in range(0, 5):
for id_num in range(5):
xpath = "//span[@data-id='{0}']/p/b".format(id_num)
self.assert_has_text(xml, xpath, 'HTML {0}'.format(id_num), exact=False)
......@@ -689,7 +689,7 @@ class OptionInputTemplateTest(TemplateTestCase):
# Create options 0-4, and select option 2
self.context['options'] = [(id_num, '<b>Option {0}</b>'.format(id_num))
for id_num in range(0, 5)]
for id_num in range(5)]
self.context['value'] = 2
xml = self.render_to_xml(self.context)
......@@ -701,7 +701,7 @@ class OptionInputTemplateTest(TemplateTestCase):
# Should have each of the options, with the correct description
# The description HTML should NOT be escaped
# (that's why we descend into the <b> tag)
for id_num in range(0, 5):
for id_num in range(5):
xpath = "//option[@value='{0}']/b".format(id_num)
self.assert_has_text(xml, xpath, 'Option {0}'.format(id_num))
......
......@@ -144,7 +144,7 @@ class TestLibraries(MixedSplitTestCase):
def test_get_libraries(self):
""" Test get_libraries() """
libraries = [LibraryFactory.create(modulestore=self.store) for _ in range(0, 3)]
libraries = [LibraryFactory.create(modulestore=self.store) for _ in range(3)]
lib_dict = dict([(lib.location.library_key, lib) for lib in libraries])
lib_list = self.store.get_libraries()
......
......@@ -107,7 +107,7 @@ class TestSplitCopyTemplate(MixedSplitTestCase):
# We do the following twice because different methods get used inside
# split modulestore on first vs. subsequent publish
for __ in range(0, 2):
for __ in range(2):
# Publish:
self.store.publish(problem_key_in_course, self.user_id)
# Test that the defaults values are there.
......
......@@ -665,8 +665,8 @@ class CombinedOpenEndedV1Module(object):
last_post_assessment = task.latest_post_assessment(self.system, short_feedback=False, join_feedback=False)
if isinstance(last_post_assessment, list):
eval_list = []
for i in xrange(0, len(last_post_assessment)):
eval_list.append(task.format_feedback_with_evaluation(self.system, last_post_assessment[i]))
for assess in last_post_assessment:
eval_list.append(task.format_feedback_with_evaluation(self.system, assess))
last_post_evaluation = "".join(eval_list)
else:
last_post_evaluation = task.format_feedback_with_evaluation(self.system, last_post_assessment)
......@@ -1017,7 +1017,7 @@ class CombinedOpenEndedV1Module(object):
ugettext = self.system.service(self, "i18n").ugettext
status_list = []
current_task_human_name = ""
for i in xrange(0, len(self.task_xml)):
for i in xrange(len(self.task_xml)):
human_task_name = self.extract_human_name_from_task(self.task_xml[i])
human_task_name = ugettext(human_task_name) # pylint: disable=translation-of-non-string
# Extract the name of the current task for screen readers.
......@@ -1080,16 +1080,16 @@ class CombinedOpenEndedV1Module(object):
if self.is_scored:
# Finds the maximum score of all student attempts and keeps it.
score_mat = []
for i in xrange(0, len(self.task_states)):
for i in xrange(len(self.task_states)):
# For each task, extract all student scores on that task (each attempt for each task)
last_response = self.get_last_response(i)
score = last_response.get('all_scores', None)
if score is not None:
# Convert none scores and weight scores properly
for z in xrange(0, len(score)):
if score[z] is None:
score[z] = 0
score[z] *= float(weight)
for j in xrange(len(score)):
if score[j] is None:
score[j] = 0
score[j] *= float(weight)
score_mat.append(score)
if len(score_mat) > 0:
......@@ -1219,7 +1219,7 @@ class CombinedOpenEndedV1Descriptor(object):
def parse_task(k):
"""Assumes that xml_object has child k"""
return [stringify_children(xml_object.xpath(k)[i]) for i in xrange(0, len(xml_object.xpath(k)))]
return [stringify_children(xml_object.xpath(k)[i]) for i in xrange(len(xml_object.xpath(k)))]
def parse(k):
"""Assumes that xml_object has child k"""
......
......@@ -59,9 +59,9 @@ class CombinedOpenEndedRubric(object):
try:
rubric_categories = self.extract_categories(rubric_xml)
if score_list and len(score_list) == len(rubric_categories):
for i in xrange(0, len(rubric_categories)):
for i in xrange(len(rubric_categories)):
category = rubric_categories[i]
for j in xrange(0, len(category['options'])):
for j in xrange(len(category['options'])):
if score_list[i] == j:
rubric_categories[i]['options'][j]['selected'] = True
rubric_scores = [cat['score'] for cat in rubric_categories]
......@@ -315,23 +315,22 @@ class CombinedOpenEndedRubric(object):
score_lists = []
score_type_list = []
feedback_type_list = []
for i in xrange(0, len(scores)):
for i in xrange(len(scores)):
score_cont_list = scores[i]
for j in xrange(0, len(score_cont_list)):
for j in xrange(len(score_cont_list)):
score_list = score_cont_list[j]
score_lists.append(score_list)
score_type_list.append(score_types[i][j])
feedback_type_list.append(feedback_types[i][j])
score_list_len = len(score_lists[0])
for i in xrange(0, len(score_lists)):
score_list = score_lists[i]
for score_list in score_lists:
if len(score_list) != score_list_len:
return success, ""
score_tuples = []
for i in xrange(0, len(score_lists)):
for j in xrange(0, len(score_lists[i])):
for i in xrange(len(score_lists)):
for j in xrange(len(score_lists[i])):
tuple = [1, j, score_lists[i][j], [], []]
score_tuples, tup_ind = CombinedOpenEndedRubric.check_for_tuple_matches(score_tuples, tuple)
score_tuples[tup_ind][0] += 1
......@@ -353,9 +352,9 @@ class CombinedOpenEndedRubric(object):
category = tuple[1]
score = tuple[2]
tup_ind = -1
for t in xrange(0, len(tuples)):
if tuples[t][1] == category and tuples[t][2] == score:
tup_ind = t
for ind in xrange(len(tuples)):
if tuples[ind][1] == category and tuples[ind][2] == score:
tup_ind = ind
break
if tup_ind == -1:
......
......@@ -574,7 +574,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
feedback_dicts = []
grader_ids = []
submission_ids = []
for i in xrange(0, len(score_result['score'])):
for i in xrange(len(score_result['score'])):
new_score_result = {
'score': score_result['score'][i],
'feedback': score_result['feedback'][i],
......@@ -817,7 +817,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
"""None if not available"""
if not self.child_history:
return None
return [self.score_for_attempt(index) for index in xrange(0, len(self.child_history))]
return [self.score_for_attempt(index) for index in xrange(len(self.child_history))]
def score_for_attempt(self, index):
"""
......
......@@ -213,7 +213,7 @@ class OpenEndedChild(object):
"""None if not available"""
if not self.child_history:
return None
return [self.child_history[i].get('score') for i in xrange(0, len(self.child_history))]
return [child_hist.get('score') for child_hist in self.child_history]
def latest_post_assessment(self, system):
"""Empty string if not available"""
......
......@@ -141,7 +141,7 @@ class LibraryEditPageTest(StudioLibraryTest):
Then 10 are displayed.
"""
self.assertEqual(len(self.lib_page.xblocks), 0)
for _ in range(0, 10):
for _ in range(10):
add_component(self.lib_page, "problem", "Multiple Choice")
self.assertEqual(len(self.lib_page.xblocks), 10)
add_component(self.lib_page, "problem", "Multiple Choice")
......
......@@ -148,7 +148,7 @@ class TestRecommender(ModuleStoreTestCase, LoginEnrollmentTestCase):
if xblock_name is None:
xblock_name = TestRecommender.XBLOCK_NAMES[0]
url = self.get_handler_url(handler, xblock_name)
for _ in range(0, times):
for _ in range(times):
self.client.post(url, json.dumps({'id': resource_id}), '')
def call_event(self, handler, resource, xblock_name=None):
......@@ -460,7 +460,7 @@ class TestRecommenderVoteWithResources(TestRecommenderWithResources):
Vote a resource thrice
"""
resource = {"id": self.resource_id, 'event': test_case['event']}
for _ in range(0, 2):
for _ in range(2):
self.call_event('handle_vote', resource)
# Test
self.check_event_response_by_key('handle_vote', resource, 'newVotes', test_case['new_votes'])
......@@ -552,7 +552,7 @@ class TestRecommenderStaffFeedbackWithResources(TestRecommenderWithResources):
Endorse a resource once/twice/thrice
"""
resource = {"id": self.resource_id, 'reason': ''}
for _ in range(0, test_case['times'] - 1):
for _ in range(test_case['times'] - 1):
self.call_event('endorse_resource', resource)
# Test
self.check_event_response_by_key('endorse_resource', resource, test_case['key'], test_case['val'])
......@@ -567,7 +567,7 @@ class TestRecommenderStaffFeedbackWithResources(TestRecommenderWithResources):
Remove a resource once/twice/thrice
"""
resource = {"id": self.resource_id, 'reason': ''}
for _ in range(0, test_case['times'] - 1):
for _ in range(test_case['times'] - 1):
self.call_event('remove_resource', resource)
# Test
self.check_event_response_by_http_status('remove_resource', resource, test_case['status'])
......
......@@ -55,11 +55,11 @@ class FakeEmail(FakeInfo):
super(FakeEmail, self).__init__()
self.id = unicode(email_id) # pylint: disable=invalid-name
# Select a random data for create field
year = random.choice(range(1950, 2000))
month = random.choice(range(1, 12))
day = random.choice(range(1, 28))
hour = random.choice(range(0, 23))
minute = random.choice(range(0, 59))
year = random.randint(1950, 2000)
month = random.randint(1, 12)
day = random.randint(1, 28)
hour = random.randint(0, 23)
minute = random.randint(0, 59)
self.created = datetime.datetime(year, month, day, hour, minute, tzinfo=utc)
......
......@@ -144,12 +144,12 @@ class TestVideoAPIMixin(object):
"""
path = course_outline[outline_index]['path']
self.assertEqual(len(path), len(path_list))
for i in range(0, len(path_list)):
for i in range(len(path_list)):
self.assertEqual(path_list[i], path[i]['name'])
#named_path will be deprecated eventually
named_path = course_outline[outline_index]['named_path']
self.assertEqual(len(named_path), len(path_list))
for i in range(0, len(path_list)):
for i in range(len(path_list)):
self.assertEqual(path_list[i], named_path[i])
def _setup_course_partitions(self, scheme_id='random', is_cohorted=False):
......
......@@ -319,7 +319,7 @@ def get_problem_list(request, course_id):
u'If not, please do so and return to this page.'
)
valid_problem_list = []
for i in xrange(0, len(problem_list)):
for i in xrange(len(problem_list)):
# Needed to ensure that the 'location' key can be accessed.
try:
problem_list[i] = json.loads(problem_list[i])
......
......@@ -247,7 +247,7 @@ def combined_notifications(request, course_id):
notification_tuples = open_ended_notifications.NOTIFICATION_TYPES
notification_list = []
for response_num in xrange(0, len(notification_tuples)):
for response_num in xrange(len(notification_tuples)):
tag = notification_tuples[response_num][0]
if tag in response:
url_name = notification_tuples[response_num][1]
......
......@@ -52,7 +52,7 @@ class TestRandomUserPartitionScheme(PartitionTestCase):
group1_id = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
# make sure we get the same group back out every time
for __ in range(0, 10):
for __ in range(10):
group2_id = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
self.assertEqual(group1_id, group2_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment