[changes requested] Refactor cli_test.py and main_test.py#3828
[changes requested] Refactor cli_test.py and main_test.py#3828ohemorange merged 25 commits intocertbot:masterfrom
Conversation
|
This looks like heroic work! |
ohemorange
left a comment
There was a problem hiding this comment.
This PR is fantastic, great work!
There's a new file not_cli_test.py that's probably not supposed to be there.
certbot/tests/error_handler_test.py
Outdated
| self.assertFalse(self.init_func.called) | ||
|
|
||
| @mock.patch('certbot.main.sys') | ||
| def test_handle_exception(self, mock_sys): |
There was a problem hiding this comment.
It's confusing to me to have _handle_exception() defined in main.py but tested in error_handler_test.py. I don't know the history of why it's in main, but could we move it to error_handler.py to match the test?
There was a problem hiding this comment.
I looks like the purpose of error_handler.ErrorHandler is to handle clean up of stateful operations when there is an exception. But main._handle_exception is for logging tracebacks and displaying them to the user properly. So they are separate but sound similar.
I think it would be better to move this test into its own class in main_test.py.
There was a problem hiding this comment.
Either way works for me, as long as they match.
| self.assertEqual(result, (None, None)) | ||
|
|
||
|
|
||
| class MainTest(unittest.TestCase): # pylint: disable=too-many-public-methods |
There was a problem hiding this comment.
How would you feel about having a BaseMainTest class that the different verb testers inherit from?
There was a problem hiding this comment.
That sounds like a good strategy. But I think I will save breaking this into separate verb tests for another PR. This PR just gets the low hanging fruit, like the parsing tests.
There was a problem hiding this comment.
Sounds good! I'll make you an issue for it.
certbot/tests/renewal_test.py
Outdated
| import tempfile | ||
|
|
||
| from certbot import configuration | ||
| from certbot import renewal |
There was a problem hiding this comment.
Can you move this into the method, just before calling _restore_webroot_config?
| return lambda cls: None | ||
|
|
||
|
|
||
| def make_lineage(self, testfile): |
There was a problem hiding this comment.
With this method in test_util, does DuplicativeCertsTest have to inherit from BaseRenewableCertTest?
There was a problem hiding this comment.
Yeah, it looks like make_lineage can be used instead of inheriting from BaseRenewableCertTest. I'll try that this afternoon.
There was a problem hiding this comment.
I didn't finish this today, I'll take another look tomorrow.
There was a problem hiding this comment.
@ohemorange, a few things for posterity, make_lineage creates as lineage based on any of the configuration files in certbot/tests/testdata/*.conf. While BaseRenewableCertTest makes a lineage (correct word?) on the fly, based on some parameters in its class definition. It would be nice to remove the dependency of BaseRenewableCertTest since it is imported from another test file.
After a few attempts I could not get the DuplicativeCertsTest tests to work using make_lineage. So I'll punt for now and make another issue.
|
Oh also this is going to conflict with #3785, so let's try to get this one in. |
|
@pde @ohemorange I think I should rename |
|
Only reason I see to keep it is that we might then get some |
|
@ohemorange cool, I'll probably have time to address your comments tomorrow morningish CST. |
|
Kicking Travis |
certbot/tests/main_test.py
Outdated
| return functools.partial(cli.prepare_and_parse_args, plugins) | ||
|
|
||
| # why can't I remove this? | ||
| def test_option_was_set(self): |
There was a problem hiding this comment.
A lot of this refactoring expects that prepare_and_parse_args is stateless, but it actually has some global side effects which are tested here. Is there a better way to handle this state?
There was a problem hiding this comment.
Fixed. I just manually reset the state of set_by_cli in each test. This is way cheaper and faster than loading all the plugins and rebuilding the parser for each test.
1b32cc1 to
47a78e5
Compare
from @ohemorange comments
|
Rebased |
|
@ohemorange Anything else? |
This moves the tests in
cli_test.pythat used thecertbot.main.mainentrypoint to main_test.py. It also moves a lot of the other extraneous tests out of there.It does not fully close #2716 because many of the tests now in
main_test.pystill use the same monolithic entrypoint, but it is a good step toward that.