Commit 9f89112e by Muzaffar yousaf

Merge pull request #10419 from edx/muzaffar/pep8-fixes

Fix pep8 & pylint warnings.
parents d9751a85 35884195
...@@ -124,7 +124,10 @@ class CapaHtmlRenderTest(unittest.TestCase): ...@@ -124,7 +124,10 @@ class CapaHtmlRenderTest(unittest.TestCase):
rendered_html = etree.XML(problem.get_html()) rendered_html = etree.XML(problem.get_html())
# expect the javascript is still present in the rendered html # expect the javascript is still present in the rendered html
self.assertTrue("<script type=\"text/javascript\">function(){}</script>" in etree.tostring(rendered_html)) self.assertIn(
"<script type=\"text/javascript\">function(){}</script>",
etree.tostring(rendered_html) # pylint: disable=no-member
)
def test_render_response_xml(self): def test_render_response_xml(self):
# Generate some XML for a string response # Generate some XML for a string response
......
...@@ -105,8 +105,7 @@ class TemplateTestCase(unittest.TestCase): ...@@ -105,8 +105,7 @@ class TemplateTestCase(unittest.TestCase):
If no elements are found, the assertion fails. If no elements are found, the assertion fails.
""" """
element_list = xml_root.xpath(xpath) element_list = xml_root.xpath(xpath)
self.assertTrue(len(element_list) > 0, self.assertGreater(len(element_list), 0, "Could not find element at '%s'" % str(xpath))
"Could not find element at '%s'" % str(xpath))
if exact: if exact:
self.assertEqual(text, element_list[0].text) self.assertEqual(text, element_list[0].text)
......
...@@ -555,8 +555,8 @@ class MatlabTest(unittest.TestCase): ...@@ -555,8 +555,8 @@ class MatlabTest(unittest.TestCase):
response = self.the_input.handle_ajax("plot", data) response = self.the_input.handle_ajax("plot", data)
self.assertFalse(response['success']) self.assertFalse(response['success'])
self.assertEqual(response['message'], error_message) self.assertEqual(response['message'], error_message)
self.assertTrue('queuekey' not in self.the_input.input_state) self.assertNotIn('queuekey', self.the_input.input_state)
self.assertTrue('queuestate' not in self.the_input.input_state) self.assertNotIn('queuestate', self.the_input.input_state)
@patch('capa.inputtypes.time.time', return_value=10) @patch('capa.inputtypes.time.time', return_value=10)
def test_ungraded_response_success(self, time): def test_ungraded_response_success(self, time):
...@@ -594,7 +594,7 @@ class MatlabTest(unittest.TestCase): ...@@ -594,7 +594,7 @@ class MatlabTest(unittest.TestCase):
the_input.ungraded_response(queue_msg, 'abc') the_input.ungraded_response(queue_msg, 'abc')
self.assertEqual(input_state['queuekey'], queuekey) self.assertEqual(input_state['queuekey'], queuekey)
self.assertEqual(input_state['queuestate'], 'queued') self.assertEqual(input_state['queuestate'], 'queued')
self.assertFalse('queue_msg' in input_state) self.assertNotIn('queue_msg', input_state)
@patch('capa.inputtypes.time.time', return_value=20) @patch('capa.inputtypes.time.time', return_value=20)
def test_matlab_response_timeout_not_exceeded(self, time): def test_matlab_response_timeout_not_exceeded(self, time):
...@@ -1076,7 +1076,7 @@ class ChemicalEquationTest(unittest.TestCase): ...@@ -1076,7 +1076,7 @@ class ChemicalEquationTest(unittest.TestCase):
) )
self.assertIn('error', response) self.assertIn('error', response)
self.assertTrue("Couldn't parse formula" in response['error']) self.assertIn("Couldn't parse formula", response['error'])
@patch('capa.inputtypes.log') @patch('capa.inputtypes.log')
def test_ajax_other_err(self, mock_log): def test_ajax_other_err(self, mock_log):
......
...@@ -449,15 +449,14 @@ class CapaModuleTest(unittest.TestCase): ...@@ -449,15 +449,14 @@ class CapaModuleTest(unittest.TestCase):
# and that we get the same values back # and that we get the same values back
for key in result.keys(): for key in result.keys():
original_key = "input_" + key original_key = "input_" + key
self.assertTrue(original_key in valid_get_dict, self.assertIn(original_key, valid_get_dict, "Output dict should have key %s" % original_key)
"Output dict should have key %s" % original_key)
self.assertEqual(valid_get_dict[original_key], result[key]) self.assertEqual(valid_get_dict[original_key], result[key])
# Valid GET param dict with list keys # Valid GET param dict with list keys
# Each tuple represents a single parameter in the query string # Each tuple represents a single parameter in the query string
valid_get_dict = MultiDict((('input_2[]', 'test1'), ('input_2[]', 'test2'))) valid_get_dict = MultiDict((('input_2[]', 'test1'), ('input_2[]', 'test2')))
result = CapaModule.make_dict_of_responses(valid_get_dict) result = CapaModule.make_dict_of_responses(valid_get_dict)
self.assertTrue('2' in result) self.assertIn('2', result)
self.assertEqual(['test1', 'test2'], result['2']) self.assertEqual(['test1', 'test2'], result['2'])
# If we use [] at the end of a key name, we should always # If we use [] at the end of a key name, we should always
...@@ -730,7 +729,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -730,7 +729,7 @@ class CapaModuleTest(unittest.TestCase):
result = module.check_problem(get_request_dict) result = module.check_problem(get_request_dict)
# Expect an AJAX alert message in 'success' # Expect an AJAX alert message in 'success'
self.assertTrue(error_msg in result['success']) self.assertIn(error_msg, result['success'])
def test_check_problem_error_nonascii(self): def test_check_problem_error_nonascii(self):
...@@ -781,10 +780,10 @@ class CapaModuleTest(unittest.TestCase): ...@@ -781,10 +780,10 @@ class CapaModuleTest(unittest.TestCase):
result = module.check_problem(get_request_dict) result = module.check_problem(get_request_dict)
# Expect an AJAX alert message in 'success' # Expect an AJAX alert message in 'success'
self.assertTrue('test error' in result['success']) self.assertIn('test error', result['success'])
# We DO include traceback information for staff users # We DO include traceback information for staff users
self.assertTrue('Traceback' in result['success']) self.assertIn('Traceback', result['success'])
# Expect that the number of attempts is NOT incremented # Expect that the number of attempts is NOT incremented
self.assertEqual(module.attempts, 1) self.assertEqual(module.attempts, 1)
...@@ -806,7 +805,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -806,7 +805,7 @@ class CapaModuleTest(unittest.TestCase):
self.assertTrue('success' in result and result['success']) self.assertTrue('success' in result and result['success'])
# Expect that the problem HTML is retrieved # Expect that the problem HTML is retrieved
self.assertTrue('html' in result) self.assertIn('html', result)
self.assertEqual(result['html'], "<div>Test HTML</div>") self.assertEqual(result['html'], "<div>Test HTML</div>")
# Expect that the problem was reset # Expect that the problem was reset
...@@ -852,7 +851,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -852,7 +851,7 @@ class CapaModuleTest(unittest.TestCase):
self.assertEqual(result['success'], 'correct') self.assertEqual(result['success'], 'correct')
# Expect that we get no HTML # Expect that we get no HTML
self.assertFalse('contents' in result) self.assertNotIn('contents', result)
# Expect that the number of attempts is not incremented # Expect that the number of attempts is not incremented
self.assertEqual(module.attempts, 1) self.assertEqual(module.attempts, 1)
...@@ -1263,7 +1262,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -1263,7 +1262,7 @@ class CapaModuleTest(unittest.TestCase):
self.assertEqual(bool(context['save_button']), show_save_button) self.assertEqual(bool(context['save_button']), show_save_button)
# Assert that the encapsulated html contains the original html # Assert that the encapsulated html contains the original html
self.assertTrue(html in html_encapsulated) self.assertIn(html, html_encapsulated)
demand_xml = """ demand_xml = """
<problem> <problem>
...@@ -1355,7 +1354,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -1355,7 +1354,7 @@ class CapaModuleTest(unittest.TestCase):
# Check the rendering context # Check the rendering context
render_args, _ = module.system.render_template.call_args render_args, _ = module.system.render_template.call_args
context = render_args[1] context = render_args[1]
self.assertTrue("error" in context['problem']['html']) self.assertIn("error", context['problem']['html'])
# Expect that the module has created a new dummy problem with the error # Expect that the module has created a new dummy problem with the error
self.assertNotEqual(original_problem, module.lcp) self.assertNotEqual(original_problem, module.lcp)
...@@ -1385,7 +1384,7 @@ class CapaModuleTest(unittest.TestCase): ...@@ -1385,7 +1384,7 @@ class CapaModuleTest(unittest.TestCase):
# Check the rendering context # Check the rendering context
render_args, _ = module.system.render_template.call_args render_args, _ = module.system.render_template.call_args
context = render_args[1] context = render_args[1]
self.assertTrue(error_msg in context['problem']['html']) self.assertIn(error_msg, context['problem']['html'])
@ddt.data( @ddt.data(
'false', 'false',
......
...@@ -554,9 +554,9 @@ class CrowdsourceHinterTest(unittest.TestCase): ...@@ -554,9 +554,9 @@ class CrowdsourceHinterTest(unittest.TestCase):
mock_module.get_hint = fake_get_hint mock_module.get_hint = fake_get_hint
json_in = {'problem_name': '42.5'} json_in = {'problem_name': '42.5'}
out = json.loads(mock_module.handle_ajax('get_hint', json_in))['contents'] out = json.loads(mock_module.handle_ajax('get_hint', json_in))['contents']
self.assertTrue('This is the best hint.' in out) self.assertIn('This is the best hint.', out)
self.assertTrue('A random hint' in out) self.assertIn('A random hint', out)
self.assertTrue('Another random hint' in out) self.assertIn('Another random hint', out)
def test_template_feedback(self): def test_template_feedback(self):
""" """
......
...@@ -225,18 +225,18 @@ class ImportTestCase(BaseCourseTestCase): ...@@ -225,18 +225,18 @@ class ImportTestCase(BaseCourseTestCase):
self.assertEqual(course_xml.attrib['unicorn'], unicorn_color) self.assertEqual(course_xml.attrib['unicorn'], unicorn_color)
# the course and org tags should be _only_ in the pointer # the course and org tags should be _only_ in the pointer
self.assertTrue('course' not in course_xml.attrib) self.assertNotIn('course', course_xml.attrib)
self.assertTrue('org' not in course_xml.attrib) self.assertNotIn('org', course_xml.attrib)
# did we successfully strip the url_name from the definition contents? # did we successfully strip the url_name from the definition contents?
self.assertTrue('url_name' not in course_xml.attrib) self.assertNotIn('url_name', course_xml.attrib)
# Does the chapter tag now have a due attribute? # Does the chapter tag now have a due attribute?
# hardcoded path to child # hardcoded path to child
with descriptor.runtime.export_fs.open('chapter/ch.xml') as f: with descriptor.runtime.export_fs.open('chapter/ch.xml') as f:
chapter_xml = etree.fromstring(f.read()) chapter_xml = etree.fromstring(f.read())
self.assertEqual(chapter_xml.tag, 'chapter') self.assertEqual(chapter_xml.tag, 'chapter')
self.assertFalse('due' in chapter_xml.attrib) self.assertNotIn('due', chapter_xml.attrib)
def test_metadata_import_export(self): def test_metadata_import_export(self):
"""Two checks: """Two checks:
......
...@@ -127,12 +127,12 @@ class ProgressTest(unittest.TestCase): ...@@ -127,12 +127,12 @@ class ProgressTest(unittest.TestCase):
prg1 = Progress(1, 2) prg1 = Progress(1, 2)
prg2 = Progress(2, 4) prg2 = Progress(2, 4)
prg3 = Progress(1, 2) prg3 = Progress(1, 2)
self.assertTrue(prg1 == prg3) self.assertEqual(prg1, prg3)
self.assertFalse(prg1 == prg2) self.assertNotEqual(prg1, prg2)
# Check != while we're at it # Check != while we're at it
self.assertTrue(prg1 != prg2) self.assertNotEqual(prg1, prg2)
self.assertFalse(prg1 != prg3) self.assertEqual(prg1, prg3)
class ModuleProgressTest(unittest.TestCase): class ModuleProgressTest(unittest.TestCase):
......
...@@ -78,7 +78,7 @@ class SelfAssessmentTest(unittest.TestCase): ...@@ -78,7 +78,7 @@ class SelfAssessmentTest(unittest.TestCase):
def test_get_html(self): def test_get_html(self):
html = self.module.get_html(self.module.system) html = self.module.get_html(self.module.system)
self.assertTrue("This is sample prompt text" in html) self.assertIn("This is sample prompt text", html)
def test_self_assessment_flow(self): def test_self_assessment_flow(self):
responses = {'assessment': '0', 'score_list[]': ['0', '0']} responses = {'assessment': '0', 'score_list[]': ['0', '0']}
......
...@@ -642,7 +642,7 @@ class CreditProviderIntegrationApiTests(CreditApiTestBase): ...@@ -642,7 +642,7 @@ class CreditProviderIntegrationApiTests(CreditApiTestBase):
# Validate the timestamp # Validate the timestamp
self.assertIn('timestamp', parameters) self.assertIn('timestamp', parameters)
parsed_date = from_timestamp(parameters['timestamp']) parsed_date = from_timestamp(parameters['timestamp'])
self.assertTrue(parsed_date < datetime.datetime.now(pytz.UTC)) self.assertLess(parsed_date, datetime.datetime.now(pytz.UTC))
# Validate course information # Validate course information
self.assertEqual(parameters['course_org'], self.course_key.org) self.assertEqual(parameters['course_org'], self.course_key.org)
......
...@@ -80,7 +80,7 @@ class TestAccountApi(UserSettingsEventTestMixin, TestCase): ...@@ -80,7 +80,7 @@ class TestAccountApi(UserSettingsEventTestMixin, TestCase):
# With default configuration settings, email is not shared with other (non-staff) users. # With default configuration settings, email is not shared with other (non-staff) users.
account_settings = get_account_settings(self.default_request, self.different_user.username) account_settings = get_account_settings(self.default_request, self.different_user.username)
self.assertFalse("email" in account_settings) self.assertNotIn("email", account_settings)
account_settings = get_account_settings( account_settings = get_account_settings(
self.default_request, self.default_request,
......
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