Fixing "wrong-assert-type" pep8 warning.

TNL-3650
This commit is contained in:
muzaffaryousaf
2015-10-29 14:23:01 +05:00
parent d9751a855a
commit cc88cfaf64
11 changed files with 32 additions and 34 deletions

View File

@@ -124,7 +124,7 @@ class CapaHtmlRenderTest(unittest.TestCase):
rendered_html = etree.XML(problem.get_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))
def test_render_response_xml(self):
# Generate some XML for a string response

View File

@@ -105,8 +105,7 @@ class TemplateTestCase(unittest.TestCase):
If no elements are found, the assertion fails.
"""
element_list = xml_root.xpath(xpath)
self.assertTrue(len(element_list) > 0,
"Could not find element at '%s'" % str(xpath))
self.assertGreater(len(element_list), 0, "Could not find element at '%s'" % str(xpath))
if exact:
self.assertEqual(text, element_list[0].text)

View File

@@ -555,8 +555,8 @@ class MatlabTest(unittest.TestCase):
response = self.the_input.handle_ajax("plot", data)
self.assertFalse(response['success'])
self.assertEqual(response['message'], error_message)
self.assertTrue('queuekey' not in self.the_input.input_state)
self.assertTrue('queuestate' not in self.the_input.input_state)
self.assertNotIn('queuekey', self.the_input.input_state)
self.assertNotIn('queuestate', self.the_input.input_state)
@patch('capa.inputtypes.time.time', return_value=10)
def test_ungraded_response_success(self, time):
@@ -594,7 +594,7 @@ class MatlabTest(unittest.TestCase):
the_input.ungraded_response(queue_msg, 'abc')
self.assertEqual(input_state['queuekey'], queuekey)
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)
def test_matlab_response_timeout_not_exceeded(self, time):
@@ -1076,7 +1076,7 @@ class ChemicalEquationTest(unittest.TestCase):
)
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')
def test_ajax_other_err(self, mock_log):

View File

@@ -449,15 +449,14 @@ class CapaModuleTest(unittest.TestCase):
# and that we get the same values back
for key in result.keys():
original_key = "input_" + key
self.assertTrue(original_key in valid_get_dict,
"Output dict should have key %s" % original_key)
self.assertIn(original_key, valid_get_dict, "Output dict should have key %s" % original_key)
self.assertEqual(valid_get_dict[original_key], result[key])
# Valid GET param dict with list keys
# Each tuple represents a single parameter in the query string
valid_get_dict = MultiDict((('input_2[]', 'test1'), ('input_2[]', 'test2')))
result = CapaModule.make_dict_of_responses(valid_get_dict)
self.assertTrue('2' in result)
self.assertIn('2', result)
self.assertEqual(['test1', 'test2'], result['2'])
# If we use [] at the end of a key name, we should always
@@ -730,7 +729,7 @@ class CapaModuleTest(unittest.TestCase):
result = module.check_problem(get_request_dict)
# 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):
@@ -781,10 +780,10 @@ class CapaModuleTest(unittest.TestCase):
result = module.check_problem(get_request_dict)
# 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
self.assertTrue('Traceback' in result['success'])
self.assertIn('Traceback', result['success'])
# Expect that the number of attempts is NOT incremented
self.assertEqual(module.attempts, 1)
@@ -806,7 +805,7 @@ class CapaModuleTest(unittest.TestCase):
self.assertTrue('success' in result and result['success'])
# Expect that the problem HTML is retrieved
self.assertTrue('html' in result)
self.assertIn('html', result)
self.assertEqual(result['html'], "<div>Test HTML</div>")
# Expect that the problem was reset
@@ -852,7 +851,7 @@ class CapaModuleTest(unittest.TestCase):
self.assertEqual(result['success'], 'correct')
# Expect that we get no HTML
self.assertFalse('contents' in result)
self.assertNotIn('contents', result)
# Expect that the number of attempts is not incremented
self.assertEqual(module.attempts, 1)
@@ -1263,7 +1262,7 @@ class CapaModuleTest(unittest.TestCase):
self.assertEqual(bool(context['save_button']), show_save_button)
# Assert that the encapsulated html contains the original html
self.assertTrue(html in html_encapsulated)
self.assertIn(html, html_encapsulated)
demand_xml = """
<problem>
@@ -1355,7 +1354,7 @@ class CapaModuleTest(unittest.TestCase):
# Check the rendering context
render_args, _ = module.system.render_template.call_args
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
self.assertNotEqual(original_problem, module.lcp)
@@ -1385,7 +1384,7 @@ class CapaModuleTest(unittest.TestCase):
# Check the rendering context
render_args, _ = module.system.render_template.call_args
context = render_args[1]
self.assertTrue(error_msg in context['problem']['html'])
self.assertIn(error_msg, context['problem']['html'])
@ddt.data(
'false',

View File

@@ -365,9 +365,9 @@ class OpenEndedModuleTest(unittest.TestCase):
def test_latest_post_assessment(self):
self.update_score_single()
assessment = self.openendedmodule.latest_post_assessment(self.test_system)
self.assertFalse(assessment == '')
self.assertNotEqual(assessment, '')
# check for errors
self.assertFalse('errors' in assessment)
self.assertNotIn('errors', assessment)
def test_update_score_single(self):
self.update_score_single()

View File

@@ -554,9 +554,9 @@ class CrowdsourceHinterTest(unittest.TestCase):
mock_module.get_hint = fake_get_hint
json_in = {'problem_name': '42.5'}
out = json.loads(mock_module.handle_ajax('get_hint', json_in))['contents']
self.assertTrue('This is the best hint.' in out)
self.assertTrue('A random hint' in out)
self.assertTrue('Another random hint' in out)
self.assertIn('This is the best hint.', out)
self.assertIn('A random hint', out)
self.assertIn('Another random hint', out)
def test_template_feedback(self):
"""

View File

@@ -225,18 +225,18 @@ class ImportTestCase(BaseCourseTestCase):
self.assertEqual(course_xml.attrib['unicorn'], unicorn_color)
# the course and org tags should be _only_ in the pointer
self.assertTrue('course' not in course_xml.attrib)
self.assertTrue('org' not in course_xml.attrib)
self.assertNotIn('course', course_xml.attrib)
self.assertNotIn('org', course_xml.attrib)
# 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?
# hardcoded path to child
with descriptor.runtime.export_fs.open('chapter/ch.xml') as f:
chapter_xml = etree.fromstring(f.read())
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):
"""Two checks:

View File

@@ -127,12 +127,12 @@ class ProgressTest(unittest.TestCase):
prg1 = Progress(1, 2)
prg2 = Progress(2, 4)
prg3 = Progress(1, 2)
self.assertTrue(prg1 == prg3)
self.assertFalse(prg1 == prg2)
self.assertEqual(prg1, prg3)
self.assertNotEqual(prg1, prg2)
# Check != while we're at it
self.assertTrue(prg1 != prg2)
self.assertFalse(prg1 != prg3)
self.assertNotEqual(prg1, prg2)
self.assertEqual(prg1, prg3)
class ModuleProgressTest(unittest.TestCase):

View File

@@ -78,7 +78,7 @@ class SelfAssessmentTest(unittest.TestCase):
def test_get_html(self):
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):
responses = {'assessment': '0', 'score_list[]': ['0', '0']}

View File

@@ -642,7 +642,7 @@ class CreditProviderIntegrationApiTests(CreditApiTestBase):
# Validate the timestamp
self.assertIn('timestamp', parameters)
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
self.assertEqual(parameters['course_org'], self.course_key.org)

View File

@@ -80,7 +80,7 @@ class TestAccountApi(UserSettingsEventTestMixin, TestCase):
# 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)
self.assertFalse("email" in account_settings)
self.assertNotIn("email", account_settings)
account_settings = get_account_settings(
self.default_request,