New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No assertion in test_del_param_on_nonexistent_header function and unused variables in some places in test_email.py #62703
Comments
In Lib/test/test_email/test_email.py, line 389, there is a unit test function: def test_del_param_on_nonexistent_header(self):
msg = Message()
msg.del_param('filename', 'content-disposition') There is no assertion here, unlike other unit test functions, such as: def test_del_param_on_other_header(self):
msg = Message()
msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')
msg.del_param('filename', 'content-disposition')
self.assertEqual(msg['content-disposition'], 'attachment') |
That's because there's nothing to assert. The test is making sure no exception is raised. (Why no exception is raised is a good question, but that design predates my stewardship of the module :) A comment to that effect would probably be a good idea. |
I see. Anyway, I am just curious. Why not doing try and catch? def test_del_param_on_nonexistent_header(self):
msg = Message()
try:
msg.del_param('filename', 'content-disposition')
except:
self.fail('del_param on empty msg raised exception!') Or is it better this way? def test_del_param_on_nonexistent_header(self):
msg = Message()
# Deleting param on empty msg should not raise exception.
msg.del_param('filename', 'content-disposition') |
Anyway, I found another issue on line 393 on the same file: def test_del_nonexistent_param(self):
msg = Message()
msg.add_header('Content-Type', 'text/plain', charset='utf-8')
existing_header = msg['Content-Type']
msg.del_param('foobar', header='Content-Type')
self.assertEqual(msg['Content-Type'], 'text/plain; charset="utf-8"') The variable existing_header is never used. Either we can remove it or change it to: def test_del_nonexistent_param(self):
msg = Message()
msg.add_header('Content-Type', 'text/plain', charset='utf-8')
existing_header = msg['Content-Type']
msg.del_param('foobar', header='Content-Type')
self.assertEqual(msg['Content-Type'], existing_header) At first, I wanted to create a ticket for this. But then, I thought why do not we combine these menial problems together? |
Another unused variable in line 2268 on function test_bad_multipart: def test_bad_multipart(self):
eq = self.assertEqual
msg1 = Message()
msg1['Subject'] = 'subpart 1'
msg2 = Message()
msg2['Subject'] = 'subpart 2'
r = MIMEMessage(msg1)
self.assertRaises(errors.MultipartConversionError, r.attach, msg2) The variable eq is never used and can be removed. I have changed the title of the ticket to reflect the problem better. |
We prefer one ticket per issue. The line is fuzzy...I think it would be OK to fix these all at once since they are all small cleanups in test_email, but as you can tell from how complex the title got, they are not really conceptually related. The try/except/fail is a valid style. I prefer to just let the exception raise, and put in a comment to that effect, but it is definitely a personal style thing. |
Okay, next time I'll separate the problems into different tickets. Here is the patch to clean up the test. |
New changeset 61d9c561b63d by R David Murray in branch '3.3': New changeset be5f1f0bea09 by R David Murray in branch 'default': |
Thanks, Vajrasky. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: